Update trackbar value on mouse wheel - c#

I am using the scroll event but this only update value in label when i click on trackBar and move it right or left. I see that i can move it when i use mouse wheel but this doesn't update value in label just moving it.
private void metroTrackBar1_Scroll(object sender, ScrollEventArgs e)
{
lblVolume.Text = metroTrackBar1.Value.ToString();
}
So my question is:
How I can make trackBar to update value in label when i scroll with mouse wheel?

I found solution, used ValueChanged event instead of Scroll event, this works in both cases, when i move trackBar with mouse wheel or when i drag it with mouse.
private void metroTrackBar1_ValueChanged(object sender, EventArgs e)
{
lblVolume.Text = metroTrackBar1.Value.ToString();
}

Related

Mouse Cursor Flickering while peforming DragOver event on Panel control in winform in C#

I am trying to implement a DRAG DROP event in windows form. The Drag event starts when I select some text in text box, click and hold the right mouse button and start dragging the text from the text box, passes over a panel(Right mouse button still hold/clicked) and then the dragged text has to be dropped over a tree view(release right mouse button).
I want my mouse cursor to change when i am dragging over the panel control. The Cursor do change to my expected cursor icon as of now but it flickers a lot and cursor image is not constant.
I am implementing the logic in Drag Over event handler which i think gets fired again and again automatically while dragging and this results in flickering or some sort of refreshing.
My implementation is as follows:
ABC.Desginer.cs:
this.splitterPanel.DragOver += new System.Windows.Forms.DragEventHandler(this.splitterPanel_DragOver);
ABC.cs:
private void splitterPanel_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
Bitmap bmp = new Bitmap(ABC.DefInstance.ImageList1.Images[3]);
Cursor c = new Cursor(new Bitmap(bmp, 32, 32).GetHicon());
frmFlat2Obj.DefInstance.splitterPanel.Cursor = c;
DestroyIcon(c.Handle);
}
}
My question is: How exactly shall I stop or reduce the mouse cursor flickering while dragging over the Panel??
THANKS IN ADVANCE :)

Change cursor permanent to specific cursor on the whole screen

I have a easy winform with a button on it.
When I press the button, the cursor is like 1ms the cursor I want it to be, but than it instantly changes back to the default cursor.
How can i keep the cursor a cross? (Not only on the form, everywhere on the screen)
private void btn_takeScreenshot_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.Cross;
}

Receiving MouseMove events from parent control

I have a WinForm application that has a panel and two buttons inside the panel. I added a mousemove event on my panel and the mousemove function gets called when I move the mouse inside my panel, just like expected.
The problem is, if I press down my mouse button while over a button, the button depresses and if I move my mouse into the panel while still holding down the button, the Panel mousemove function never gets called till I release the mouse button.
Is there a work around for this? And if I'm not being clear, I can try to be more clear.
So it seems that while the button is depressed and the mouse moved back over the underlying panel, the panel's MouseMove event is not fired.
You can capture the pointer position at this time by hooking into the button's MouseMove. BUT, the pointer's position will be relative to the button, not the panel, so you need to add these coordinates to the button's location coordinate:
Point mousePoint;
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
mousePoint = e.Location;
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
mousePoint = new Point(button1.Location.X + e.Location.X, button1.Location.Y + e.Location.Y);
}

How can I make an imitation of a button control with a picture box, that behaves exactly like a button?

Buttons do that: if the user preses and holds he left mouse button over a button control and moves the cursor out of the control, the button control changes it's appearance back to default, and if the mouse button is still being held, and the cursor enters a button control, the control changes it's appearance to it's pressed version. I'm trying to imitate a button using a PictureBox, but when the mouse leaves the PictureBox before the left mouse button is released, the PictureBox's picture doesn't change until the mouse button is released.
I'm trying to do this because the button control can't look the way I want to.
How can I make an imitation of a button control with a picture box, that behaves exactly like a button?
This is by design, the control sets the Capture property to true so it will keep receiving mouse messages while the button is held down when you move the mouse outside of the control rectangle.
You could turn it off when you see it moving out:
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) {
var box = (PictureBox)sender;
if (!box.DisplayRectangle.Contains(e.Location)) box.Capture = false;
}
Try using the DragLeave event as opposed to the MouseLeave event.

C# triggering MouseEnter even even if mouse button is held down

I have this problem that event called "MouseEnter" does not fire when mouse button is held down. How could i fix it?
That's by design. You can work around it by using, say, MouseMove:
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point pt = TargetControl.PointToClient(Cursor.Position);
Rectangle rc = TargetControl.ClientRectangle;
if (rc.Contains(pt))
{
// do what would be done on MouseEnter
}
}
}
This is not ideal, though - if the mouse button is pressed when the mouse is hovering over another control on the form, then it doesn't appear in the MouseMove event that the button is pressed (as #Hans pointed out, the other control 'Captures' the MouseDown). If that's a problem, then combining the hit test in MouseMove while separately tracking MouseDown and MouseUp on the form should work.

Categories