2017-11-17 8 views
0

私はdatagridviewヘッダーセルのすぐ下のフォームを開こうとします。私はこれを持っている(と、それが動作していない)DataGridviewcellの下のフォームを開く

private void button1_Click(object sender, EventArgs e) 
{ 
    Form aForm = new Form(); 

    aForm.Text = @"Test"; 
    aForm.Top = this.Top + dataGridView1.Top - dataGridView1.GetCellDisplayRectangle(0, 0, false).Height; 
    aForm.Left = this.Left + dataGridView1.GetCellDisplayRectangle(0, 0, false).Left; 
    aForm.Width = 25; 
    aForm.Height = 100; 
    aForm.ShowDialog(); 
} 

私は右上を取得する方法を参照してDataGridViewのセルをもとに残されていません。

答えて

2

はあなたが画面座標を使用して、その場所を計算する必要があり、フォームを使用することを検討する必要があります。あなたはフォームを使用してトラブルにyouselfを見つけた場合

Form _form = new Form(); 
_form.StartPosition = FormStartPosition.Manual; 
_form.FormBorderStyle = FormBorderStyle.FixedSingle; 
_form.Size = new Size(dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].Width, 100); 

Point c = dataGridView1.PointToScreen(dataGridView1.GetCellDisplayRectangle(
             dataGridView1.CurrentCell.ColumnIndex, 
             dataGridView1.CurrentCell.RowIndex, false).Location); 
_form.Location = new Point(c.X, c.Y); 
_form.BringToFront(); 
_form.Show(this); 

、あなたの代わりにパネルを使用して検討するかもしれない:

Point c = dataGridView1.PointToScreen(dataGridView1.GetCellDisplayRectangle(
         dataGridView1.CurrentCell.ColumnIndex, 
         dataGridView1.CurrentCell.RowIndex, false).Location); 
Point r = this.PointToClient(c); 
panel1.Location = new Point(r.X, r.Y); 
panel1.BringToFront(); 

もこの作品thisthis

+0

おかげで、見てみましょう。 – Hansvb

関連する問題