?
Solved

Text longer than textbox

Posted on 2003-10-29
9
Medium Priority
?
147 Views
Last Modified: 2010-05-03
How do I figure out if the text inside a textbox is longer than the textbox (all the text cannot be displayed)?
0
Comment
Question by:PLavelle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 9

Assisted Solution

by:Dang123
Dang123 earned 600 total points
ID: 9643161
This should get you off to a good start

http://www.vb-helper.com/howto_size_textbox.html
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 1400 total points
ID: 9643168
Hi PLavelle,

You can use the following method to achieve this.

Private Sub TestLength(ByRef TBox As TextBox)
    With TBox
        If Me.TextWidth(TBox.Text) > TBox.Width - 100 Then
            MsgBox "Uh oh"
        End If
    End With
End Sub

Shows how

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9643946
hearing...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9643970
You could know in advance how many lines would be displayed in advance, doesn't it?
Then, just knowing how many lines has after the text box is populated and comparing with that data, you should know if text is completelt displayed or not.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9643989
Const WM_USER = 1024
Const EM_GETLINECOUNT = WM_USER + 10
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long


TotalLines = SendMessage(Text1.hWnd, EM_GETLINECOUNT, 0, 0&)
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9644001
Richie_Simonetti,
 Different fonts take differing amount of room for the same letters. The link I posted above uses TextWidth and TextHeight to take this into account.

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9644059
You are right but you know that when design the app and set the properties, isn't it?
Simply doing a test, you would know how many lines textbox would displays.
If font size is 24, maybe you will see only one line, if font size is 12 you would see 2 lines and so on, so it is easy to test it.
TextWidth and TextHeight would be usefull when you know nothing about YOUR textbox target but this is not the case.
0
 

Author Comment

by:PLavelle
ID: 9644481
Thank you.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9644533
wow! Besides VB, i have to learn to read minds!!!
:)))))))
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question