【问题标题】:Where would the responsibility to handle this event be placed?处理此事件的责任将放在哪里?
【发布时间】:2011-06-15 10:16:34
【问题描述】:

我有一个 NavigationBar.cs 用户控件。 我也有 NavigationItem.cs 用户控件。

这是两者的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Uboldi.CustomUI
{
    public partial class NavigationBar : UserControl
    {
        public NavigationBar()
        {
            InitializeComponent();
        }

        public List<NavigationItem> NavigationItems { private get; set; }
        public NavigationItem SelectedItem { get; set; }
    }
}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Uboldi.CustomUI
{
    public partial class NavigationItem : UserControl
    {
        public NavigationItem()
        {
            InitializeComponent();
        }

        private Image _picture = null;
        public Image Picture
        {
            get
            {
                return _picture;
            }
            set
            {
                _picture = value;
                ptbIcon.Image = _picture;
            }
        }

        private string _content = null;
        public string Content 
        {
            get
            {
                return _content;
            }
            set
            {
                _content = value;
                lblDisplayText.Text = _content;
            }
        }
    }
}

我只想在任何给定时间“选择”导航栏中的单个 NavigationItem。

当一个项目被选中时,它会被赋予不同的颜色。

我的问题是,我应该在哪里编写此代码?在栏中,还是按钮应该做的事情,让栏只调用 SetYourSelfAsSelected() 方法?

谢谢。

【问题讨论】:

  • 我的直觉告诉我,在 NavigationBar.cs 中有一个返回 NavigationItem 的属性有点靠不住。也许它应该只返回一个字符串?有什么想法吗?

标签: c# winforms events user-controls


【解决方案1】:

我将在NavigationBar 中实现此功能,原因如下:其他一些开发人员可以在不同的上下文中使用您的NavigationItems,其中没有标记活动项目或标记任何不同。或者想要重载NavigationBar 以实现活动项目的另一种行为。

【讨论】:

    猜你喜欢
    • 2015-09-16
    • 2011-11-14
    • 1970-01-01
    • 2016-07-14
    • 2011-08-01
    • 2013-04-02
    • 2013-08-04
    • 2015-08-05
    • 1970-01-01
    相关资源
    最近更新 更多