How can I determine when scroll bars become visible for a form?

  • Thread starter Thread starter Serg
  • Start date Start date
S

Serg

I have an MDIParent window.
And I can`t catch the moment when scroll bars become visibe.
this.VScroll and this.HScroll

are always return false.

Thanks in adv

Serg.
 
Sounds bad, but could try holding the difference of form size and clientsize
in a varible and if that is smaller than 'last' value onresize window would
have scroll bars

Never tried it.
 
Serg,

There are VScroll and HScroll proeperties that get give you information
where the scorll bars are visible or not, but there is no notification when
these properties changes. There is no also notification when the MDI
children inside the MDI parent move.

I have two workarounds for you:
1. Hook on Application.Idle event and check VScroll and HScroll propoerties
and fire events when they change (or do whatever you want to do).
Cons: Using this solution you will get the event fired eventually, but not
right away.;
Pros: This solution doesn't use any window messages, refelection, PInvoke or
undocumneted stuff; Works for all .NET versions

2. When scollabars show/hide in a ScrollableControl (the one that support
autoscrolling) the SizeChanged event fires. This could be used to check for
changing scrollbars visiblity.
The bad news is that when a form is configure to be a MDI container it
creates one internal control that host all MDI children and shows all the
scrollbars, thus handling SizeChanged event on the level of the form won't
do.
Good news is that this control is added to the form's Controls collection as
any other control. You can enumerate the child control and hook to its
SizeChanged event. For example your form's contructor can look something
like this:

public Form1(int a)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
foreach(Control ctrl in this.Controls)
{
if(ctrl is MdiClient)
{
ctrl.SizeChanged += new EventHandler(MDIClinet_SizeChanged);
}
}
}

private void MDIClinet_SizeChanged(object sender, EventArgs e)
{
//Check VScroll and HScroll and fire event if they change
}

Pros: You get the event right away; This solution doesn't use any window
messages, refelection, Works for all current versions of .NET
Cons: The solution uses undocumented mdi client control. It may not work for
future versions if MS desides to change the implementation of this, but it
is unlikely to happen.


--
HTH
Stoitcho Goutsev (100)

Then in the MDIClinet_SizeChanged you can check VScroll and HScroll
properties and fire an event if they change or do whatever you want to do
 
Hi, Stoitcho

First way is not working because of VScroll and HScroll for MDI parent form
always return false. I think this is error in .NetFramework_1.1.
Second way is working well.

Thank you.
Serg.
 
Serg,

I never tried the first way. It may not work because the scroll bars are
carried by the internal MDIClinet control. I thought that they are taking
this into considereation.
 
Back
Top