I have added a listBox containing a list and a toolStrip in my application. These are used to select control to added runtime in a panel. (I have added an image. The toolStrip and listBox are on the left and right side respectively.) Now what I do with these controls is,
1 - I select an item from toolStrip or listBox
2 - A runtime control is made and shown on the form
3 - On Mouse_Up event, the control is set on the Panel (If it is in the panel.)
Now the question is, as shown in the image, the runtime control is not at the tip of the cursor. I want these runtime controls on the tip of the cursor.
Below is the Image.
EDIT: Below is the code.:
private void listBox_MouseDown(object sender, MouseEventArgs e)
{
this.globalLabel1 = new Label();
this.globalLabel1.Text = this.listBox.SelectedItem.ToString() + " : ";
//other label properties like, tag, name, events, font etc.
}
private void listBox_MouseMove(object sender, MouseEventArgs e)
{
if (this.globalLabel1 != null)
{
this.globalLabel1.Left = System.Windows.Forms.Cursor.Position.X
- this.Location.X;
this.globalLabel1.Top = System.Windows.Forms.Cursor.Position.Y
- this.Location.Y;
this.globalLabel1.Show();
this.lPanel.SendToBack();
}
}
private void listBox_MouseUp(object sender, MouseEventArgs e)
{
this.globalLabel1.Parent = this.lPanel;
this.globalLabel1.Anchor = AnchorStyles.Top | AnchorStyles.Left;
this.globalLabel1.Left = Cursor.Position.X
- /*Cursor.Size.Height -*/ this.lPanel.Location.X
- this.Location.X;
this.globalLabel1.Top = Cursor.Position.Y
- /*Cursor.Size.Width -*/ this.lPanel.Location.Y
- this.Location.Y;
}
Thanks.