הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Saturday, April 18, 2009 3:53 AM
is it possible to have a drop down menu from a button, somewhat similar to windows right click on a file, except, click/double click a button.
if you do answer, can you provide a sample code, let's say, option1 (on the drop down menu) get's text to change to bold, option 2 to italic, and so on..
guess i lost my nut again...just a squirrel looking for my nut...
All replies (6)
Saturday, April 18, 2009 4:49 AM ✅Answered
If you would rather it fall completely under the button rather than covering a bit of the button, then you can use this to alter the positioning:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ContextMenuStrip1.Show(Button1, Button1.Location.X - 10, Button1.Location.Y + 10)
End Sub
Hope this helps!Hobbyist programmer: VB.NET, C++, Pascal
Thursday, June 25, 2009 6:37 PM ✅Answered
Yes I noticed that when I tried to add it to an existing button, it ended up somewhere else. It's a bug. However it went away after I tried again with a new project. Just put 5 new buttons on the form and try again. Then add 5 ContextMenuStrips to the form and call the appropriate one from your button click event. Should work!
Hobbyist programmer: VB.NET, C++, Pascal
just added this reply, since it needed the fixed location problem solved..
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
ContextMenuStrip1.Show(Button1, e.Location)
End If
End Sub
help out microsoft for helping you.. test run 7
Saturday, April 18, 2009 4:32 AM
Well you can add a ContextMenuStrip to your form, and then use on the button click event:
ContextMenuStrip1.Show(Button1, Button1.Location.X, Button1.Location.Y)
That will set it so it opens under the button when you click it. You can set the fonts and style of the items from the ContextMenuStrip's properties.Hobbyist programmer: VB.NET, C++, Pascal
Saturday, April 18, 2009 5:09 AM
it's good, just not what i expected..
i'm looking for something that has, let's say 5 buttons, and each button should have it's own personal drop down menu . possible?
also, with the code above, the drop down menu ends up on the right side of the screen and nowhere close to my button. ;o/
thanx to you, i'm that much closer and now i know a little bit more about context menus. never used them before. :O) nice.just a squirrel looking for my nut...
Saturday, April 18, 2009 5:13 AM
Yes I noticed that when I tried to add it to an existing button, it ended up somewhere else. It's a bug. However it went away after I tried again with a new project. Just put 5 new buttons on the form and try again. Then add 5 ContextMenuStrips to the form and call the appropriate one from your button click event. Should work!Hobbyist programmer: VB.NET, C++, Pascal
Saturday, April 18, 2009 5:15 AM
never mind about the 5 buttons, and each button should have it's own personal drop down menu .
i figured it out. just add another context menu.. which i did, they just kept dissapearing until i found them in the properties section..
now i just need the location fix and to figure out how to add all the responses on this post as answered...
just a squirrel looking for my nut...