J'essaye de créer un NotifyIcon qui peut être hérité afin que je puisse ajouter mes propres propriétés/etc. En examinant une classe de composants que quelqu'un d'autre a écrite, j'ai fait quelques progrès comme on peut le voir ci-dessous, et le composant peut être glissé dans le formulaire. Pour être honnête, je n'ai aucune idée de ce que je suis en train de faire, et il semble qu'il n'existe aucun tutoriel sur Internet qui soit utile.C# Obtenir les valeurs d'un composant lors de l'exécution?
Dans la méthode PrepareIcon
que vous voyez, la boîte de message qui s'affiche apparaît vide, même si j'ai essayé de modifier la valeur de la valeur par défaut du concepteur notifyIconInheritable1
. J'ai vu le NotifyIcon apparaître dans le concepteur, donc j'ai été complètement confus sur la façon dont cela fonctionne.
La question est; Qu'est-ce qui ne va pas ou qu'est-ce que je fais de mal? Est-ce que je perds mon temps et que je ne devrais pas essayer cela du tout?
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;
}
}
}
est ici les propriétés comme on le voit dans le concepteur:
http://cl.ly/1vIF/content http://cl.ly/1vIF/content
Je suis désolé, mais quelle est exactement votre question? – msteiger
Oups. Edité la question. – unrelativity