Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Are ScrollBars Visible?

Status
Not open for further replies.

earthandfire

Programmer
Mar 14, 2005
2,924
GB
Whilst working on the TGML exercise, I came up against the problem of being able to identify when ScrollBars are visible. I think this has been asked here before, and I'm not sure that there has been answer.

I've tested this with RichTextBox, ListBox and TreeeView and it seems to work:

Code:
[Blue]Public[/Blue] [Blue]Class[/Blue] HorizontalScroll

  [Blue]Public[/Blue] Shared [Blue]Function[/Blue] IsVisible([Blue]ByVal[/Blue] c [Blue]As[/Blue] Control) [Blue]As[/Blue] [Blue]Boolean[/Blue]

    [Blue]Dim[/Blue] BorderWidth [Blue]As[/Blue] [Blue]Integer[/Blue] = Math.Abs(Convert.ToInt32(Microsoft.Win32.Registry.CurrentUser.OpenSubKey([Red]"Control Panel"[/Red]).OpenSubKey([Red]"Desktop"[/Red]).OpenSubKey([Red]"WindowMetrics"[/Red]).GetValue([Red]"BorderWidth"[/Red])))
    [Blue]Return[/Blue] (c.ClientRectangle.Height + BorderWidth) < c.Height

  [Blue]End[/Blue] [Blue]Function[/Blue]

[Blue]End[/Blue] [Blue]Class[/Blue]


[Blue]Public[/Blue] [Blue]Class[/Blue] VerticalScroll

  [Blue]Public[/Blue] Shared [Blue]Function[/Blue] IsVisible([Blue]ByVal[/Blue] c [Blue]As[/Blue] Control) [Blue]As[/Blue] [Blue]Boolean[/Blue]

    [Blue]Dim[/Blue] BorderWidth [Blue]As[/Blue] [Blue]Integer[/Blue] = Math.Abs(Convert.ToInt32(Microsoft.Win32.Registry.CurrentUser.OpenSubKey([Red]"Control Panel"[/Red]).OpenSubKey([Red]"Desktop"[/Red]).OpenSubKey([Red]"WindowMetrics"[/Red]).GetValue([Red]"BorderWidth"[/Red])))
    [Blue]Return[/Blue] (c.ClientRectangle.Width + BorderWidth) < c.Width

  [Blue]End[/Blue] [Blue]Function[/Blue]

[Blue]End[/Blue] [Blue]Class[/Blue]

Call using:

Code:
    MessageBox.Show(HorizontalScroll.IsVisible(TreeView1).ToString)
    MessageBox.Show(VerticalScroll.IsVisible(TreeView1).ToString)

Hope this is of some use.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top