 |
|
 |
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(); }
} }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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 ---------------
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
 | code  yingxuzhong | 3:12 20 Feb '09 |
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
 | thanks  EvilInide | 0:48 10 Jul '07 |
|
 |
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
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
The ressource 'Icon1.ico' could not be found in class 'TrayTest.Form1' error on Line m_notifyicon.Icon = new Icon(GetType(),"Icon1.ico")
s
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
 | Help  ashokkumar767 | 23:45 9 Jan '07 |
|
 |
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?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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!
|
| Sign In·View Thread·PermaLink | 1.33/5 |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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!
|
| Sign In·View Thread·PermaLink | 1.33/5 |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | 1.50/5 |
|
|
|
 |
|
 |
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>
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | 1.50/5 |
|
|
|
 |
|
 |
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(); }
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
I have a thought to alter the behavior of standard clock provided in system tray. Do you have any idea how to access it. Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi, I am writing a c# code that opens a file and searches for some condition and according to the condition that occuring tray icon changes.This should be done every 10 minutes.
I have coded this part well but I can not exit my application from a context menu item(exit) which never appears.
If I erase the line where my while loop appear, context menu appears and every thing goes well.
Do you have any suggestion where I might have made a mistake? I am a c# newbie and I cannot find the solution...
thanks for your help very much..
Here is the code:
using System; using System.Drawing; using System.Windows.Forms; using System.Threading; using System.Collections; using System.ComponentModel; using System.Data; using System.IO; using System.Diagnostics; public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.NotifyIcon notifyIcon1; private System.Windows.Forms.ContextMenu contextMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.ComponentModel.IContainer components; private System.Boolean check;
public Form1() { this.check=true; //this.HideApp(); //this.ShowInTaskbar = false; this.components = new System.ComponentModel.Container(); this.contextMenu1 = new System.Windows.Forms.ContextMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); // Initialize contextMenu1 this.contextMenu1.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] {this.menuItem1});
// Initialize menuItem1 this.menuItem1.Index = 0; this.menuItem1.Text = "E&xit"; this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
// Set up how the form should be displayed. //this.ClientSize = new System.Drawing.Size(292, 266);
this.Text = "Notify Icon Example";
// Create the NotifyIcon.
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); notifyIcon1.ContextMenu = this.contextMenu1;
// The Text property sets the text that will be displayed, // in a tooltip, when the mouse hovers over the systray icon. notifyIcon1.Text = "Form1 (Situation controller)"; notifyIcon1.Visible = true; notifyIcon1.Icon = new Icon("Icon2.ico"); while(this.check==true) { FileStream file = new FileStream("path.txt", FileMode.Open, FileAccess.Read,FileShare.Read); StreamReader sr = new StreamReader(file); string s; bool control=false; while((s = sr.ReadLine())!= null) { if(s.IndexOf("down")!=-1) { control=true; } } if(control==true) { notifyIcon1.Icon = new Icon("Icon2.ico"); } else { notifyIcon1.Icon = new Icon("Icon1.ico"); } sr.Close(); file.Close(); //bu kısmı degistirdim Thread.Sleep(1000*10*1);//1000*60*10 //this.Close(); //Application.Exit(); } this.notifyIcon1.Dispose(); }
protected override void Dispose( bool disposing ) { // Clean up any components being used. if( disposing ) if (components != null) components.Dispose();
base.Dispose( disposing ); }
private void notifyIcon1_DoubleClick(object Sender, EventArgs e) { // Show the form when the user double clicks on the notify icon.
// Set the WindowState to normal if the form is minimized. if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
// Activate the form. this.Activate(); }
private void menuItem1_Click(object Sender, EventArgs e) { this.check=false;
notifyIcon1.Visible = false;
Application.Exit();
this.Close(); }
private void InitializeComponent() { // // Form1 // //this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); //this.ClientSize = new System.Drawing.Size(292, 273); this.Name = "Form1"; this.ShowInTaskbar = false; this.Load += new System.EventHandler(this.Form1_Load);
}
private void Form1_Load(object sender, System.EventArgs e) {
} public void HideApp() { this.WindowState = FormWindowState.Minimized; Hide(); } public void ShowApp() { Show(); this.WindowState = FormWindowState.Normal; } [STAThread]
static void Main() { Application.Run(new Form1());
}
}
|
| Sign In·View Thread·PermaLink | 1.50/5 |
|
|
|
 |