Click here to Skip to main content
15,887,998 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ??
Posted
Updated 28-May-15 3:12am
v2
Comments
Sergey Alexandrovich Kryukov 28-May-15 11:02am    
Why? Good layout design does not require this information. Roughly speaking: always dock everything.
—SA

1 solution

Simple: handle the Resize event.
C#
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");
        }
    }
Add to a form, and set as Dock:Fill in the designer.
Run the app, and you get:
C#
Constructor : (150, 150)
Resize : (357, 188)
Load : (357, 188)
Resize : (531, 381)
Where the Form original size was: (373, 226) and the form was resized in the Form Load event to (547, 419)
 
Share this answer
 
v2
Comments
OriginalGriff 28-May-15 14:43pm    
I hate Markdown...it keeps mucking up my code blocks...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900