|
|
Comments and Discussions
|
|
 |

|
It s so helpfull in creating icons
|
|
|
|

|
how to get this icon for all users to let a program run when you start under admin and managing it could and normal user?
|
|
|
|

|
i am working on a application which has timers set up in it as
System.Threading.Timer timer = new System.Threading.Timer(timerDelegate, autoEvent, new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 0, 0, -1));
now when i am trying to support this application in task bar, using notifyIcons --- whenever i try to close the app, the icon doesn't go away and the application keeps on running in task manager, untill i again click on icon (just clicking on icon serves, no need to select any option)
Actually the timers are running as below, cause i want them to run continuosly with doing some calculation every 12 hours
private void Form1_Load(object sender, EventArgs e)
{
while (true)
{
if (x == 0)
{
System.Threading.Timer timer = new System.Threading.Timer(timerDelegate, autoEvent, new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 0, 0, -1));
autoEvent.WaitOne();
x++;
}
else if (x == 1)
{
System.Threading.Timer timer = new System.Threading.Timer(timerDelegate, autoEvent, new TimeSpan(12, 0, 0), new TimeSpan(0, 0, 0, 0, -1));
autoEvent.WaitOne();
}
}
}
|
|
|
|

|
Hi , thanks for nice article
I have a problem, when i follow step by step that article in vs2008 and build my project and finally i run Bin\Release\MyProect.exe i've recieved a windows problem "MyProect has encountered a problem and needs to close. We are sorry for the inconvenience."
Here is My Code :
namespace PostIt
{
public partial class frmPostIT : System.Windows.Forms.Form
{
private System.Windows.Forms.NotifyIcon m_notifyicon;
private System.Windows.Forms.ContextMenu m_menu;
public frmPostIT()
{
InitializeComponent();
m_notifyicon = new System.Windows.Forms.NotifyIcon();
m_notifyicon.Text = "Post IT";
m_notifyicon.Visible = true;
m_notifyicon.Icon = new System.Drawing.Icon(GetType(), "NotifyPostIT");
m_menu.MenuItems.Add(0, new System.Windows.Forms.MenuItem("Add New PostIt", new System.EventHandler(Add_Click)));
m_menu.MenuItems.Add(0, new System.Windows.Forms.MenuItem("Save Current PostIt", new System.EventHandler(Save_Click)));
m_menu.MenuItems.Add(0, new System.Windows.Forms.MenuItem("Load Last PostIt", new System.EventHandler(load_Click)));
m_menu.MenuItems.Add(0, new System.Windows.Forms.MenuItem("Exit PostIt", new System.EventHandler(Exit_Click)));
}
protected void Add_Click(System.Object sender, System.EventArgs e)
{
}
protected void Save_Click(System.Object sender, System.EventArgs e)
{
}
protected void Load_Click(System.Object sender, System.EventArgs e)
{
}
protected void Exit_Click(System.Object sender, System.EventArgs e)
{
Close();
}
}
}
|
|
|
|

|
Hi, thanks for your article
i have a problem , when i follow your solution step by step in VS2008 and build my project ,finally I run bin\Release\Myproject.exe and recieve a windows message "Myproject.ex has encountered a problem and needs to close. We are sorry for the inconvenience."
this is my code
namespace PostIt
{
public partial class frmPostIT : System.Windows.Forms.Form
{
private System.Windows.Forms.NotifyIcon m_notifyicon;
private System.Windows.Forms.ContextMenu m_menu;
public frmPostIT()
{
InitializeComponent();
m_notifyicon = new System.Windows.Forms.NotifyIcon();
m_notifyicon.Text = "Post IT";
m_notifyicon.Visible = true;
m_notifyicon.Icon = new System.Drawing.Icon(GetType(), "NotifyPostIT");
m_menu.MenuItems.Add(0, new System.Windows.Forms.MenuItem("Add New PostIt", new System.EventHandler(Add_Click)));
m_menu.MenuItems.Add(0, new System.Windows.Forms.MenuItem("Save Current PostIt", new System.EventHandler(Save_Click)));
m_menu.MenuItems.Add(0, new System.Windows.Forms.MenuItem("Load Last PostIt", new System.EventHandler(load_Click)));
m_menu.MenuItems.Add(0, new System.Windows.Forms.MenuItem("Exit PostIt", new System.EventHandler(Exit_Click)));
}
protected void Add_Click(System.Object sender, System.EventArgs e)
{
}
protected void Save_Click(System.Object sender, System.EventArgs e)
{
}
protected void Load_Click(System.Object sender, System.EventArgs e)
{
}
protected void Exit_Click(System.Object sender, System.EventArgs e)
{
Close();
}
}
}
---------------
Honey Variani
---------------
|
|
|
|

