自分のプロパティなどを追加できるように、継承できるNotifyIconを作成しようとしています。他の誰かが書いたコンポーネントクラスを見ると、以下に示すようにある程度の進歩があり、コンポーネントをフォームにドラッグできます。正直なところ、私は自分が何をしているのかほとんどわかりません。インターネット上のどこにも、まったく役に立たないチュートリアルはないようです。
表示されている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;
}
}
}
デザイナに表示されるプロパティは次のとおりです。