473,513 Members | 2,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detecting the number of lines in a label.

4 New Member
Is there a method of programmatically detecting the number of lines of text contained in a label?

I want to know how many lines of text have been triggered in a label control. I need to use a label control because of its transparent capabilities.

There must be some way of accessing the number of new line events that have been triggered, but I haven't been able to figure it out, nor have I read anything that helps.

Any suggestions?
Feb 28 '12 #1
4 5462
CamB
4 New Member
Oh, sorry, I should have mentioned that I'm using Visual Basic 2010.
Feb 28 '12 #2
Guido Geurs
767 Recognized Expert Contributor
This works in VB6:
Split the Caption of the label on "VbNewLine" to an array.
The Ubound + 1 = number of lines in the Caption.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim ARRlines() As String
  3.    'fill label
  4.    Label1.Caption = "ffff" & vbNewLine & _
  5.                   "gggg" & vbNewLine & _
  6.                   "hhhh" & vbNewLine & _
  7.                   "mmmmmmm"
  8.    'Split text
  9.    ARRlines = Split(Label1.Caption, vbNewLine)
  10.    MsgBox "Lines in Label1= " & UBound(ARRlines) + 1
  11.    ' clean array
  12.    ReDim ARRlines(0) 
  13. End Sub
Feb 28 '12 #3
CamB
4 New Member
Thanks for the help, but it doesn't address my difficulty. Your code forces line breaks; I know how to do that, but it's not the issue.

I want to detect the automated line breaks created in a label by Visual Basic when it is set to Autosize False. I was parsing the text myself and creating line breaks where spaces occured near the desired label width. I'm hoping that rather than all of that fuss, that I can instead utilize the events that - evidently - must be locked somewhere in the Visual Basic code.

However, thanks for caring enough to reply.
Feb 29 '12 #4
Guido Geurs
767 Recognized Expert Contributor
You can use the EM_GETLINECOUNT.
Make a copy of the label.caption in a hidden textbox with the same properties for width and font of the label. (see attached demo)
Use EM_GETLINECOUNT on the textbox with:

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function SendMessageAsLong Lib "user32" _
  2.      Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
  3.      ByVal wParam As Long, ByVal lParam As Long) As Long
  4. Const EM_GETLINECOUNT = 186
and :

Expand|Select|Wrap|Line Numbers
  1.       MsgBox "Lines in label = " & SendMessageAsLong(Text1.hWnd, EM_GETLINECOUNT, 0, 0)
Attached Files
File Type: zip Detecting the number of lines in a label_v1.zip (2.5 KB, 256 views)
Feb 29 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
9590
by: Melissa | last post by:
I'm trying to create a function that I can put in a query field that will consecutively number the records returned by the query starting at 1 and will start at 1 each time the query is run. So far...
18
1936
by: Vasilis Serghi | last post by:
Presently I define the number of lines to be expected in a file when defining the array size and the initialisation of this array. This works fine for now, but i'm sure that in the future this...
5
2718
by: Brian | last post by:
Hello all.. Am working on an Air Hockey game... have an table loaded into a picture box. The borders of the table are slightly slanted. Am using hit testing lines with GDI+ to manipulate the...
4
2542
by: jcrouse | last post by:
I am using the following code to move a label on a form at runtime: If myMousedown = lblP1JoyRight.Name Then If lblP1JoyRight.BackColor.Equals(Color.Transparent) Then bTransCk = True ...
54
3200
by: MLH | last post by:
I use A97 and do not always insert line numbers while writing procedures. I find it necessary to go back and add them later to aid in debugging. Nearly 3 years ago, something was mentioned in...
19
4142
by: eric.nave | last post by:
this is a slight change to a fequently asked question around here. I have a table which contains a "sortorder" column where a user can specify some arbitrary order for records to be displayed in. ...
1
1666
by: Simon Verona | last post by:
I have the requirement for address label printing within my software. I have a name and address list in a ado.net in-memory dataset - I'd like a pre-built software library which will display a...
19
107862
Frinavale
by: Frinavale | last post by:
Filtering user input is extremely important for web programming. If input is left unfiltered users can input malicious code that can cripple your website. This article will explain how to make...
2
1564
by: HardySpicer | last post by:
Some pcs have only the c drive whilst others like mine have c,d,e,f and z! How do I detect this automatically if I want to search all drives in a pc? I also want to ignore the DVD and floppy of...
2
4084
by: rka77 | last post by:
Hi, I am trying to make a Python2.6 script on a Win32 that will read all the text files stored in a directory and print only the lines containing actual data. A sample file - Set : 1 Date:...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.