c# winform 模拟触发鼠标点击按钮

模拟触发鼠标点击winform数据表控件列点击事件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DXApplication1
{
    public partial class Form1 : DevExpress.XtraEditors.XtraForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if(e.ColumnIndex == 0)
            {
                MessageBox.Show("点击第一列触发");
            }
            if(e.ColumnIndex == 1)
            {
                MessageBox.Show("点击第二列触发");
            }
            if(e.ColumnIndex == 2)
            {
                MessageBox.Show("点击第三列触发");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var s = textBox1.Text;
            MouseEventArgs m = new MouseEventArgs(new MouseButtons(), 0, 0, 0, 0);
            DataGridViewCellMouseEventArgs ex = new DataGridViewCellMouseEventArgs(columnIndex: int.Parse(s), rowIndex: 0, localX: 0, localY: 0, e: m);

            dataGridView1_CellMouseClick(null, ex);
        }
    }
}

你可能感兴趣的:(c#,开发语言)