0

I want to create a button that when clicked, a menu will be shown. I want it to look like this (with an arrow on the side):

contextMenuStrip output

I tried the following code on the onClick event:

Button btnSender = (Button)sender;
Point ptLowerLeft = new Point(0, btnSender.Height);
ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
contextMenuStrip1.Show(ptLowerLeft);

but the output is this:

code output

How can I create a button with an arrow on the right and the menu will show right next to it when clicked?

ThEpRoGrAmMiNgNoOb
  • 1,256
  • 3
  • 23
  • 46

3 Answers3

1

The very hort answer is that I think you confused width with height. Just exchange the line

Point ptLowerLeft = new Point(0, btnSender.Height);

with

Point ptUpperRight = new Point(btnSender.Width, 0);

However, there is usually more to do. Especially, depending on the buttons position, the context menu may show up outside the visible area of the screen. I think the easiest solution would be to use a toolbar control. As far as I remember there is a control that supports this behavior.

Georg
  • 5,626
  • 1
  • 23
  • 44
1

To add to Georg's answer: To add an Image you simply write:

button1.Image = Image.FromFile(yourImageFile); // or a resource etc..
button1.ImageAlign = ContentAlignment.MiddleRight;
button1.TextAlign = ContentAlignment.MiddleLeft;
TaW
  • 53,122
  • 8
  • 69
  • 111
0

Why dont you use menu instead of button or you can add a background image with a small arrow which you can make visible on hover or on button click