gmtongar wrote:
Hi,
I've made a custom scrollbar which consists of three buttons and a panel. My problem is: How do I move it like a scrollbar slider? I've tried DoDragDrop, but it does not appear to be the same, all though I can move the button. I have also used the mouseMove event, so I can move the button, but it's completely out of control. Still I feel it's the right way to go. This is what I've written:
private void btnSecond_Mouse Move(object sender, System.Windows. Forms.MouseEven tArgs e)
{
if (MouseButtons.L eft == e.Button)
{
btnSecond.Top = e.Y;
PositionToValue (btnSecond.Top) ;
}
}
private int PositionToValue (int pos)
{
return (_maxValue / (panelArea.Heig ht-btnSecond.Heigh t)) * pos;
}
Anyone who can help me out?
Thanks, gmtongar
Here is what I did to "drag drop" my form that had no title bar.
//First create three global variables
int curDifX,curDifY ;
bool drag = false;
//now to the event handlers
private void button_MouseDow n(..)
{
//not sure about button.Left here but it should be the position of your
button
curDifX = Cursor.Position .X-button.Left;
curDifY = Cursor.Position .Y-button.Top;
drag = true;
}
private void button_MouseMov e(...)
{
if (drag)
{
button.Left = Cursor.Position .X-curDifX;
button.Top = Cursor.Position .Y-curDifY;
}
}
//and finally
private void button_MouseUp( ...)
{
drag = false;
}
This will make it look like you are able to click hold, move and drop a
button. In your case, since it is a slider, you could only monitor the X
value of the mouse, which would only allow you to move the control
horizontally.
Hope I understood your question correctly.
Nick Z.