Bug with controls location and scrollbars in a Windows Form

  • Thread starter Thread starter Tophe
  • Start date Start date
T

Tophe

Hi,

I've noticed a bug with WinForm and scrollbars, and I would like to
know if there is a workaround ...

Bug description :
------------------------
1) create a win form, and add 3 buttons :
* FirstButton : upper left corner of the winform
* SecondButton : location = (0 ; 600)
* ThirdButton : location = (100, 600)

2) Set : ThirdButton.Visible = false

3) Set the Form size to 100 x 100 ... and set : AutoScroll = true

4) Add the following event handler to the Click event of FirstButton
and SecondButton ...

private void OnButton_Click(object sender, EventArgs e)
{
this.ThirdButton.Visible = true;
}

Now is the trick :
- if you click on FirstButton ... the ThirdButton will be displayed to
its right location

- if you scroll to SecondButton and click on it, ThirdButton is
displayed to a wrong location (offset added)


Does anybody know how to solve this issue?
Thanks in advance
 
Tophe said:
[...]
Now is the trick :
- if you click on FirstButton ... the ThirdButton will be displayed to
its right location

- if you scroll to SecondButton and click on it, ThirdButton is
displayed to a wrong location (offset added)


Does anybody know how to solve this issue?

Sure. You have to take the AutoScrollPosition into account when setting
the button's location. It's "by design".

Alternatively, put all three button instances in a Panel instance that
is itself a child of the Form. Then the Panel is what scrolls and the
Button instances are all relative to the Panel, unscrolled.

Pete
 
Back
Top