2

最初我有一个图片框,用户可以在表单上从一个地方移动到另一个地方。我已经处理了图片框的事件,它正在完美地移动。

但是现在用户想要在图片下方显示一个文本。所以我想动态创建一个自定义控件,并在用户控件中添加那个图片框和一个标签控件。

我还将控件的停靠属性设置为 TOP 和 Bottom。现在我的用户控件完全被子控件覆盖了。

之后我想为用户控件处理鼠标事件。但不幸的是,这对我不起作用。

据我了解,现在我无法访问用户控件,而是可以访问用户控件中的子控件,因此用户控件的鼠标事件不起作用。

如果我错了,请纠正我,并提供任何解决方案。

4

1 回答 1

1

好吧,鼠标事件MouseDownMouseUp在鼠标在特定控件上执行某些操作时才会发生。我能给你的最好的提议是捕捉控件中的每个鼠标事件并在userControl

  public UserControl1()
  {
     InitializeComponent();
     this.MouseDown += new MouseEventHandler(this.UserControl1_MouseDown);
     this.comboBox1.MouseDown += new MouseEventHandler(this.comboBox1_MouseDown);
  }

  private void UserControl1_MouseClick(object sender, MouseEventArgs e)
  {
      UCMouseDown();
  }

  private void UserControl1_MouseDown(object sender, MouseEventArgs e)
  {
      UCMouseDown();
  }

  private void comboBox1_MouseDown(object sender, MouseEventArgs e)
  {
      UCMouseDown();
  }

  private void UCMouseDown()
  {
      // Your code
  }
于 2013-09-10T07:07:47.630 回答