NotifyIcon ContextMenu Popup

G

Guest

I have a windowless notifyicon with a ContextMenu on it. Since there is no
main window with this app, I would like to have a singleclick event on the
icon to open the contextmenu. Creating the eventhandler for the click event
is easy, but the contextmenu.show() method is looking for a windows control
to base the popup on. What control does the right-click use or is there
another way around this?
 
C

Claes.Bergefall

Try creating a window that has 0 width/height and pass
that to the method. An instance of the Control class
should be enough. You will need create the handle before
passing it.

Something like this:

** VB.NET **
Dim c As New Control
c.Size = New Size(0, 0)
c.Visible = True
c.CreateControl()

** C# **
Control c = new Control();
c.Size = new Size(0, 0);
c.Visible = true;
c.CreateControl();

You'll need to experiment with the position of it to get
the menu where you want it.

/claes
 
H

Herfried K. Wagner [MVP]

Robert Beaubien said:
I have a windowless notifyicon with a ContextMenu on it. Since there is no
main window with this app, I would like to have a singleclick event on the
icon to open the contextmenu.

Assign the context menu object to the notify icon's 'ContextMenu' property.
 
G

Guest

I didn't know you could actually create a control without a window. I'
ll try that, but it still doesn't answer what control the menu is using when
it is right-clicked.

Thanx
 
Joined
Jun 8, 2011
Messages
1
Reaction score
0
You could use something like this:


private void notify_Click(object sender, EventArgs e)
{
typeof(NotifyIcon).InvokeMember("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, this.notify, null);
}


It's hacky, but it works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top