Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 236 Vote(s) - 3.69 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I make a .NET Windows Forms application that only runs in the System Tray?

#1
What do I need to do to make a [Windows Forms][1] application to be able to run in the System Tray?

Not an application that can be minimized to the tray, but an application that will be only exist in the tray, with nothing more than
- an icon
- a tool tip, and
- a "*right click*" menu.

[1]:

[To see links please register here]

Reply

#2
As far as I'm aware you have to still write the application using a form, but have no controls on the form and never set it visible. Use the NotifyIcon (an MSDN sample of which can be found [here][1]) to write your application.


[1]:

[To see links please register here]

Reply

#3
"System tray" application is just a regular win forms application, only difference is that it creates a icon in windows system tray area. In order to create sys.tray icon use NotifyIcon component , you can find it in Toolbox(Common controls), and modify it's properties: Icon, tool tip. Also it enables you to handle mouse click and double click messages.

And One more thing , in order to achieve look and feels or standard tray app. add followinf lines on your main form show event:

private void MainForm_Shown(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
Hide();
}
Reply

#4
As mat1t says - you need to add a NotifyIcon to your application and then use something like the following code to set the tooltip and context menu:

this.notifyIcon.Text = "This is the tooltip";
this.notifyIcon.ContextMenu = new ContextMenu();
this.notifyIcon.ContextMenu.MenuItems.Add(new MenuItem("Option 1", new EventHandler(handler_method)));

This code shows the icon in the system tray only:

this.notifyIcon.Visible = true; // Shows the notify icon in the system tray

The following will be needed if you have a form (for whatever reason):

this.ShowInTaskbar = false; // Removes the application from the taskbar
Hide();

The right click to get the context menu is handled automatically, but if you want to do some action on a left click you'll need to add a Click handler:

private void notifyIcon_Click(object sender, EventArgs e)
{
var eventArgs = e as MouseEventArgs;
switch (eventArgs.Button)
{
// Left click to reactivate
case MouseButtons.Left:
// Do your stuff
break;
}
}

Reply

#5
I've wrote a traybar app with .NET 1.1 and I didn't need a form.
First of all, set the startup object of the project as a Sub `Main`, defined in a module.
Then create programmatically the components: the `NotifyIcon` and `ContextMenu`.
Be sure to include a `MenuItem` "Quit" or similar.
Bind the `ContextMenu` to the `NotifyIcon`.
Invoke `Application.Run()`.
In the event handler for the Quit `MenuItem` be sure to call set `NotifyIcon.Visible = False`, then `Application.Exit()`.
Add what you need to the `ContextMenu` and handle properly :)

Reply

#6
Here is how I did it with [Visual Studio 2010][1], .NET 4

1. Create a Windows Forms Application, set 'Make single instance application' in properties
2. Add a ContextMenuStrip
3. Add some entries to the context menu strip, double click on them to get the handlers, for example, 'exit' (double click) -> handler -> me.Close()
4. Add a NotifyIcon, in the designer set contextMenuStrip to the one you just created, pick an icon (you can find some in the VisualStudio folder under 'common7...')
5. Set properties for the form in the designer: FormBorderStyle:none, ShowIcon:false, ShowInTaskbar:false, Opacity:0%, WindowState:Minimized
6. Add Me.Visible=false at the end of Form1_Load, this will hide the icon when
using <kbd>Ctrl</kbd> + <kbd>Tab</kbd>
7. Run and adjust as needed.

[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through