我試圖創建一個可以繼承的NotifyIcon,以便我可以添加自己的屬性/等。通過查看別人寫的組件類,我已經取得了一些進展,如下所示,並且可以將組件拖到表單中。說實話,我對自己在做什麼沒有多少想法,而且在互聯網上的任何地方都沒有任何教程可以使用。C#在運行時獲取組件的值?
在您看到的PrepareIcon
方法中,彈出的消息框顯示爲空白,即使我已嘗試更改設計器默認值notifyIconInheritable1
的值。我看到NotifyIcon出現在設計師身上,所以我對這個工作原理感到非常困惑。
問題是;這有什麼問題,或者我做錯了什麼,我在浪費時間,不應該試圖這樣做?
namespace AwesomeNotifyIcon
{
[DefaultProperty("Text"), DefaultEvent("Click"), Description("Displays an icon in the notification area, on the right side of the Windows taskbar, during run time")]
public partial class NotifyIconInheritable : Component
{
private NotifyIcon notifyIcon;
public NotifyIconInheritable()
{
//PrepareIcon();
InitializeComponent();
}
public NotifyIconInheritable(IContainer container)
{
if (container != null)
{
container.Add(this);
}
PrepareIcon();
InitializeComponent();
}
[Category("Appearance"), Description("The icon to associate with the balloon ToolTip."), DefaultValue(ToolTipIcon.None)]
public ToolTipIcon BalloonTipIcon { get; set; }
[Category("Appearance"), Description("The text to associate with the balloon ToolTip.")]
public string BalloonTipText { get; set; }
[Category("Appearance"), Description("The title of the balloon ToolTip.")]
public string BalloonTipTitle { get; set; }
[Category("Appearance"), Description("The icon to display in the system tray.")]
public Icon Icon { get; set; }
[Category("Appearance"), Description("The text that will be displayed when the mouse hovers over the icon.")]
public string Text { get; set; }
[Category("Behaviour"), Description("The shortcut menu to show when the user right-clicks the icon.")]
public ContextMenuStrip ContextMenuStrip { get; set; }
[Category("Behaviour"), Description("Determines whether the control is visible or hidden."), DefaultValue(false)]
public bool Visible { get; set; }
[Category("Data"), Description("User-defined data associated with the object.")]
public object Tag { get; set; }
[Category("Action"), Description("Occurs when the component is clicked.")]
public event EventHandler Click;
private void PrepareIcon()
{
notifyIcon = new NotifyIcon();
notifyIcon.Dispose();
MessageBox.Show(this.Text);
if (Click != null)
notifyIcon.Click += Click;
}
}
}
這裏的屬性,如設計師看到:
http://cl.ly/1vIF/content http://cl.ly/1vIF/content
對不起,但是你的問題到底是什麼? – msteiger 2010-08-09 08:48:02
糟糕。編輯了這個問題。 – unrelativity 2010-08-09 08:49:00