0

我有一个 Windows 窗体,我在其中以编程方式创建控件.. 后来我允许它们在我自己实现的拖放中移动:

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);
        }

结合这些功能:

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;
        }
    }

这对图片框、标签、按钮等非常有效。现在我想添加一个 axWindowsMediaplayer 并做同样的事情:

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";
    }

但我不能拖动播放器(MouseDown 和 MouseUp 没有触发),而且上下文菜单也不是正确的,而是一个标准的东西,看起来好像我没有改变任何东西..

任何想法为什么会这样?

我已经尝试删除项目中的引用并再次添加它..

4

0 回答 0