NotifyIcon ContextMenu Popup

Discussion in 'Microsoft Dot NET Framework Forms' started by Guest, Sep 8, 2005.

  1. Guest

    Guest 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?
     
    Guest, Sep 8, 2005
    #1
    1. Advertisements

  2. 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" <> wrote in
    message news:...
    >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?
    >
     
    Claes.Bergefall, Sep 8, 2005
    #2
    1. Advertisements

  3. "Robert Beaubien" <> 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/>
     
    Herfried K. Wagner [MVP], Sep 8, 2005
    #3
  4. Guest

    Guest 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

    "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" <> wrote in
    > message news:...
    > >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?
    > >

    >
    >
    >
     
    Guest, Sep 8, 2005
    #4
  5. Guest

    Loki

    Joined:
    Jun 8, 2011
    Likes Received:
    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.
     
    Loki, Jun 8, 2011
    #5
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xin Huang

    RE: NotifyIcon

    Xin Huang, Jun 25, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    706
    nhansen
    Jun 25, 2003
  2. Julien [CNSX]

    Problem with NotifyIcon

    Julien [CNSX], Jul 4, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    4
    Views:
    1,048
    Julien [CNSX]
    Jul 8, 2003
  3. Naim Rizk

    Re: Service and NotifyIcon

    Naim Rizk, Aug 1, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    2
    Views:
    330
    Naim Rizk
    Aug 2, 2003
  4. Petr Dana

    Focus form after use popup menu in notifyicon

    Petr Dana, Nov 25, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    968
    Petr Dana
    Nov 25, 2003
  5. DalePres

    ownerDraw MenuItems in ContextMenu from NotifyIcon

    DalePres, Jan 31, 2004, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    332
    DalePres
    Jan 31, 2004
  6. Guest
    Replies:
    1
    Views:
    532
    Claes Bergefall
    Mar 15, 2004
  7. ContextMenu Popup event fires twice in RichTextBox.

    , Jan 26, 2005, in forum: Microsoft Dot NET Framework Forms
    Replies:
    2
    Views:
    1,009
  8. Guest

    icons on ContextMenu for new NotifyIcon()

    Guest, Jul 31, 2005, in forum: Microsoft Dot NET Framework Forms
    Replies:
    2
    Views:
    430
    Guest
    Aug 3, 2005
Loading...