NotifyIcon ContextMenu Popup

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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
 
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.
 
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
 
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.
 
Back
Top