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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autosizing textboxes results cover controls

Status
Not open for further replies.

FemPro

Programmer
Feb 15, 2008
28
GR
Hello everybody,
i am very new to vb.net 2005 professional edition.
I have several controls design on a form, such us labels, textboxes and buttons. When I autosize two of the textboxes during runtime, to fit its contents, the one textbox covers the other and generally us a result they cover other controls, or other controls covered by them. So my form looks very bad. What can i do to avoid this? Any help will be much appreciated.

Thank you
in advanced
 
In general don't rely on Autosize as it doesn't take into account other controls on the form.

The simplest action is to remove the autosize option on the fields and instead set the ToolTip to the value of the text.

This way some of the text will be visible in the text box (and all of it will be able to be edited) and if you hover your mouse over the text box you will see the full text.

Otherwise you'll have to take care of the resizing yourself. What exactly this involves depends on the layout of your form.



Bob Boffin
 
Thank you very much Bob Boffin.
I don't thing its a good idea to remove the autosize from these two textboxes. The what i want to do is to have all the text visible to the first textbox because i want the user can see it without editing it and typing this text to the other textbox and the what the other controls do is to see how fast user can type the text, meter the user's accurasy, and graduate the user's about these. Well, i dont want user looses time to edit the first box to see all text to type it in the other textbox. Any other idea please?

Thank you
much again.
 
Is there a limit to the amount of text that can be entered into the first textbox? If so, you can set the textbox to be multiline and make it large enough to see all of the text up to the max text length. Most typing tests are like this.

Do a google search for typing speed tests, and you can see how they set up theirs.
 
Thank you too Qampgine.
The limit to the amount of text is a half page of a4 paper into the first textbox. Its large as you can see, because i want to provide more practise to the user and teach him to type more accurately and fastely as he can i want to provide the user his best progress.
Well something i missed to mention is that the text appears every time the user navigate through exercises, will be in table of a data base so i will display the properly text to the first textbox from the database. Every new exercise is a new text in the textbox. And the textbox must be adapt to fit its contents and that's i autosize it.
I want your opinion. Do you think that the bigger size of text i mentioned before (half a page a4) into the first textbox is very big? Do you think i have to split it in small texts, so is it better have more smaller exersices than one big? Would it be less tiring to the user?

Thanks all of you
in advanced.
 
Have you considered using a RichTextBox instead of a normal TextBox? This is much more like typing into a word processor and can be extended to allow underline, bold, colors, fonts etc. and even spell checking.

Set the size of the control to be fixed and big enough to show half a page of A4. Just allow the control to take care of word wrapping etc. It will add a vertical scroll bar if necessary.


Bob Boffin
 
Thanks all of you.
bboffin i didn't found nice idea to use a rich textbox.
I finally managed to do the what i want. Here is the code i did it.

Public Class Form1
Dim g As Graphics = CreateGraphics()
Dim DistanceBetweenTxtBxs As Integer
Dim dstncBetweenTb2DsgnTime_Tb2Autosized As Integer
Dim tb2Btm As Integer

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

DistanceBetweenTxtBxs = Tb2.Top - Tb1.Bottom
tb1.text="the big text half a page a4"
Dim g As Graphics = CreateGraphics()
Dim sz As SizeF = g.MeasureString(Tb1.Text, Tb1.Font, Tb1.ClientSize.Width)

Tb1.MaxLength = Tb1.Text.Length
Tb1.Height = CType(sz.Height, Integer)
Tb1.Width = CType(sz.Width, Integer)
g = Nothing
sz = Nothing
Tb2.Width = Tb1.Width
Tb2.Font = Tb1.Font
Tb2.MaxLength = Tb1.MaxLength
tb2Btm = Tb2.Location.Y + Tb2.Height
End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles Me.Paint

Dim lines, cols As Integer
e.Graphics.MeasureString(Tb1.Text, Tb1.Font, _
New SizeF(Tb1.Width, 1000), New StringFormat, cols, lines)
Tb1.Height = Tb1.Font.Height * (lines + 1)

Tb2.Height = Tb1.Height
Tb2.Top = Tb1.Location.Y + Tb1.Size.Height + DistanceBetweenTxtBxs
dstncBetweenTb2DsgnTime_Tb2Autosized = Tb2.Bottom - tb2Btm
For Each c As Control In Me.Controls
If (c.Name <> "Tb2" And c.Name <> "Tb1") Then
If c.Name <> "ChapterNameLbl" And c.Name <> "ExerciseNameLbl" Then
If (c.Top < Tb2.Bottom And c.Location.X < Tb2.Width) Then
c.Top = c.Top + dstncBetweenTb2DsgnTime_Tb2Autosized
End If
End If
Else
Exit For
End If
Next
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top