473,605 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to auto fit a label width to its text?

1 New Member
I have a dynamic label on my form that has changeable text and want to know how to auto fit a label width to its text every time the text is changed? The lable benlongs to a text box and I want to dynamically change the width of it to its text that is changable text. The main thing is to change also the text box width according to the label width.

Thanks
Mar 12 '11 #1
1 11815
jimatqsi
1,275 Recognized Expert Top Contributor
In the OnCurrent event (or whatever event is appropriate to your situation. I don't know what makes the content of the label change) you could put something like this. The code looks at the number of characters in the caption of the label and then sets the width of the label and text box based on an assumption about the TWIPS for your font and resolution. 1440 generally works for me. Google VBA and TWIPS for more info.

Expand|Select|Wrap|Line Numbers
  1. Dim intChars as integer
  2. dim intTwips as integer
  3.  
  4. intChars = len(me!mylabel.caption) ' how many chars in the label
  5. intTwips = 1440  ' might depend on what font you are using
  6. me!mylabel.width = intchars * intTwips
  7. me!mytextbox.width = me!mylable.width ' not sure if  you want equivalence here or what
  8.  
Jim
Mar 15 '11 #2

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

Similar topics

5
11557
by: Johnny Meredith | last post by:
I have seven huge fixed width text file that I need to import to Access. They contain headers, subtotals, etc. that are not needed. There is also some corrupt data that we know about and can correct once the data is in Access (or during the import process itself). Furthermore, the text files are poorly set up, such that some records may be "shifted" over a few characters, and therefore the fixed width nature of the file is corrupted. ...
8
3235
by: KathyB | last post by:
Please tell me where I'm going wrong on the marked lines***. The code is fine to that point. I've only used this code to populate dropdownlists using databind to the control. Here, I just need to get the one field associated with a variable or a label control. THANKS! kathy Dim Conn3 As New OleDbConnection()
0
1279
by: Masa Ito | last post by:
I have large fixed width text files that I need to parse. I regex'd a file that defines the columns - so I now have a large arraylist of column headers and column widths. I can read a line of the large text file, then loop through the arraylist of column headers, doing some math to grab the substrings - but this is going to be a sluggish way to do it. I am hoping others some tricks for doing something like this? Thanks!
1
3761
by: ghadley_00 | last post by:
Hi, I have a MS access database table for which I regularly need to import fixed width text data. At present I have to to cut and paste the text data from its source to a text file, save the file, import the text file as fixed width text , and then run an update query to copy the appropriate info into fields of a different table. Is it possible to write a macro to do all these steps? Also, is it
2
2429
by: sephali | last post by:
Hello sir, I want to hide the label and text box control which is of null value. The name of the FORM is "Index Entries". The Field name of that text box is the "Legislature". For this I have taken the form in current event procedure and put the following visual basic code : Private Sub Form _ Current() Me. visible=Not IsNull(Me.) End Sub After running this code I have got the error 2165. PLEASE HELP !
8
12873
by: elastreto | last post by:
Hello, I have been trying, so far in vain, to hide the label and text control in a form when the text control is empty/null. I have looked at past postings and tried the code below, however I am getting Run-Time Error 438, stating that the object doesn’t support this property or method. I don't know if I am writing the code to the wrong place or if I have an error in the code itself. Any help is appreciated!! (I am running Access...
4
3982
by: Jeff | last post by:
Hey I'm wondering how the Fixed-Width Text Format is What I know is that the top line in this text format will contain column names. and each row beneath the top line represent for example a row in a table etc... But does fixed-with mean that every column has a fixed with: for example first column is 10 char wide and second column is 30 char wide?
1
2937
by: kostareject | last post by:
Hello! Can anyone tell me how can I printi label/textbox Text property in MDI Child by clicking MDI Parent print button in C#! I have MDI Chil form with several labels and textboxes, and I want to print its content(label.text and/or textbox.text). Also I would like to see that in print preview dialog. The picture is in attachment... Please Help! Thanks!
0
1717
by: kostareject | last post by:
Hello! Can anyone tell me how can I printi label/textbox Text property in MDI Child by clicking MDI Parent print button in C#! I have MDI Chil form with several labels and textboxes, and I want to print its content(label.text and/or textbox.text). Also I would like to see that in print preview dialog. The picture is in attachment... Please Help! Thanks!
0
1101
by: umutesi | last post by:
I am developping a Database in access.I am tyring to make an access interface that will make a lot of things easier .Now I have a text field which is an Id for my table and it has Text as a datatype.How can I Auto Increment that Text Field,so that each time i add new record it increments automaticaly??For example having 6 records,after cliking add button it increment by one. THx
0
7934
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8424
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...
0
8415
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8069
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
8286
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
6742
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5886
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
1537
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1270
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.