Pop up menu from Button Click.

Hi,

I need to show a pop up menu when user click a button.
After the user click one of the menu then I need to do something.
This is windows form.

Please help how to do it.

Thank you.
LVL 1
emi_sastraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
emi_sastra,

Add a ContextMenuStrip control to your form, adding items and using each items Click event to perform the required action. Then use the attached code to show the menu when the user clicks the button.

Wayne
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        With CType(sender, Button)
            Me.ContextMenuStrip1.Show(.Left + Me.Left, .Top + Me.Top)
        End With
    End Sub

Open in new window

0
emi_sastraAuthor Commented:
Hi,

The button is inside a flowlayoutpanel and the flowlayoutpanel  is inside a windows form and the windows form is inside a mdiform.

When I try your code, it displayed at the top of of the a mdi form.

Thank you.

0
Wayne Taylor (webtubbs)Commented:
Adjust the position as required.
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

emi_sastraAuthor Commented:
Hi,

Why we have to do it manually?
Is there any other better way?

Thank you.
0
Wayne Taylor (webtubbs)Commented:
>>Is there any other better way?
No. Although, when I said "Adjust the position as required", I meant use the position of all the other container controls to get the location.....
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        With CType(sender, Button)
            Me.ContextMenuStrip1.Show(.Left + Me.Left + FlowLayoutPanel1.Left + ChildForm.Left, .Top + Me.Top + FlowLayoutPanel1.Top + ChildForm.Top)
        End With
    End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
emi_sastraAuthor Commented:
Hi,

Yes, your above code is what I meant a better way, not manually adjust.

Thank you very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.