Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何防止面板出现在屏幕外?_C#_.net_Datagridview - Fatal编程技术网

C# 如何防止面板出现在屏幕外?

C# 如何防止面板出现在屏幕外?,c#,.net,datagridview,C#,.net,Datagridview,我有一个包含datagridview的表单。每当用户单击一行时,该行下方就会出现一个小面板,并显示一些按钮。使用以下代码,一切正常工作: private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { rowSelected = e.RowIndex; columnSelected = e.ColumnIndex; if (e.R

我有一个包含datagridview的表单。每当用户单击一行时,该行下方就会出现一个小面板,并显示一些按钮。使用以下代码,一切正常工作:

private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
    {

      rowSelected = e.RowIndex;
      columnSelected = e.ColumnIndex;

      if (e.RowIndex == -1) return;

      var cellRectangle = dataGridView1.PointToScreen(
      dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location);
      panel_EditButtons.Location = new Point(cellRectangle.X + 50, cellRectangle.Y);

      panel_EditButtons.Show();

    }
有人能告诉我,当用户点击一行时,如果没有足够的空间来显示面板,如何防止面板出现在屏幕外?请看我附上的两张图片:


正常视图(当有足够的空间显示面板时,面板显示正确)

当我单击行的右侧时(没有足够的空间显示面板,面板显示在屏幕外)


有人能告诉我,即使我单击行的右侧,但没有足够的空间,因此面板位置仅限于屏幕宽度,我如何显示整个面板?

我知道的唯一方法是重置坐标

if (panel_EditButtons.Location.X + panel_EditButtons.Size.X > width)
    panel_EditButtons.Location = new Point(width - panel_EditButtons.Size.X, panel_EditButtons.Location.Y);
// same with Y
请记住,我的代码只是伪代码,简单地复制粘贴可能无法工作