Bug with controls location and scrollbars in a Windows Form

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
 
P

Peter Duniho

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top