Togliere lo scrollbar da un textbox quando non server

by enrico 10. April 2009 13:42

Non so se anche a voi è capitato ma mi sembra utile postarlo. Se hai un TextBox con una scrollbar e vuoi nascondere la scrollbar quando questa è inutile, come si può fare?

Ecco il codice (txtTesto è il nostro TextBox):

   1: Private Sub txtTesto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTesto.TextChanged
   2:     Static busy As Boolean
   3:     If busy Then Exit Sub
   4:     busy = True
   5:  
   6:     With sender
   7:         Dim tS = TextRenderer.MeasureText(.Text, .Font)
   8:         Dim Hsb = .ClientSize.Height < tS.Height + .Font.Size
   9:         Dim Vsb = .ClientSize.Width < tS.Width
  10:  
  11:         If Hsb And Vsb Then
  12:             .ScrollBars = ScrollBars.Both
  13:         ElseIf Not Hsb And Not Vsb Then
  14:             .ScrollBars = ScrollBars.None
  15:         ElseIf Hsb And Not Vsb Then
  16:             .ScrollBars = ScrollBars.Vertical
  17:         Else
  18:             .ScrollBars = ScrollBars.Horizontal
  19:         End If
  20:     End With
  21:     busy = False
  22: End Sub

Ciao!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Tricks & Tips | Work around | windowsform

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by Esia Software 1.4.0.0

Informazioni sull'autore

Sono un cittadini di Trieste, ho 33 anni e faccio lo sviluppatore nella mia azienda che si chiama Esia Software.

Commenti recenti

Comment RSS

Post recenti

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Info legali

Le opinioni espresse in questo blog sono strettamente personali e ogni persona è responsabile dei commenti che inserisce.

RecentComments

Comment RSS