I've looked over & over and have been having a hard time finding Simple Tutorials for task bars.
The Code has a ton of stuff when I wanted something simple.
This one uses no Forms, File Loading, ECT.
Just only Extra code in it is a Message Box to display "Hello ColdCall"
So I Present to you a Very Simple Task Bar Icon in C#
1) Create a new Project
2) Add an Icon of your Choice that will be displayed in the Task Bar.
Now to break it down we've got 4 sectionsCode:using System; using System.Drawing; using System.ComponentModel; using System.Windows.Forms; namespace Debuging { public class MyApp { private NotifyIcon appIcon = new NotifyIcon(); private ContextMenu sysTrayMenu = new ContextMenu(); private MenuItem MenuItem1 = new MenuItem("Say Hello"); private MenuItem MenuItem2 = new MenuItem("Exit"); public static void Main() { MyApp app = new MyApp(); app.Start(); Application.Run(); } public void Start() { Icon ico = new Icon("MyIcon.ico"); appIcon.Icon = ico; appIcon.Text = "Hello Cold Call App"; // Place the menu items in the menu. sysTrayMenu.MenuItems.Add(MenuItem1); sysTrayMenu.MenuItems.Add(MenuItem2); appIcon.ContextMenu = sysTrayMenu; // Show the system tray icon. appIcon.Visible = true; // Attach event handlers. MenuItem1.Click += new EventHandler(MenuItem1_Click); MenuItem2.Click += new EventHandler(MenuItem2_Click); } private void MenuItem1_Click(object sender, System.EventArgs e) { MessageBox.Show("Hello ColdCall"); } private void MenuItem2_Click(object sender, System.EventArgs e) { appIcon.Visible = false; Application.Exit(); } } }
Main
Start
MenuItem1_Click
MenuItem2_Click
I'm hoping MenuItem1_Click is self explanatory
Main.
We Create a copy of the Application that we're coding
MyApp app = new MyApp();
Start it
app.Start();
and use
Application.Run();
So Windows won't kill the application when this finishes, otherwise your app will be over before it starts.
Start()
Icon ico = new Icon("MyIcon.ico");
appIcon.Icon = ico;
appIcon.Text = "Hello Cold Call App";
Creates the Icon that is displayed in your Task bar, & gives you some text if you hold it over the icon
The Next 3 lines Create the Menus for when you Right Click on the Icon.
sysTrayMenu.MenuItems.Add(MenuItem1);
sysTrayMenu.MenuItems.Add(MenuItem2);
appIcon.ContextMenu = sysTrayMenu;
you can add additional menuItems by creating more MenuItem in your decorations
Make the Icon Visible
appIcon.Visible = true;
And Assign our Menu Items so we can do something with them.
MenuItem1.Click += new EventHandler(MenuItem1_Click);
MenuItem2.Click += new EventHandler(MenuItem2_Click);
Add more for each menu item you create.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks