我发布了我在项目中实现的一个示例代码...在按钮单击事件中,我正在移动一些文本框,datagridview 在每个按钮单击时向下移动...与您使搜索文本框和标签位置动态的方式相同.. . 例如..假设您的第一列(日期)从位置 10,20 开始,然后在选择描述列时将标签的位置设置为 (10,20) ..以同样的方式进行其他选项...
看下面的代码可能会给出一些想法......
public void btn_add_Click(object sender, System.EventArgs e)
{
if (sender == btn_mc_add)
{
dgv_mc.Rows.Add();
int count = dgv_mc.Rows[0].Height;
int count1 = dgv_mc.Rows.Count;
k = k + count;
GBOX_MC.Height = count * count1 + 44;
dgv_mc.Height = count * count1 + 44;
GBOX_MW.Location = new Point(5, 141 + k - 44);
lbl_mw.Location = new Point(6, 90 + k - 22);
btn_mw_add.Location = new Point(700, (90 + k - 22));
btn_mw_delete.Location = new Point(770, (90 + k - 22));
GBOX_SCROLL_NOW.Location = new Point(5, 210 + k + l + 22);
lbl_scroll_now.Location = new Point(6, 185 + k + l + 22);
btn_scroll_now_add.Location = new Point(700, 185 + k + l + 22);
btn_scroll_now_delete.Location = new Point(770, 185 + k + l + 22);
}
else if (sender == btn_mw_add)
{
dgv_mw.Rows.Add();
int count = dgv_mw.Rows[0].Height;
int count1 = dgv_mw.Rows.Count;
l = l + count;
GBOX_MW.Height = count * count1 + 44;
dgv_mw.Height = count * count1 + 44;
GBOX_SCROLL_NOW.Location = new Point(5, 210 + l + k);
lbl_scroll_now.Location = new Point(6, 185 + l + k);
btn_scroll_now_add.Location = new Point(700, 185 + l + k);
btn_scroll_now_delete.Location = new Point(770, 185 + l + k);
}
}