Location of context menu strip - vb.net

I have a context menu strip on my form which is displayed on right click on the datagridview.
Problem is the menu is displayed on the upper right corner while I want to show it on the location where mouse is clicked.
Please advise.
Thanks

A ContextMenuStrip could be automatically shown by a DataGridView at the location of the MouseDown click event.
For this to happen it is necessary to associate the property ContextMenuStrip to the actual instance of your menu strip. You could do this either by code or directly in the designer
DataGridView1.ContextMenuStrip = ctxMenu;

Related

Devexpress Form With Header Panel (Title) and Menu Below Panel

Can someone give me insight how can I achieve the form with panel title first and then menu bar below panel (barmanager). Because devexpress always put barmanager on top
Thank you
EDIT :
After I add standalonebardock, the result as picture shown below: the red bar is standalonebardock
UPDATE :
After I drag the barmanager menu into standalonedock, now it is already inside the dock. But the menu still on top docking, what I need how to make space above menu so I can write title/image/etc
The StandaloneBarDockControl control allows bars to be displayed at any position within the form, not simply docked to the form’s edge. To do this, create a StandaloneBarDockControl object and add bars to it. Bars can be added to the control at design time or runtime.

How to hide a panel when mouse leave/mouse hover

I have multiple buttons in a Panel. I want to hide the Panel on mouse leave of the panel, or buttons.
The problem is that when my cursor hovers on one button and hovers again on another button, the panel that holds the button will hide because I have panel.hide() code on each mouse_Leave event in the button and on the panel. I want to hide it when the cursor leaves the panel or the button.
It sounds like you basically want the panel hidden at all times unless the cursor is over it, and when the cursor isn't the panel hides again?
You could try keeping the panel hidden by default so it's always that way unless the mouse enter's over it, then it shows. That way, when the mouse leaves the panel again it'll automatically hide.

How can I get mouse location on a button?

VB.NET
Visual Studio
I have several buttons that I add at runtime, and I have a MouseDown event handler for the click event. Left click works just fine, but the right click event fires, but doesn't do what I need it to.
If e.Button = Windows.Forms.MouseButtons.Right Then
If sender.Bounds.Contains(e.Location) = True Then
ContextMenuStrip.Show(Cursor.Position)
End If
End If
I shortened this to make it easier to read.
When I look at e.Location, it shows the mouse location in relation to the button.
So if my button is at 400, 600, the location of the mouse should be in that area, but the mouse location comes back with 20, 30 because it is at 20,30 inside the button.
How can I do this right click event properly?
MouseDown event raises when the mouse is down on your control, so the mouse is surely in your control bounds and you don't need to check if the button contains e.Location.
To show the context menu strip, if you assign the context menu strip to ContextMenuStrip property of your control, then you don't need to do anything and the menu will show automatically. But if for any reason you want to handle MouseDown event, you can use either of these options:
ContextMenuStrip1.Show(DirectCast(sender, Control), e.Location)
ContextMenuStrip1.Show(MousePosition)
Note: Just for learning purpose if you want to check if e.Location is in your button, you can use either of these options:
Button1.ClientRectangle.Contains(e.Location)
Button1.Bounds.Contains(Button1.Parent.PointToClient(Button1.PointToScreen(e.Location)))
Or some other combinations using PointToClient, PointToScreen, RectangleToClient, RectangleToScreen methods of controls.

vb.net winforms datagridview how to tell where the user clicked in a cell

I am adding a custom column to a custom datagridview. One of the options this new datagridcolumn has is the ability show a value and then a button to allow the user to click on the button and something will happen. The button only takes up the right portion of the cell and the rest is a value. This button and value are displayable always and the button should always be able to be clicked on. In datagridview's display mode the value and button are painted. What I need help on is how to tell whether the user clicked on the button portion of the cell. Can someone please provide example code on how to do this?
Thanks,
Greg
Never mind I figured it out. I just put some logic in the cellclick event of the datagridview to get the GetCellDisplayRectangle and converted that to screen points and got where the mouse is on the screen and did a bounds test with the rectangle contains method.

Changing properties of the control that calls a Context Menu

I have 10 PictureBox on a windows form (created in Design View) and a context menu strip is attached to each of them. I am trying to set the property of the PictureBox using the context menu.
For eg If the user selects Red from the context menu a Red picture shows up
I can get the the name of the control that popped the Context Menu strip by
cmStrp1.SourceControl.Name
Is there any way I can use the cmStrp1.SourceControl.Name to get the object/control and set its properties
Just use cmStrp1.SourceControl instead of cmStrp1.SourceControl.Name. You need to cast the control to a PictureBox before using it.