2017-11-17 1 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(); 
} 

I 오른쪽 상단을 취득하고있는 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(); 

this보고 this

+0

감사를 타고,이 작동합니다. – Hansvb