如何在(锚定或停靠)之后获得控制高度? [英] How to get height of control after (anchored or docked )?

查看:127
本文介绍了如何在(锚定或停靠)之后获得控制高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为项目创建自定义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 ??

推荐答案

简单:处理Resize事件。

Simple: handle the Resize event.
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)


这篇关于如何在(锚定或停靠)之后获得控制高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