473,670 Members | 2,407 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 programmaticall y 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 5499
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, 259 views)
Feb 29 '12 #5

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

Similar topics

7
9598
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 I have the function shown below which doesn't work. If Reset is True then all I get is 1 in every field and if Reset is False, the numbering does not start at 1 each time the query is run. Can someone show me a function that works. Function...
18
1978
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 could change. So rather than explicitly define the number expected, the file is read and the number defined that way. So I have a csv file that I can read in, how can I work out the number of lines in the file? Is there a function that can do this,...
5
2730
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 puck moving around. I want the puck is bounce when it hits a border (specified by the hitlines). Retreieved some info on hit testing lines from Bob Powell's GDI+ FAQ (very useful!) but i'm fairly new at the idea of hit testing and am
4
2552
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 lblP1JoyRight.BackColor = clrLabelMove
54
3241
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 this NG to the effect that "...when you access a module programatically, there is a lines collection..." Have any of you experimented with your own procedures to aid in numbering lines? Would the lines collection be of some
19
4160
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. Users have sometimes ordered records the way we used to number lines in a BASIC program (10,20,30, etc.). I'd like to do an update query and fix this so that every record is in sequential order. I found an example in this newsgroup of how to...
1
1684
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 number of label formats (eg Avery label formats) and then be able to mailmerge and print the labels. I'm willing to pay for a development licence for a product - but I need it to be free from runtime royalties. Anybody know of such a product?
19
107946
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 sure that the user only submits a number to your .NET web application and also demonstrate how to add JavaScript to your ASPX pages. Upon popular demand, I have added a section that also covers how to use a validator control to check if a text box...
2
1567
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 course. regards Hardy
2
4092
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: 10212009 12 34 56 25 67 90 End Set ******** Set: 2 Date: 10222009
0
8901
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8591
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5683
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4208
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1791
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.