PC Review


Reply
Thread Tools Rate Thread

NotifyIcon ContextMenu Popup

 
 
=?Utf-8?B?Um9iZXJ0IEJlYXViaWVu?=
Guest
Posts: n/a
 
      8th Sep 2005
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?

 
Reply With Quote
 
 
 
 
Claes.Bergefall
Guest
Posts: n/a
 
      8th Sep 2005
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" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
>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?
>



 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      8th Sep 2005
"Robert Beaubien" <(E-Mail Removed)> schrieb:
>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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

 
Reply With Quote
 
=?Utf-8?B?Um9iZXJ0IEJlYXViaWVu?=
Guest
Posts: n/a
 
      8th Sep 2005
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

"Claes.Bergefall" wrote:

> 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" <(E-Mail Removed)> wrote in
> message news:(E-Mail Removed)...
> >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?
> >

>
>
>

 
Reply With Quote
 
New Member
Join Date: Jun 2011
Posts: 1
 
      8th Jun 2011
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Popup event of MenuItem of ContextMenu of NotifyIcon does not fire =?Utf-8?B?VHJhdmlzIFBldHRpam9obg==?= Microsoft Dot NET Framework 1 9th Feb 2005 04:59 AM
NotifyIcon ContextMenu Bug Derrick Microsoft C# .NET 2 21st Jan 2005 02:14 PM
NotifyIcon and ContextMenu Glen Microsoft C# .NET 3 21st Sep 2004 06:44 PM
ownerDraw MenuItems in ContextMenu from NotifyIcon DalePres Microsoft Dot NET Framework Forms 0 31st Jan 2004 07:30 AM
NotifyIcon.ContextMenu Mike Allen Microsoft C# .NET 0 5th Aug 2003 03:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:42 AM.