Solved

Text longer than textbox

Posted on 2003-10-29
9
146 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 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

717 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