I have a windows form where I programmatically create controls.. later I allow them to be moved around per drag&drop that I implemented myself:
private void valueToolStripMenuItem_Click(object sender, EventArgs e)
{
Label label = new Label();
label.Text = "Label";
label.AutoSize = true;
label.Location = PointToClient(MousePosition);
label.MouseDown += new MouseEventHandler(this.dyncontrol_MouseDown);
label.MouseMove += new MouseEventHandler(this.dyncontrol_MouseMove);
label.MouseUp += new MouseEventHandler(this.dyncontrol_MouseUp);
label.ContextMenuStrip = valueContextMenu;
this.Controls.Add(label);
}
combined with these functions:
private void dyncontrol_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
Control control = (Control)sender;
selected = true;
offset.X = PointToClient(MousePosition).X - control.Location.X;
offset.Y = PointToClient(MousePosition).Y - control.Location.Y;
}
}
private void dyncontrol_MouseMove(object sender, MouseEventArgs e)
{
if (selected)
{
Control control = (Control)sender;
Point newLocation = new Point(PointToClient(MousePosition).X - offset.X, PointToClient(MousePosition).Y - offset.Y);
control.Location = newLocation;
}
}
private void dyncontrol_MouseUp(object sender, MouseEventArgs e)
{
selected = false;
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
Control control = (Control)sender;
Point newLocation = new Point(PointToClient(MousePosition).X - offset.X, PointToClient(MousePosition).Y - offset.Y);
control.Location = newLocation;
}
}
this works perfectly fine for pictureboxes, labels, buttons etc.. now I wanted to add a axWindowsMediaplayer and do the same:
private void videoStreamToolStripMenuItem_Click(object sender, EventArgs e)
{
AxWMPLib.AxWindowsMediaPlayer wmp = new AxWMPLib.AxWindowsMediaPlayer();
wmp.Size = new Size(300, 300);
wmp.ContextMenuStrip = valueContextMenu;
wmp.MouseDown += new MouseEventHandler(this.dyncontrol_MouseDown);
wmp.MouseMove += new MouseEventHandler(this.dyncontrol_MouseMove);
wmp.MouseUp += new MouseEventHandler(this.ddyncontrol_MouseUp);
this.Controls.Add(wmp);
wmp.uiMode = "none";
wmp.Ctlenabled = false;
wmp.URL = "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv";
}
but I can't drag the Player(MouseDown and MouseUp are not firing) around and also the contextmenu isn't the right one, but a standard thing that appears as if I hadn't changed anything..
Any ideas why this is so?
I already tried to delete the reference in the project and add it again..