【问题标题】:c# win form , Get CELL Location in DataGridViewc# win form , 在 DataGridView 中获取 CELL 位置
【发布时间】:2021-06-06 17:26:24
【问题描述】:

当我在我的 Winform 项目中单击 DataGridView 中的特定单元格时,比如说 ColumnIndex 5 ,然后我想在与单击的单元格相同的位置弹出或打开一个小表单(不是 MessageBox)。现在,当我单击特定单元格时,我的表单将在屏幕中心打开。但我不会在单击的单元格的相同位置或位置打开 iy。我不知道如何,但我认为我需要获取单击单元格的位置或位置,以及如何集成到弹出表单。 这是我的代码,当我单击 ColmnIndex 5 时,测试表单会在屏幕中间打开

private void dgvComputersAdgv_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
     if (e.ColumnIndex == 5)
     { 
        Test ts = new Test(); 
        ts.ShowDialog();
     }
}

提前谢谢你!

【问题讨论】:

  • GetCellDisplayRectangle 也许?
  • @Jimi 非常感谢。非常有用的链接。
  • @Charlieface,谢谢查理的回复,我从 Jimi.l 得到了一个非常有用的链接

标签: c# winforms datagridview cell


【解决方案1】:

看来可能是表单的 StartPosition 属性设置。 默认选项显示为 Manual、CenterScreen、WindowsDefaultLocation、WindowsDefaultBounds 和 CenterParent。单击要在设计视图中调整 StartPosition 的窗体的空白区域。试试 CenterParent 或 Manual 看看是否能让你更接近。否则,您将需要将 FormName.Designer.cs - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen 更新为保存位置的 this.Position = System.Windows.Forms.FormStartPosition.custom 变量...... ....

【讨论】:

  • 感谢您的回复,但我想在单击特定单元格时将其打开为与单击的单元格相同的位置。我从 Jimi 那里得到了这个链接,他对我很好......这个stackoverflow.com/questions/47359798/…
猜你喜欢
  • 1970-01-01
  • 2011-05-16
  • 2010-11-18
  • 1970-01-01
  • 1970-01-01
  • 2018-05-15
  • 1970-01-01
  • 1970-01-01
  • 2011-05-22
相关资源
最近更新 更多