Solved

Text longer than textbox

Posted on 2003-10-29
9
139 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
9 Comments
 
LVL 9

Assisted Solution

by:Dang123
Dang123 earned 150 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 350 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Vb.net 2008 2 49
Problem to skip loop 6 49
How to measure sizes and angles in scanned images ? 3 28
Visual Studio 2005 text editor 10 20
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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now