ContextMenuStrip from a left click on a Notify Icon

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?cHJvZ2dlcg==?=

    ContextMenuStrip from a left click on a Notify Icon

    I've written an application that can minimize to the tray and can reappear if
    you double click on the icon in the tray (ShowInTaskbar is set to false).
    I've also created a ContextMenuStri p (Visual C# 2005) so that you can write
    click on the icon in the tray for options. I then captured the event for
    mouse clicks on the Notify Icon so that I could detect the left click event
    and then display the contextmenustri p using either:
    contextMenuStri p1.Show(this,
    this.PointToCli ent(Cursor.Posi tion));
    or:
    contextMenuStri p1.Show(this.Po intToClient(Cur sor.Position));

    This works well and displays the contextmenustri p appropriately, however
    whilst doing this it also creates an icon for the application in the taskbar
    which isn't intended as the form has been set to ShowInTaskbar = false. I've
    also tried using a dummy control as the parameter to show to no avail.
  • Linda Liu [MSFT]

    #2
    RE: ContextMenuStri p from a left click on a Notify Icon

    Hi Simon,

    I performed a test based on your description and did see the problem.

    I also performed a test on ContextMenu and found that the problem doesn't
    exist on ContextMeu. So it looks to me like a limitation of
    ContextMenuStri p.

    I have searched in our inner database. However, I didn't find a similar
    issue in it.

    As for a workaround, I think you have two options.

    One option is to use ContextMenu intead of ContextMenuStri p.

    The other is to set the ContextMenuStri p property of the NotifyIcon to the
    ContextMenuStri p on your form. Thus, you could show up the ContextMenuStri p
    by right-clicking the NotifyIcon in the system tray.

    Hope this helps.
    If you have any question, please feel free to let me know.


    Sincerely,
    Linda Liu
    Microsoft Online Community Support

    =============== =============== =============== =====
    Get notification to my posts through email? Please refer to
    Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

    ications.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscripti...t/default.aspx.
    =============== =============== =============== =====

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comment

    • =?Utf-8?B?cHJvZ2dlcg==?=

      #3
      RE: ContextMenuStri p from a left click on a Notify Icon

      Hi Linda,
      Many thanks for your response. Unfortunately I am already using the
      ContextMenuStri p property of the Notify Icon but as you state this only works
      for right clicks and not also for left clicks hence the addtional code I
      spoke of.

      Do you know if there are any plans for Microsoft to fix this bug or do you
      know if there are any other work arounds? If I remember correctly, by using
      just ContextMenu instead you don't get the Office 2003 style menus.

      Thanks

      Comment

      • Linda Liu [MSFT]

        #4
        RE: ContextMenuStri p from a left click on a Notify Icon

        Hi Simon,

        Thank you for your prompt response.

        I will report this issue to our product team to ask if there's a better
        workaround. And I will get the result back to you ASAP. I appreciate your
        patience.

        Sincerely,
        Linda Liu
        Microsoft Online Community Support

        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

        ications.

        Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 1 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions or complex
        project analysis and dump analysis issues. Issues of this nature are best
        handled working with a dedicated Microsoft Support Engineer by contacting
        Microsoft Customer Support Services (CSS) at
        http://msdn.microsoft.com/subscripti...t/default.aspx.
        =============== =============== =============== =====

        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        • Linda Liu [MSFT]

          #5
          RE: ContextMenuStri p from a left click on a Notify Icon

          Hi Simon,

          I received a response from our product team. The following is the response
          I received.

          The reason it works as a ContextMenu and not when Show is just called is
          that the NotifyIcon p/invokes SetForgroundWin dow before showing its
          ContextMenu. To get this behavior, the user would have to do the same and
          p/invoke SetForegroundWi ndow in the notifyIcon1_Cli ck EventHandler:

          using System.Runtime. InteropServices ;

          [DllImport("User 32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
          public static extern bool SetForegroundWi ndow(HandleRef hWnd);

          void notifyIcon1_Cli ck(object sender, EventArgs e)
          {
          SetForegroundWi ndow(new HandleRef(this, this.Handle));

          this.contextMen uStrip1.Show(th is, this.PointToCli ent(Cursor.Posi tion));
          }

          I have tested the above code on my machine and confirmed it works.
          If you have any question, please feel free to let me know.


          Sincerely,
          Linda Liu
          Microsoft Online Community Support

          Comment

          • Linda Liu [MSFT]

            #6
            RE: ContextMenuStri p from a left click on a Notify Icon

            Hi Simon,

            How about the problem now?

            If the problem is still not solved, please feel free to let me know.

            Thank you for using our MSDN Managed Newsgroup Support Service!

            Sincerely,
            Linda Liu
            Microsoft Online Community Support

            Comment

            Working...