|
|
thanks very much dave.. i was wery big help.
but how shut i get the application name which user has clict on.
thanks very mutch
|
|
|
|
|
Not sure - I just came accross that article the other day when searching for info for someone else!
This one[^] captures the App name so you should be able to figure it out from the source.
Don't forget to use the CP search function - that's how I found them
Dave
|
|
|
|
|
I was creating my tray icon for a console application using NotifyIcon Class adn it is working fine (it creates the icon)
However it dosent seem to run the event handlers (click events) on the icon..
Please guide me..
Here is my simple test program which dosent run the mouse events..
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.MyMethod();
}
void MyMethod()
{
NotifyIcon tray = new NotifyIcon();
tray.Icon = new Icon("MyIcon.ico");
tray.Visible = true;
tray.MouseClick += new MouseEventHandler(tray_MouseClick);
tray.Click += new EventHandler(tray_Click);
tray.DoubleClick += new EventHandler(tray_DoubleClick);
Console.Read();
}
public void tray_MouseClick(object sender, MouseEventArgs e)
{
Process.Start(@"C:\Windows\Notepad");
Console.WriteLine("Hello World!");
}
public void tray_Click(object sender, EventArgs e)
{
Console.WriteLine("Hello World!");
}
public void tray_DoubleClick(object sender, EventArgs e)
{
Console.WriteLine("Hello World!");
}
}
|
|
|
|
|
Where is your Application.Run ?
|
|
|
|
|
leppie wrote: Where is your Application.Run?
This is just a test to see whether on clicking the icon, the "Hello World" is printed to the console..
This is not a forms application, this is a console application.
I put a breakpoint on the code in the tray_MouseClick, trayClick, and tray_DoubleClick and it dosent hit the break points..
|
|
|
|
|
ptr2void wrote: This is not a forms application, this is a console application.
I know that, but how the hell is a Winform control suppose to respond if your app does not have a friggen message loop????
Thats why you need Application.Run . It will not work any other way.
|
|
|
|
|
tray.Click += new System.EventHandler(this.notifyIcon1_Click);
tray.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseClick);
tray.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDoubleClick);
|
|
|
|
|
Abhijit Jana wrote: tray.Click += new System.EventHandler(this.notifyIcon1_Click); tray.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseClick); tray.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDoubleClick);
hi, thanks for the answer, but it still dosent seem to work..
Here is my edited code, but still of no use..
static void Main(string[] args)
{
Program p = new Program();
p.MyMethod();
Console.Read();
}
void MyMethod()
{
NotifyIcon tray = new NotifyIcon();
tray.Icon = new Icon("Mcafee.ico");
tray.Visible = true;
tray.MouseClick += new System.Windows.Forms.MouseEventHandler(this.tray_MouseClick);
tray.Click += new EventHandler(this.tray_Click);
tray.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.tray_DoubleClick);
}
public void tray_MouseClick(object sender, MouseEventArgs e)
{
Process.Start(@"C:\Windows\Notepad");
Console.WriteLine("Hello World!");
}
public void tray_Click(object sender, EventArgs e)
{
MessageBox.Show("Hi");
}
public void tray_DoubleClick(object sender, EventArgs e)
{
Console.WriteLine("Hello World!");
}
|
|
|
|
|
are you getting any error ?
|
|
|
|
|
No I am not getting any errors..
The application is running fine waiting for my input (Console.ReadLine)..
But when I click the icon in the system tray, nothing happens..
I even tried adding breakpoints at the starting brace of the three methods: tray_MouseClick, tray_Click, tray_DoubleClick
But these breakpoints are never hit.
|
|
|
|
|
ok, let me check, i will back when done !!
Thanks
|
|
|
|
|
do one thing.
Do the same program in windows. Then Check the Designer.Cs Code.
|
|
|
|
|
Thanks abhijit for the answer, but yaar this icon needs to be for a console application only..
I am developing a console application and want a notify icon for an console application and not a windows form.
I'd really appreciate if anyone could help me out.
|
|
|
|
|
|
I don't often write console apps so if this is incorrect - someone please point it out!
Although you can create a notify icon in a console app, I don't believe you can interact with it from one.
I think one way to do this is to launch an invisible winforms app that handles the notify icon and attach the console app's process to it so the winforms app can redirect the output.
Alternatively, you may be able to do some Pinvoke[^] stuff to catch the messages.
Dave
|
|
|
|
|
Okay, this doesn't work because a console application is not event driven. It just sits there and waits, when its waiting for your input its because you called the method Read or ReadLine otherwise it wouldn't know you had pressed any keys.
Windows applications listen for messages that the OS sends it, so when you click something the OS will send a message to the application which contains information on what what was clicked, where, with what button etc. To use these messages you need to use Application.Run otherwise the OS will not send any messages to your application (or the application will ignore them, either way).
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Seeing as no one had the decency to just give you the code:
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace NotifyIconTest
{
class Program : ApplicationContext
{
static void Main(string[] args)
{
Application.Run(new Program());
}
public Program()
{
MyMethod();
}
void MyMethod()
{
NotifyIcon tray = new NotifyIcon();
tray.Icon = new Icon("MyIcon.ico");
tray.Visible = true;
tray.MouseClick += new MouseEventHandler(tray_MouseClick);
tray.Click += new EventHandler(tray_Click);
tray.DoubleClick += new EventHandler(tray_DoubleClick);
tray.ShowBalloonTip(10000, "Hello", "World", ToolTipIcon.Info);
}
public void tray_MouseClick(object sender, MouseEventArgs e)
{
Process.Start(@"C:\Windows\Notepad"); Console.WriteLine("Hello World!");
}
public void tray_Click(object sender, EventArgs e)
{
Console.WriteLine("Hello World!");
}
public void tray_DoubleClick(object sender, EventArgs e)
{
Console.WriteLine("Hello World!");
}
}
}
For explanations of the ApplicationContext see the other replies.
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
I want to learn C# and .net. your example "Hello, World" depresses me.
I will plod on.
p.s.
ain't you ed. Just the complexity of .net's hello world.
Charlie Gilley
Will program for food...
|
|
|
|
|
It's not complex, if you're just starting to learn then what you're trying to do is reasonably complex and not many "simple" apps do it. So it was just a bad choice so to speak.
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
Hello everyone,
I understand what is event log source name, i.e. mentioned here in MSDN -- "The event source indicates what logs the event. It is often the name of the application, or the name of a subcomponent of the application, ..."
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.lognamefromsourcename(VS.80).aspx
But what does the log name mean (in EventLog.LogNameFromSourceName API as mentioned in above link)?
thanks in advance,
George
|
|
|
|
|
Hey guys,
I'm trying to port a Java application to C#. The Java code makes heavy use of the dnsjava library, located here: http://www.dnsjava.org/[^]. I'm wondering what the best equivalent C# library would be. Any ideas?
Thanks,
klk
|
|
|
|
|
I dont know dnsjava, but there are some functionality for DNS in .NET.
System.Net.Dns
|
|
|
|
|
How to intercept request/responce sequence from IE (generally, WebBrowser control or csExWB) and be able to set other data as request / responce? Like I need not to send this request via default proxy, but to send it via WebRequest.
|
|
|
|
|
Hey all. Im making an application at the moment which [on a schedule] backs up certain files to an ftp server. Now my question is, how do I backup a sql/mysql database without stopping it?
Thanks alot in advance!
|
|
|
|