问题描述
我正在为项目创建自定义datagridview控件。我必须计算要添加的行数以避免垂直滚动条。当用户控件未锚定或停靠时它可以工作但是当(锚定或停靠)然后它失败时。
当我检查计算时,控制大小给出控制前的控件大小或锚点发生。
如何在停靠或锚定后获得实际的运行时控制大小?
I am creating custom datagridview control for a project . i have to calculate number of rows to be added to avoid vertical scrollbar . it works when user control is not anchored or docked But when (anchored or docked ) then it fails .
when i check calculation , control size gives size of control before dock or anchor takes place .
how to get actual run-time size of control after docking or anchoring takes place ??
推荐答案
public partial class MyUserControl : UserControl
{
public MyUserControl()
{
InitializeComponent();
ShowSize("Constructor");
}
private void ShowSize(string from)
{
Debug.WriteLine("{0} : ({1}, {2})", from, Width, Height);
}
private void MyUserControl_Load(object sender, EventArgs e)
{
ShowSize("Load");
}
private void MyUserControl_Resize(object sender, EventArgs e)
{
ShowSize("Resize");
}
}
添加到表单,并设置为Dock:填写设计器。
运行应用程序,然后你get:
Add to a form, and set as Dock:Fill in the designer.
Run the app, and you get:
Constructor : (150, 150)
Resize : (357, 188)
Load : (357, 188)
Resize : (531, 381)
表单原始大小为:(373,226)并且表单在Form Load事件中调整大小(547,419)
Where the Form original size was: (373, 226) and the form was resized in the Form Load event to (547, 419)
这篇关于如何在(锚定或停靠)之后获得控制高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!