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

why does textbox scroll up?

Status
Not open for further replies.

hinchdog

Programmer
Feb 14, 2001
380
US
I'm trying to make a textbox resize downward when a person hits return, starting a new line. I got the return to work and I got the box to resize downward, EXCEPT the very first line, which always scrolls up out of site. Has anyone encountered similar problems? thanks

-Hinchdog
 
Here is how I got it to work:


Private Sub Text1_Change()

Dim lngCount As Long
Dim lngPosition As Long

lngPosition = 0

Do
lngPosition = InStr(lngPosition + 1, Text1.Text, vbCr)

lngCount = lngCount + 1
Loop Until lngPosition = 0

Text1.Height = (195 * lngCount) + 90
End Sub

Hope that helps.
 
That did work, thanks alot. Here's the code I use to change the width of a text box (and a flexgrid that the textbox popluates). Quid pro quo!

Private Sub ChangeWidth(ByRef grid As MSFlexGrid, ByRef text As TextBox)
Dim w As Single
w = Me.TextWidth(grid.text) ' grab the text width
If w < 500 Then
w = 500
End If ' set a default so the = column doesn't disappear
grid.ColWidth(grid.Col) = w * 1.1 ' expand or contract the cell
text.Width = w * 1.1
End Sub


-thanks again
 
oops, i probably should have shown the sub that changes the flexgrid width too since they depend on eachother. here goes..


Public Sub AdjustFlexGridRowHeight(ByRef grid As MSFlexGrid, Optional ByRef rownum As Integer = -1)
'if rownum = -1 (or not specified), resizes all rows. Else, resizes the specified row
Dim i As Integer
Dim j As Integer
Dim LinesOfText As Integer
Dim OldLineNum As Integer
Const EM_GETLINECOUNT = &HBA
With frmMain
If (grid.Tag = &quot;&quot;) Then 'I use the grid's tag property to store textheight. This way, this routine can support multiple grids.
Set .Font = grid.Font
Set .txtDummy.Font = grid.Font
grid.Tag = .TextHeight(&quot;GENERIC TEXT&quot;)
End If

'My fgrids only have one column (col 0)
'grid.ColWidth(0) = grid.Width - 250 '250 helps keep text from being too close to the edge
'.txtDummy.Width = grid.ColWidth(0)

For i = 1 To (grid.Rows - 1)
Dim iWidth As Integer
If ((rownum = -1) Or (i = rownum)) Then
OldLineNum = 0
LinesOfText = 1
For j = 1 To (grid.Cols - 1)
.txtDummy.text = grid.TextMatrix(i, j)
LinesOfText = SendMessage(.txtDummy.hwnd, EM_GETLINECOUNT, 0&, 0&)
If LinesOfText < OldLineNum Then
LinesOfText = OldLineNum
End If
grid.RowHeight(i) = Val(grid.Tag) * LinesOfText
OldLineNum = LinesOfText
Next j
End If
Next i
txtEdit.Height = Grid1.CellHeight
Call ChangeWidth(Grid1, txtEdit)

End With

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top