Question

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 !

enter image description here

thanks for help.

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top