473,480 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Create 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 11771
jimatqsi
1,271 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
11538
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...
8
3227
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...
0
1258
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...
1
3749
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...
2
2413
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...
8
12830
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...
4
3949
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...
1
2926
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...
0
1711
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...
0
1093
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 ...
0
7037
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
6904
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
6732
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
6886
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...
0
5324
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
4768
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
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
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 ...
0
174
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...

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.