DataGridView 指定位置添加按钮

注:此方法添加的按钮固定位置,不能移动,如果想跟着dgv滚动条拉动移动,最好是重写

 

System.Windows.Forms.Button btn = new System.Windows.Forms.Button();//创建Buttonbtn
btn.Text = "<";//设置button文字
btn.Font = new System.Drawing.Font("Arial", 5);//设置文字格式
btn.Visible = true;//设置控件允许显示
btn.Width = 30;//获取单元格高并设置为btn的宽
btn.Height = this.dgv.GetCellDisplayRectangle(1,19, true).Height - 2;//获取单元格高并设置为btn的高
btn.Click += Btn_Click;
this.dgv.Controls.Add(btn);
btn.Location = new System.Drawing.Point(((this.dgv.GetCellDisplayRectangle(1,19, true).Right) -
70), this.dgv.GetCellDisplayRectangle(1, 19, true).Y);//设置btn显示位置

 

private void Btn_Click(object sender, EventArgs e)
{
  if (index == 0) index = templine.numVerts();
  index--;
  dgv.Rows[19].Cells[1].Value = index + 1;
  OdGePoint3d point = new OdGePoint3d();
  templine.getPointAt(index, point);
  dgv.Rows[20].Cells[1].Value = point.x;
  dgv.Rows[21].Cells[1].Value = point.y;
  dgv.Rows[22].Cells[1].Value = point.z;
}

posted @ 2021-03-01 09:43  月下独酌孤醉  阅读(314)  评论(0)    收藏  举报