zoukankan      html  css  js  c++  java
  • Winform datagridview 控制滚轮事件

            /// <summary>
            /// 给datagridview添加鼠标滚轮事件
            /// </summary>
            /// <param name="dataGridView1"></param>
            public static void bindMouseWheel(System.Windows.Forms.DataGridView dataGridView1)
            {
                dataGridView1.MouseWheel += new System.Windows.Forms.MouseEventHandler(dataGridView1_MouseWheel);
                dataGridView1.TabIndex = 0; //获得焦点
            }
    
            private static void dataGridView1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                DataGridView dataGridView1 = sender as DataGridView;
                try
                {
                    if (dataGridView1.CurrentCell != null)
                    {
                        DataGridViewCell dvc = dataGridView1.CurrentCell;
                        int ri = dvc.RowIndex;
                        int ci = dvc.ColumnIndex;
                        if (e.Delta > 0) //向上
                        {
                            if (ri > 0)
                            {
                                dvc = dataGridView1.Rows[ri - 1].Cells[ci];
                                dataGridView1.CurrentCell = dvc;
                            }
                        }
                        else
                        {
                            if (ri < dataGridView1.Rows.Count - 1)
                            {
                                dvc = dataGridView1.Rows[ri + 1].Cells[ci];
                                dataGridView1.CurrentCell = dvc;
                            }
                        }
                    }
                }
                catch
                {
                    return;
                }
            }
    

      

  • 相关阅读:
    活动安排问题
    完美字符串
    Codeforces Round #696 (Div. 2) 解题报告
    Codeforces 1459D
    Codeforces 25D
    POJ 1847
    LightOJ 1074
    POJ 3159
    POJ 1511
    POJ 1502
  • 原文地址:https://www.cnblogs.com/ShaYeBlog/p/2694027.html
Copyright © 2011-2022 走看看