Can someone tell me how I can move an object, in this case a listbox, over a
form. The code below works, but not when the form is custom sized. It works
perfectly when the form is maximized. And what is the best way to give the
object boundries to move within?
Hope someone can help me.
TIA,
Arjan.
/*Begin Code*/
/*Source: MSDN*/
void ListBox1MouseDo wn(object sender, System.Windows. Forms.MouseEven tArgs e)
{
int xOffset;
int yOffset;
if(e.Button == MouseButtons.Le ft)
{
xOffset = -e.X - SystemInformati on.FrameBorderS ize.Width;
yOffset = -e.Y - SystemInformati on.CaptionHeigh t -
SystemInformati on.FrameBorderS ize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}
void ListBox1MouseMo ve(object sender, System.Windows. Forms.MouseEven tArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePo sition;
mousePos.Offset (mouseOffset.X, mouseOffset.Y);
listBox1.Locati on = mousePos;
}
}
void ListBox1MouseUp (object sender, System.Windows. Forms.MouseEven tArgs e)
{
isMouseDown = false;
}
/*End Code*/
form. The code below works, but not when the form is custom sized. It works
perfectly when the form is maximized. And what is the best way to give the
object boundries to move within?
Hope someone can help me.
TIA,
Arjan.
/*Begin Code*/
/*Source: MSDN*/
void ListBox1MouseDo wn(object sender, System.Windows. Forms.MouseEven tArgs e)
{
int xOffset;
int yOffset;
if(e.Button == MouseButtons.Le ft)
{
xOffset = -e.X - SystemInformati on.FrameBorderS ize.Width;
yOffset = -e.Y - SystemInformati on.CaptionHeigh t -
SystemInformati on.FrameBorderS ize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}
void ListBox1MouseMo ve(object sender, System.Windows. Forms.MouseEven tArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePo sition;
mousePos.Offset (mouseOffset.X, mouseOffset.Y);
listBox1.Locati on = mousePos;
}
}
void ListBox1MouseUp (object sender, System.Windows. Forms.MouseEven tArgs e)
{
isMouseDown = false;
}
/*End Code*/
Comment