如何通鼠标右键事件 来获取当前控件?又或者先获取焦点也行 再取活动控件..
忘前辈指点一二;在线等......................

解决方案 »

  1.   

    这个问题我之前也问过,没有答案。
    可能是.Net控件在开发时,就没有考虑到这个问题。没办法,我只能加进一些代码处理,比如给 控件添加鼠标右键事件,或键盘按键事件,主动拦截此类事件。虽然不完美,但至少可以基本解决此类问题
      

  2.   

    添加MouseDown事件,事件代码如下:
     private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    MessageBox.Show(ActiveControl.Text);//ActiveControl当前活动控件
                }
            }
      

  3.   

    问题关键之关键 
    是 右键单击后....控件焦点并没有获得转移...也就是说 右键单击的控件并没有获得焦点也就取不到ActiveControlActiveControl只停留在获得焦点的控件上
    关键就是右键事件里 怎么让鼠标位置的控件获得焦点.....再次感谢...热心的前辈
      

  4.   

    ActiveControl.Name获取活动控件name
    ActiveControl.Text获取活动控件Text
      

  5.   

    右键单击的控件.Focus();//加上这句焦点就转移到你想要的控件上了
      

  6.   

    多个相同的控键共用的一个 右键单击事件sender...这个怎么取控件名?前辈
      

  7.   

    控件的快捷菜单清空,然后手动程序显示快捷菜单,并添加如下程序事件    private void textBox_KeyUp(object sender, KeyEventArgs e)
        {
          if (e.KeyCode == Keys.Apps)
          { 
            //用户按下快捷键,执行调用快捷菜单代码
            //注意 上面的 sender 变量存储着触发事件的TextBox对象
          }
        }    private void textBox_MouseUp(object sender, MouseEventArgs e)
        {
          if (e.Button == MouseButtons.Right)
          {
            //用户按下鼠标右键,执行调用快捷菜单代码
            //注意 上面的 sender 变量存储着触发事件的TextBox对象
          }
        }
      

  8.   


    已取到了 对象((Button)sender).Name谢谢 很感谢前辈们的指点
      

  9.   

    强制转换  private void Form1_Load(object sender, EventArgs e)
            {
                this.button2.Click += new EventHandler(button_Click);
                this.button1.Click+=new EventHandler(button_Click);
            }        void button_Click(object sender, EventArgs e)
            {
                if (sender is Button)
                {
                    MessageBox.Show(((Button)sender).Name);
                }
            }
      

  10.   

    上面说的不可以吗
      
       void button_Click(object sender, EventArgs e)
            {
                if (sender is Button)
                {
                    MessageBox.Show(((Button)sender).Name);
                }
            }