|
-
Jun 11th, 2003, 09:22 AM
#6
Thread Starter
Fanatic Member
Originally posted by Spajeoly
Isn't there a property for the text box to have all the text centered?
Horizontally? Yes
Vertically? No
I wrote some code this morning to center the text box itself instead of the text. I've been testing it for a bit and so far I really like the results. The textbox is borderless, so it looks to the end user like the text just centers when they move off the text box.
VB Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const EM_GETLINECOUNT = &HBA
Private Const TEXT_HEIGHT = 210
Private Sub UserControl_Resize()
ResizeControls
End Sub
Private Sub txtDescription_GotFocus()
'hightlight text
txtDescription.SelStart = 0
txtDescription.SelLength = Len(txtDescription.Text)
'make description full size while it has focus
ResizeDescription
End Sub
Private Sub txtDescription_LostFocus()
'make sure beginning text is visible
txtDescription.SelStart = 0
txtDescription.SelLength = 0
ResizeControls
End Sub
Private Sub ResizeDescription()
txtDescription.Top = UserControl.ScaleTop
txtDescription.Width = UserControl.ScaleWidth - 60
txtDescription.Left = 30
txtDescription.Height = txtUtensil.Top - txtDescription.Top
End Sub
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=UserControl,UserControl,-1,Refresh
Public Sub Refresh()
UserControl.Refresh
ResizeControls
End Sub
Private Sub ResizeControls()
txtUtensil.Left = 50
txtUtensil.Top = UserControl.ScaleTop + UserControl.ScaleHeight - txtUtensil.Height - 5
txtUtensil.Height = UserControl.TextHeight(txtUtensil.Text) - 50
txtUtensil.Width = UserControl.ScaleWidth - 100
txtDescription.Width = UserControl.ScaleWidth - 60
txtDescription.Left = 30
txtDescription.Height = GetLines(txtDescription) * TEXT_HEIGHT
txtDescription.Top = (txtUtensil.Top - txtDescription.Height) / 2
End Sub
Private Function GetLines(txt As TextBox) As Long
GetLines = SendMessage(txt.hwnd, EM_GETLINECOUNT, 0&, ByVal 0&)
End Function
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|