473,425 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

Detecting the number of lines in a label.

4
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 5445
CamB
4
Oh, sorry, I should have mentioned that I'm using Visual Basic 2010.
Feb 28 '12 #2
Guido Geurs
767 Expert 512MB
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
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 Expert 512MB
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
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
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
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
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
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
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
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
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
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
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:...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.