PC Review


Reply
Thread Tools Rate Thread

Determine whether vertical scrollbar is visible

 
 
Alain Dekker
Guest
Posts: n/a
 
      22nd Dec 2011
Hi,

Got this code from Google, but it doesn't work:

//...
private const int WS_VSCROLL = 0x200000;
//...

//...
[DllImport("coredll.dll")]
public static extern int GetWindowLong(IntPtr hWnd, int Index);
//...

//...
private static bool IsScrollbarVisible(IntPtr hWnd)
{
// Determines whether the vertical scrollbar is visible for the specified
control
bool bVisible = false;
int nMessage = WS_VSCROLL;
int nStyle = GetWindowLong(hWnd, nMessage);
bVisible = ((nStyle & nMessage) != 0);
return bVisible;
}
//...

//...
bVisible = IsScrollbarVisible(lstAccounts.Handle);
//...

Problem is that bVisible is always false, regardless of whether the vertical
scrollbar is actually displayed or not. nStyle is always 0 above.

This was programmed in VS2005 using the CF .NET v2.0 for Windows CE.

Thanks,
Alain


 
Reply With Quote
 
 
 
 
Alain Dekker
Guest
Posts: n/a
 
      23rd Dec 2011
Thanks, I've tried a variant of that (used by the previous developer on
other forms so I guiess there's precedent) of starting a "LoadTimer" at the
end of the FormLoad event. This then does the rest of the GUI work
(including checks for the vertical scrollbar) and (I'm guessing) is
effectively the same as the FormShown event.

Works fine now.

Note that in VS 2005 and C# using .NET 2.0 (specifically the CF version),
there is no shown event for a System.Windows.Form control. Is this a new
form event? The list of events is:
Activated
Click, Closed, Closing, Deactivate, DoubleClick, EnabledChanged, GotFocus,
HelpRequested, KeyDown/Press/Up, Load, LostFocus, MouseDown/Move/Up, Paint,
ParentChanged, Resize, TextChanged, Validated, Validating

The idea of using a timer to complete loading seems reasonable to me.

Thanks again for the help and Merry Christmas.
Alain

"Peter Duniho" <(E-Mail Removed)> wrote in message
news:CI6dnSlsOo0t-(E-Mail Removed)...
> On 12/22/11 8:06 AM, Alain Dekker wrote:
>> Hi, found one problem. It should be:
>> int nStyle = GetWindowLong(hWnd, GWL_STYLE); // private const int
>> GWL_STYLE = -16;
>>
>> and not:
>> int nStyle = GetWindowLong(hWnd, WS_VSCROLL);
>>
>> but I still have a problem. The very first time the form is loaded, the
>> scrollbar returns "false" (not visible). You check it again once it is
>> fully
>> loaded and it returns "true" (yes I am visible). Why is it false to start
>> with, but then corrects itself after the Form Load event has completed?

>
> Try handling the Shown event rather than Load.
>
> I don't know 100% that will work for sure (I try not to write code that
> relies on whether the scroll bar is visible or not), but it's worth
> trying.
>
> Pete



 
Reply With Quote
 
ajaytemp@gmail.com
Guest
Posts: n/a
 
      3rd Jan 2012
thanks.

i have been wondering why my ancient suggestion doesn't get into the browser. i submitted long ago with minimal response and no reply.

any how, windows is just that a window ontop of GNU (unix) microkernels.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:48 AM.