|
where is the code that i can download
|
|
|
|

|
why is there a limitation of 64 characters?
m_notifyicon.Text = "Right click for context menu .................. more than 64 characters. breaks everything off..... breaksss ......................";
in an old project of mine in C++ the tooltips have a limitation of 128 characters.
|
|
|
|

|
It helps me in my job but i wanna idea is there any way how to display context menu on mouse over like as tooltip
finally thanks for the article
evil
|
|
|
|

|
The ressource 'Icon1.ico' could not be found in class 'TrayTest.Form1'
error on Line m_notifyicon.Icon = new Icon(GetType(),"Icon1.ico")
s
|
|
|
|

|
Did you make sure to change it to embedded? Is that the proper name of the object?
Jeff
|
|
|
|

|
The GetType() (or typeof(somethinginthisassembly)) doesn't seme to work for class libraries.
The flollowing works, though:
m_icon = new Icon(
System.Reflection.Assembly
.GetExecutingAssembly()
.GetManifestResourceStream("project.iconname.ico"));
Where project is usually the class library project name, and iconname.ico is the embedded resource name. You can also see the "full" resource name using Reflector.
|
|
|
|

|
Even that doesn't really work for me.
I'm just trying this out to learn how to do it,
but despite it's beauty and simplicity - it just doesn't run.
I added the resource myIcon.ico (in Visual C# Express, newest version)
and I am getting a folder "Resources" where the icon seems to live in.
After that I edit the icon's properties.
Build Action: Embedded Resource
m_notifyicon.Icon = new Icon(System.Reflection.Assembly
.GetExecutingAssembly()
.GetManifestResourceStream("TrayTest.Form1.myIcon.ico"));
Yields: "Value of 'null' is not valid for 'stream'." on runtime.
This:
m_notifyicon.Icon = new Icon(System.Reflection.Assembly
.GetExecutingAssembly()
.GetManifestResourceStream("TrayTest.Resources.myIcon.ico"));
Yields: Oooops, it doesn't yield any error, but an icon in the tray!
Don't seem to have tried that before...
Well then, no problem left, just solved it.
May this post help other people as dumb as me who can't get their paths right.
Btw, the world is a great place, actually. Must see it!
|
|
|
|

|
I guess that's what I meant - If you open the binary with the embedded icon in Lutz Röders Reflector[^], you will see the correct path.
|
|
|
|

|
Actually i have created one context menu and assigned it for the system tray icon's context menu. I wanted to change the particular context menu's text dynamically. Using the property contextmenuname.text i have changed the context menu's text. But it didn't get refreshed in the tray icon.
How can we do this?
|
|
|
|

|
Can this work for a windows service? From my recent trials, it doesn't seem to.
Got a coding problem? Hand it to the CodeDevil!
|
|
|
|

|
Very easy and clear !! As someone also posted a question. How can we minimize windows to system tray when we click on minimize button?
Let me know if you have solution for this.
Thanks,
Tejpal
|
|
|
|

|
Hello… Thanks for the article! Straight forward except for one thing…
When I tried it in VS 2005 Team Developer, it complained that Form1 already had a dispose. After scratching my head for a while, I realized - There is a dispose in the "other part" of the partial class (Form1.Designer.cs) - in which it went:
if (disposing && (components != null))
{
components.Dispose();
}
Which I changed to:
if (disposing)
{
if (components != null)
{
components.Dispose();
}
this.m_notifyicon.Dispose(); }
Then it worked… Thanks!
|
|
|
|

|
Hi,
What about canceling the context menu ? Today, we are used to click anywhere else than on context menu to cancel it (or to hide it). How can I detect a click outside the context menu region ?!?
Thanks.
_____________________________
Fylom
|
|
|
|

|
Many programs minimize to the system tray when you minimize them and rise up out of the system tray as you open the form again.
Is this possible in vb.net?
Mike
|
|
|
|

|
Very Nice article. To the point, clear and Concise.
<html>
Without education, you're not going anywhere in this world.
Malcolm X, speech at Militant Labor Forum, NY, 29 May 1964
</html>
|
|
|
|

|
Simple and easy to follow. I like that!
ak
|
|
|
|

|
I've know that Windows Mobile 5.0 supporting tray icon on today screen, I've have the Windows Mobile 5.0 SDK and there is a sample creating tray icon application but the code in C/C++. Now i want to change the code into C#, but i have problem create NotifyIconData object on cbSize variable, how to use "sizeof" function in C#, because creating tray icon in Windows Mobile and Windows 32 is same nothing difference. Ok my problem is when i want to take size of NotifyIconData object it always make exception of NotSupportedException, i have use "sizeof" and "Marshal.SizeOf" but still have same problems. My code is :
* The NOTIFYICONDATA Structure
[StructLayout(LayoutKind.Sequential)]
public struct NOTIFYICONDATA
{
public int cbSize;
public int hWnd;
public int uID;
public int uFlags;
public int uCallbackMessage;
public int hIcon;
public char[] szTip;
}
* Get the structure size on cbSize
...
this.tryData.cbSize = Marshal.SizeOf(tryData);
...
I have use alternate for char[] into string but still same exception.
Sorry long message, i hope you can help. Thanks a lot.
|
|
|
|

|
NOTIFYICONDATA notdata = new NOTIFYICONDATA();
notdata.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(notdata);
notdata.hIcon = hIcon;
notdata.hWnd = hwnd;
notdata.uCallbackMessage = WM_NOTIFY_TRAY;
notdata.uFlags = NIF_MESSAGE | NIF_ICON;
notdata.uID = uID;
I think u can use like this, it gives no exception.
yuvraj
|
|
|
|

|
Thanks for the article.. Its very well written.
Can you help out on how to attach a Context Menu to the NotifyIcon in the .Net Compact Framework.
I have succesfully created a NotifyIcon to the application using the article at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/messagewindow.asp[^]. But I need help on attaching a Context Menu to the NotifyIcon..
Please help... really in need.
Thanks in advance.
We are alone, absolutely alone on this chance planet: and, amid all the forms of life that surround us, not one, excepting the dog, has made an alliance with us. - Maurice Maeterlinck
|
|
|
|

|
Since you're using the NotifyIcon class from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/messagewindow.asp, just add the following to your application (to your Form class).
Create a context menu, add some menu items to it, add some click event handlers for the menu items.
Add these declarations:
[DllImport("coredll.dll")]
internal static extern IntPtr LoadIcon(IntPtr hInst, string IconName);
[DllImport("coredll.dll")]
internal static extern IntPtr GetModuleHandle(String lpModuleName);
private NotifyIcon notifyIcon;
Set up your notifyicon (probably in the constructor for your Form class):
notifyIcon = new NotifyIcon();
notifyIcon.Click += new EventHandler(notifyIcon_Click);
AddIcon();
Add these methods:
private void AddIcon()
{
IntPtr hIcon = LoadIcon(GetModuleHandle(null), "#32512");
notifyIcon.Add(hIcon);
}
private void RemoveIcon()
{
notifyIcon.Remove();
}
private void notifyIcon_Click(object sender, EventArgs e)
{
contextMenu1.Show(this, new System.Drawing.Point(20, 20));
}
private void Form1_Closing(object sender, CancelEventArgs e)
{
RemoveIcon();
}
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
Beginner's Tutorial on adding tray icons and setting context menus
| Type | Article |
| Licence | |
| First Posted | 10 Apr 2002 |
| Views | 418,754 |
| Bookmarked | 166 times |
|
|