J'ai créé une application de bac dans .Net qui fonctionne correctement. Cependant, les utilisateurs veulent changer l'image de l'icône Tray à l'exécution dans certaines conditions. Pour le rendre simple, disons, quelque chose ne fonctionne pas - l'icône de plateau devrait montrer l'image rouge; Si tout va bien, il devrait apparaître vert. Je ne suis pas sûr de savoir comment y parvenir en .Net.Modification de l'icône de la barre d'état système Image
Veuillez fournir quelques entrées à ce sujet. Merci
J'ai construit CustomApplicationContent pour Tray. Quelques extraits ci-dessous:
Program.cs
[STAThread]
static void Main()
{
if (!SingleInstance.Start()) { return; }
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
try
{
var applicationContext = new CustomApplicationContext();
Application.Run(applicationContext);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Program Terminated Unexpectedly",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
SingleInstance.Stop();
}
CustomApplicationContext.cs
public class CustomApplicationContext : ApplicationContext
{
private System.ComponentModel.IContainer components; // a list of components to dispose when the context is disposed
private NotifyIcon notifyIcon;
private static readonly string IconFileName = "green.ico";
private static readonly string DefaultTooltip = "Employee Management System";
private readonly TrayManager trayManager;
public CustomApplicationContext()
{
InitializeContext();
trayManager = new TrayManager(notifyIcon);
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null) { components.Dispose(); }
}
private void InitializeContext()
{
components = new System.ComponentModel.Container();
notifyIcon = new NotifyIcon(components)
{
ContextMenuStrip = new ContextMenuStrip(),
Icon = new Icon(IconFileName),
Text = DefaultTooltip,
Visible = true
};
notifyIcon.ContextMenuStrip.Opening += ContextMenuStrip_Opening;
notifyIcon.DoubleClick += notifyIcon_DoubleClick;
//notifyIcon.MouseUp += notifyIcon_MouseUp;
}
private void notifyIcon_DoubleClick(object sender, EventArgs e)
{
ShowAboutForm();
}
private TestForm testForm;
private void ShowAboutForm()
{
if (testForm == null)
{
testForm = new TestForm { trayManager = trayManager };
testForm.Closed += testForm_Closed; ; // avoid reshowing a disposed form
testForm.Show();
}
else { testForm.Activate(); }
}
void testForm_Closed(object sender, EventArgs e)
{
testForm = null;
}
Où dois-je ajouter minuterie - en contexte? Les utilisateurs ne peuvent pas ouvrir un formulaire, de sorte que l'ajout de la minuterie au formulaire peut ne pas fonctionner tout le temps. Comment changer d'icône?
il suffit de changer la propriété d'icône, ne pouvait pas être plus simple ou plus intuitive. –