Move controls automatically when Dragover on table layout panel in C# - c#

I want to drag button on table layout panel that consist 4 row and 4 button each inside, when dragging over the panel I want the other button automatically move up or down depend on location the current button being drag over.
Example : if I drag new button to button2 , automatically button 2,3,4 move down empty the button2 place. I have tried out mouseUp, mouseDown, MouseMove events of control, but that is not what I am looking for.
Can I do this? If you can give me an idea it will be great.

Related

Picturebox blocks MouseEnter event from firing?

as a part of my WinForms application, I want to move a picturebox (blue box) onto the grid as seen below.
I'm moving the picturebox according to the mouse positions (while the left mouse button is pressed down).
Now my problem is, that when dragging the picturebox over the grid, the MouseEnter event is supposed to be called (each box in the grid is a picturebox in itself, with the event attached to it). The event gets called when simply moving with the mouse over it, but as soon as I'm dragging the blue box over it, it doesn't.
So my question is, is it possible that the picturebox on top (blue box) blocks the MouseEnter event of the picturebox on the bottom from firing? And if so, is there a way to work around it? I've thought about using Drag&Drop, but this seemed as the easier solution.
Thanks in advance.

Clicking lable which is behind picture box

There is a picture box and its onto a lable and when mouse enters the picture box's visibility is turned to false so that the label is shown the problem is I want to make the lable clickable but it's not working ..... I think the mouse enter event is blocking the click every thing is coded I didn't use the drag and drop thing.
If you double click on the label in Winform designer that should take you to the OnClick method for the label. There you can specify what you want to do when the user clicks on it. If you have done this and cant click or see the label. In designer place the label on top of the image, make the label not visible until the picture is hovered then click label.

Button event and states

I have a Windows Form in C# with 4 buttons with different states that I use as a menu.
What is the best way to use/implement the different button states.
Normal --> Mouse Enter, Mouse Leave and Mouse click. On click, that specific button should stay the clicked color and only change back to normal once a different button is clicked. Clicked color should also not change again on mouse enter or mouse leave. Should be flat buttons.
Thanks
change background of all buttons to default on click.
Then apply the Required backrgound to the button which triggered the click event by using the sender variable of the event

How do I prevent the verticalscrollbar in flowlayoutPanel to carousel

I have a FlowLayoutPanel with 50 UserControl and I use this.KeyPreview = true
to catch the event KeyUp in the event handler Form1_KeyUp in the form.
So I can either move the scrollbar manually and select a UserControl or step to the next or previous UserControl in the FlowLayoutPanel by using arrow keyUp or arrow key down buttons. The one that is selected has another background.
This works perfect except when at the entpoint.
But there is a problem when I click the arrow up when displaying UserControl in index 0 the VerticalScrollbar will carousel to the end and when click arrow down when displaying index 49 it will carousel to the beginning.
I have googled for preventing VerticalScrollbar to carousel in general or
for FlowLayoutPanel but there is nothing about this.
Any hints are helpful.
//Tony

Move controls between multiple containers in a single form

The questions says it all.
How can I move a control, say a PictureBox between multiple panels, or betwween a panel and a flow layout panel.
I'm aware I can drag and drop controls between multiple panels and such, however this is does not make the control visually movable between the containers. The mouse only changes to a diferent cursor and after you drag to the other control and release the mouse button the control appears on the other container. I require the control to be visually movable.
Can someone provide a simple example, so I can extract the idea to apply to my situation.
NOTE: Runtime of course.
Assuming you need it runtime:
You can save the control as bitmap using Control.SaveToBitmap method
Create cursor from image.
Set the current cursor which we created from control.
Once drag and drop completed reset the cursor.
Let's take a simple example of dragging a button around.
Suppose you have two types of container controls:
1) an X-Y layout
2) a flow layout (assume left to right)
When you click to drag the button, record the x-offset and y-offset from the click to the top left corner of the control. As well, record the index of the control within the Controls collection.
As the mouse moves, first check if the mouse has changed container controls.
If so, then remove the button from its current parent and add it to the new parent.
If the button is added to a flow control, then you need to calculate the new index. To do this, calculate the distance from the mouse to the closest edge of a bounding box of all other controls. Then if the mouse is left of the center of that control, insert to that control's index minus 1, otherwise insert to the right of that control (index + 1).
If the button is added to an X-Y layout, then the index doesn't matter that much. You can simple just set the button's location relative to the mouse plus the x-offset, and y-offset.
As the mouse is dragging, you will need to force the controls to refresh. I think calling Invalidate() on the container control should be sufficient.
This should give you the basic idea that you could use to start coding something.

Categories

Resources