Results 1 to 18 of 18

Thread: Correct control for displaying Mouse right click menu?

  1. #1

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Correct control for displaying Mouse right click menu?

    what is the correct control for displaying mouse event -> right click?

    i tried the ContextMenuStrip control but it seems i can't change its location, can i?
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Correct control for displaying Mouse right click menu?

    you need to assign the contextmenustrip to the control you're intending to use it with.
    why do you need to change its location?

  3. #3

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Correct control for displaying Mouse right click menu?

    ok i found the correct answer for re-locate the ContextMenuStrip control

    Code:
    ContextMenuStrip1.show(Me,100,100)
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  4. #4

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Correct control for displaying Mouse right click menu?

    even though i have the solution, How do I assign the contextmenustring to control?

    as for your question: i want it to display a menu when the user right click on a control
    and the location i need is the mouse.x mouse.y position which i already know how to acomplish
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

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

    Re: Correct control for displaying Mouse right click menu?

    Quote Originally Posted by motil View Post
    ok i found the correct answer for re-locate the ContextMenuStrip control

    Code:
    ContextMenuStrip1.show(Me,100,100)
    If you assign your ContextMenuStrip to the ContextMenuStrip of a control, e.g. a Button or a TextBox, then it will appear where the user right-clicks that control. Is that not what you want?
    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

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Correct control for displaying Mouse right click menu?

    Quote Originally Posted by jmcilhinney View Post
    If you assign your ContextMenuStrip to the ContextMenuStrip of a control, e.g. a Button or a TextBox, then it will appear where the user right-clicks that control. Is that not what you want?
    yes i want to assign it to a TabControl, how do i do that ?
    another question, is the ContextMenuStrip is a control?
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  7. #7
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Correct control for displaying Mouse right click menu?

    Every control has a ContextMenuStrip property. Assign your ContextMenuStrip control to that property, and it will appear at the correct location automatically. You do NOT need to handle the mouse click manually, or show the ContextmenuStrip manually.

    You can see in the MSDN page that the ContextMenuStrip inherits from the Control class. So in that sense, yes, it is a control. I think it's kind of a special case though because it does not appear on the form as a usual control, but rather in the component tray (like the file dialogs).
    The OpenFileDialog (for example) does not inherit from Control and hence is not a control.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Correct control for displaying Mouse right click menu?

    in design time, click on your tabcontrol. you'll find the ContextMenuStrip property in the properties window

  9. #9

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Correct control for displaying Mouse right click menu?

    ok, i'm trying now what you guys suggested.
    brb
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

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

    Re: Correct control for displaying Mouse right click menu?

    Quote Originally Posted by motil View Post
    yes i want to assign it to a TabControl, how do i do that ?
    Set the ContextMenuStrip property of the control and select your ContextMenuStrip object from the drop-down list provided.
    Quote Originally Posted by motil View Post
    another question, is the ContextMenuStrip is a control?
    You don't need to ask us that. Open the MSDN Library and look at the documentation for the ContextMenuStrip class. Is the System.Windows.Forms.Control class in its inheritance hierarchy? If so then it's a control, otherwise it's not.
    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

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Correct control for displaying Mouse right click menu?

    ok, my application dynamically create tabs, when a new tab is been created i assign the contextmenustring like this
    Code:
    Dim newTab As New TabPage
                    newTab.ContextMenuStrip = ContextMenuStrip1
                    TabControl1.Width = "500"
                    TabControl1.Height = "500"
                    newTab.Controls.Add(newRichTextBox)
                    TabControl1.TabPages.Add(newTab)
                    TabControl1.SelectedIndex = tabsCounter
                    TabControl1.TabPages(TabControl1.TabPages.Count - 1).Controls.Add(newRichTextBox)
    but the location is not changing correctly
    what am i'm doing wrong?
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

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

    Re: Correct control for displaying Mouse right click menu?

    The TabPage is not the TabControl and vice versa. The tabs across the top are part of the TabControl, not the TabPages. You really need to explain exactly what you're trying to achieve so we don't have to guess.
    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
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Correct control for displaying Mouse right click menu?

    It looks like you are trying to add a contextmenustrip to each tab header. Is that the case? If so, take a look at my signature. I have a codebank submission on a custom TabControl where each TabPage has a TabHeaderContextMenuStrip property. Set that property to your desired ContextMenuStrip, and it will display when you right-click the tab header.

  14. #14

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Correct control for displaying Mouse right click menu?

    Quote Originally Posted by jmcilhinney View Post
    The TabPage is not the TabControl and vice versa. The tabs across the top are part of the TabControl, not the TabPages. You really need to explain exactly what you're trying to achieve so we don't have to guess.
    I'm sorry if i'm not making myself clear, in addition to the fact that my english is not that good my familiarity with .NET is also still in its beginning stage
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

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

    Re: Correct control for displaying Mouse right click menu?

    Quote Originally Posted by motil View Post
    I'm sorry if i'm not making myself clear, in addition to the fact that my english is not that good my familiarity with .NET is also still in its beginning stage
    A lot of people say that but even if you know nothing about programming you still know how you want your application to behave. End users know how to use software, even if they don't know how to create it. The problem is that people have an idea in their head of how their app should behave but they don't convey that when they post. If we have to guess what's required or make assumptions then there's every chance that the answers we give won't actually be to the question you want answered.
    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

  16. #16

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Correct control for displaying Mouse right click menu?

    so... you didn't answered... how many years are you programming ?
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

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

    Re: Correct control for displaying Mouse right click menu?

    Quote Originally Posted by motil View Post
    so... you didn't answered... how many years are you programming ?
    From my profile:
    Started programming at university in 1998 at the age of 28 and haven't stopped since.
    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

  18. #18

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Correct control for displaying Mouse right click menu?

    Nice, your knowledge is really impressing, i have about 6 years of programming but with much simpler languages such asp classic,javascript,vbscript and other Net related lang, i just regret i didn't made the switch to .net much sooner as it looked very intimidating at start.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

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