473,526 Members | 2,918 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically shrink font in Textbox

1 New Member
I have a report textbox that contains a name. Because the report is for labels, I don't want it to grow. Instead, I want to see if the name is too big for the field width and then reduce the size of the font until it fits. Basically, I'm looking for a "ItWillGrow" property that will allow me to resize the field using VB. I'm thinking of using the "OnFormat" event of the details section.

Thanks for your help!

- Mike Heyden
Jun 20 '07 #1
2 7510
Rabbit
12,516 Recognized Expert Moderator MVP
I have a report textbox that contains a name. Because the report is for labels, I don't want it to grow. Instead, I want to see if the name is too big for the field width and then reduce the size of the font until it fits. Basically, I'm looking for a "ItWillGrow" property that will allow me to resize the field using VB. I'm thinking of using the "OnFormat" event of the details section.

Thanks for your help!

- Mike Heyden
What version of Access are you using?

Try using conditional formatting to check the length of the string and if over a certain length, reduce the font size.
Jun 20 '07 #2
dima69
181 Recognized Expert New Member
Basically, I agree with Rabbit, although I woul take it a little further.
The problem here is that you cannot actually evaluate the string width from it's length when using true type fonts.
So for this purpose I use report's TextWidth property.
The sample code will look like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(...)
  2. dim R as Single
  3. Me.FontName = "Areal" 'Your default font here
  4. Me.FontSize = 10 'Your default font size here
  5. R = Me.TextWidth(Me![MyTextStr]) / Me![MyTextStr].Width
  6. If R >= 1 then
  7.     Me![MyTextStr].FontSize = 10 'Don't forget to restore original font size
  8. Else
  9.     Me![MyTextStr].FontSize = 10*R
  10. End If
  11. End Sub
Jun 21 '07 #3

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

Similar topics

2
355
by: fplisa | last post by:
Hi- I have code that dynamically adds 1 to 10 textboxes to a form. The user is asked how many boxes he/she needs. Problem is, I can't get to the events of each box that is added EXCEPT for the last one. I need to do a running total of the text boxes as the user enters a value and moves onto the next textbox
3
3650
by: pnp | last post by:
I have created a coposite user control of a text box and a label. I have exposed the font of the textbox property through a property of the control but every time I try to change that through the property grid of the designer when I use the composite control in a form, after a rebuild the changes seem to get lost! I don't see the Font property...
1
3006
by: Shilpi Chaudhry | last post by:
I have a forloop which I use to create textboxes - but unfortunately all of them have the same ids - I need to assign different ids to these textboxes creeated in the loop so that I can retrieve their corrs values. Anybody?? Code snippet: <% int y = 7; %>
1
4486
by: dx | last post by:
I'm extremely frustrated with ASP.NET...again! To me this should be as simple as setting oCheckBox.Checked = True.. yet for some reason it isn't. I have a user control (ascx) that that has a checkbox and I can't get it to default to checked. I tried radiobuttons and experienced the same result.. can't start them as checked. The really...
3
1228
by: SD | last post by:
Hello, I have a form that has a panel container where I'm adding textboxes dynamically based on a query to database, so I'm looping through the records. The problem I have is that once built, I need to pass those textboxes values to another for to build the parameters for a report. Here is the sample:
0
2081
by: loga123 | last post by:
Hi All, I am very new to .net and trying to develop a small application. I am using asp .net 2.0. I have a table control (server) in my code that has header row like this. <asp:Table id="Table1" GridLines="Both"
0
2385
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event, which I am). I now want to read the text/values of those controls. I have found out that I can read the values if I wait until Page_Load, but then I...
1
7515
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and having the sql statement dynamically built according to the input provided by the user. I have used the method described here hundreds of times it is...
8
2132
by: NIKHILUNNIKRISHNAN | last post by:
Experts, I have a textbox which displays some contents in some font. I am providing the user a dialog which will provide him the options to change the font. The change is getting refelcted only when the user restarts the application.I want to change the font of the text box dynamically; ie; when the user selects the new font,it should be...
0
7329
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7653
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...
1
7236
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...
0
7604
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...
0
5782
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...
1
5176
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...
0
3318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1703
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
0
551
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...

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.