简体   繁体   中英

TextBox shown in the wrong place after a scroll down

i have a from c# and i want to show text Box after a click in a check box. but when i scroll down, and check , the text Box is shown in the wrong place !!! the text Boxes must be in the same level with check Boxes.

private void checkBox1_Checkedchanged(object sender, EventArgs e)
{
    textBox1.Visible = true;
}

and changing the Location of the text Box don't give good results !

在此处输入图片说明

thanks for help.

You are running into an awkward quirk of the Panel control, it only scrolls controls that are visible. When you make it visible in your code, it will have the wrong Location property if you've used the scrollbar. You will need to make the correction yourself. Make it look like this:

private void checkBox1_Checkedchanged(object sender, EventArgs e)
{
    if (!textBox1.Visible) {
        textBox1.Location = new Point(textBox1.Left + panel1.AutoScrollPosition.X,
                                      textBox1.Top  + panel1.AutoScrollPosition.Y);
        textBox1.Visible = true;
    }
}

A better alternative is to use the Enabled property instead, also much less disorienting for the user. Set it to False in the designer and then:

private void checkBox1_Checkedchanged(object sender, EventArgs e)
{
    textBox1.Enabled = true;
}

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