Results 1 to 13 of 13

Thread: [RESOLVED] selecting a menu item with 1 click rather than 2

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Location
    vermont usa
    Posts
    72

    Resolved [RESOLVED] selecting a menu item with 1 click rather than 2

    I have two forms form1 and form 2.
    form2 has a menu strip with an item -- tools and a subitem item1

    form1 is loaded first and in form1.load form2 is shown

    now select form 1 by clicking on it.

    now form1 has the focus and form2 does not.

    move the mouse over the form2 menu item tools and click on it. -- nothing happens except form 2 now has the focus. now click
    again on tools and the dropdown appears.

    is this the way it is supposed to work. no other windows application seems to work in this way. for example open two
    notepads. then clicking on an item of one of them regardless of whether it has the focus will display the dropdown.

    hopefully there is something I can do to overcome this awkward and not very useful behavior

    thanks,

    follys

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: selecting a menu item with 1 click rather than 2

    is this the way it is supposed to work.
    Nope. Which is why it doesn't. I'm completely unable to replicate the problem as you state it. As you haven't supplied us with any code I've no idea what but there is clearly something about your program which overrides the normal behaviour.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Location
    vermont usa
    Posts
    72

    Re: selecting a menu item with 1 click rather than 2

    I have used vb.net to create form1 and form 2.
    in form2 I have from the toolbox selected menustrip
    in the menustrip I have the main item of tools.
    a subitem of item1.

    and that's all there is!

    follys

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: selecting a menu item with 1 click rather than 2

    Quote Originally Posted by follys View Post
    I have two forms form1 and form 2.
    Actually that seems to be the normal behavior for the menu strip control, at least thats what I'm seeing here using menu strips.
    Now if I use the "MainMenu" control on both forms instead then it works (and looks) just the way notepads work and the menu opens even when the form doesn't have focus as you want.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: selecting a menu item with 1 click rather than 2

    Quote Originally Posted by follys View Post
    no other windows application seems to work in this way.
    That's a big call. How many other Windows applications did you test? Just Notepad? I just tested Outlook 2013 and it doesn't respond to clicks on ribbon tabs or items if the window doesn't have focus.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Addicted Member
    Join Date
    Oct 2012
    Location
    Springfield, IL
    Posts
    142

    Re: selecting a menu item with 1 click rather than 2

    follys i understand your question. I asked the same question for a toolstrip in this tread. Scroll down to the bottom to find the code for the toolstrip and perhaps it can be modified for a menustrip.

    Edit.. yes the code can be modified to work with the MenuStrip.

    vb.net Code:
    1. Public Class MenuStripEx
    2.     Inherits MenuStrip
    3.  
    4.     Public Sub New()
    5.         MyBase.New()
    6.     End Sub
    7.  
    8.     Private m_clickThrough As Boolean = False
    9.  
    10.     ''' <summary>
    11.     ''' Gets or sets whether the MenuStripEx honors item clicks when its containing form does
    12.     ''' not have input focus.
    13.     ''' </summary>
    14.     ''' <remarks>
    15.     ''' Default value is false, which is the same behavior provided by the base MenuStrip class.
    16.     ''' </remarks>
    17.     Public Property ClickThrough() As Boolean
    18.         Get
    19.             Return Me.m_clickThrough
    20.         End Get
    21.         Set(value As Boolean)
    22.             Me.m_clickThrough = value
    23.         End Set
    24.     End Property
    25.  
    26.     Protected Overrides Sub WndProc(ByRef m As Message)
    27.         MyBase.WndProc(m)
    28.         If Me.m_clickThrough AndAlso m.Msg = NativeConstants.WM_MOUSEACTIVATE AndAlso m.Result = CType(NativeConstants.MA_ACTIVATEANDEAT, IntPtr) Then
    29.             m.Result = CType(NativeConstants.MA_ACTIVATE, IntPtr)
    30.         End If
    31.     End Sub
    32. End Class
    33.  
    34. Friend NotInheritable Class NativeConstants
    35.     Private Sub New()
    36.     End Sub
    37.     Friend Const WM_MOUSEACTIVATE As UInteger = &H21
    38.     Friend Const MA_ACTIVATE As UInteger = 1
    39.     Friend Const MA_ACTIVATEANDEAT As UInteger = 2
    40.     Friend Const MA_NOACTIVATE As UInteger = 3
    41.     Friend Const MA_NOACTIVATEANDEAT As UInteger = 4
    42. End Class
    Last edited by OICU812; May 24th, 2013 at 07:24 AM.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Location
    vermont usa
    Posts
    72

    Re: selecting a menu item with 1 click rather than 2

    I don't see "mainMenu" control in my toolbox. how do u get it?

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Location
    vermont usa
    Posts
    72

    Re: selecting a menu item with 1 click rather than 2

    thank you. I have added mainmenu control to toolbox by selecting "choose items" from right clicking the toolbox. and it works just like you said.

    the menu strip that Microsoft replaced mainmenu by has that little feature that is really unwelcome.

    again thank you very much.

    follys

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Location
    vermont usa
    Posts
    72

    Re: selecting a menu item with 1 click rather than 2

    I have since ur comment looked at pdf, windows explorer, gmail, windows live mail, and infact visual studio itself. none seem to have this rather awkward feature of requiring the forms' focus before allowing the menu item to be selected. as you point out it is probably not a general feature of the menu control that apps incorporate. but I think that any app that has the sluggish behavior has probably been built with the vb menustrip. I think somebody should fix this.
    follys

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: selecting a menu item with 1 click rather than 2

    Quote Originally Posted by follys View Post
    I think that any app that has the sluggish behavior has probably been built with the vb menustrip.
    Office is not a .NET app and uses a ribbon, so there goes that idea.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: selecting a menu item with 1 click rather than 2

    Quote Originally Posted by OICU812 View Post
    Edit.. yes the code can be modified to work with the MenuStrip.
    Nice one!

    That menu behavior was one of the first things I noticed when switching from VB6 to VB10(net) and I didn't like it either, but if I nitpick at everything I don't like about Windows and .Net I'd never use em.

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] selecting a menu item with 1 click rather than 2

    My guess is that some people considered preferable to make it easy to click and application to give it focus without activating some function of that application. By menus and tool bars not activating on a click when the app doesn't have focus, it means that you don;t have to be careful where you click to activate the app. I don't think that you say that either approach is right or wrong and which is better is a matter of preference but I reckon that that's the thinking behind it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jan 2013
    Location
    vermont usa
    Posts
    72

    Re: [RESOLVED] selecting a menu item with 1 click rather than 2

    makes sense but not consistent. since if you have buttons on the form if you hit the button without giving the form the focus the button runs the event.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width