简体   繁体   中英

How to change size of panel control on resize of parent form

I am using this code to change size of a panel control for maximize and normal state , and it's working fine, but I am not getting how to re-size panel according to my background image when the user will re-size the form other than minimize,maximize and normal state, ie using the mouse. how do I do this using some calculation code or any other way?

private void ParentHome_ClientSizeChanged(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Maximized)
    {
        this.Panel1.Size = new System.Drawing.Size(227, 324);
        this.Panel1.Location = new System.Drawing.Point(69, 223);
    }
    else if (this.WindowState == FormWindowState.Normal)
    {
        this.Panel1.Size = new System.Drawing.Size(198, 289);
        this.Panel1.Location = new System.Drawing.Point(60, 193);
    }
}

在此处输入图片说明

You don't need to handle any event. Just use the Anchor property:

Panel1.Anchor = AnchorStyles.Left | AnchorStyles.Top | 
                AnchorStyles.Right | AnchorStyles.Bottom;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM