Solved

Dynamic labels on a form

Posted on 2006-06-14
9
257 Views
Last Modified: 2010-04-23
Hello,

I have a form with 1 column of about 6 or 7 labels.

These label's text is generated from a mdb database

Sometimes, the text in the database is really long and I need a way to make the label multilined, shift everything below the label down and add a scrollbar if needed.

How would i go about this?

Bryan
0
Comment
Question by:bryanford
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 12

Expert Comment

by:omegaomega
ID: 16909721
Hello, Bryan,

I think that it is a bit difficult to determine the vertical size that will be required for the labels.  One of the overloads of the Graphics "MeasureString" method returns a line count.  I haven't done this, but I imagine that you could use this in the TextChanged event multiplied by the individual line height to set the height of the label's ClientSize property.  Then set the next label's position based on the position and height of this label (with an allowance for a vertical gap).  Perhaps you can use the PreferredHeight property to get the individual line height, and the GetNextControl method to determine which is the following label that needs to be moved.

Then in the Label's LocationChanged event, also set the next label's position, so that the position adjustment is propagated through all of the Form's labels.  (I'm assuming here that you are assigning the same event handler to each of the labels involved.)

Finally, just make sure that the Form's AutoScroll property is set to True, so that scroll bars will appear when required.

But, if all that seems too difficult, instead of labels you might consider using multiline textboxes (with vertical scroll bars, and ReadOnly property set to True.)

Cheers,
Randy
0
 
LVL 1

Author Comment

by:bryanford
ID: 16910251
I figured out an easier way myself. I used a TableLayoutPanel control from the toolbox and set autoscroll to true. Works marvelous.
0
 
LVL 12

Expert Comment

by:omegaomega
ID: 16910522
Hello, Bryan,

That's great that you found an easy solution.  

I guess this is a new control available in v2005.  (I'm still using v2003, so I cna't try it out.)  It looks very useful, but I can't see immediately how it handles the problem of resizing to accommodate all of the required text.  

Can you please give us a brief description of the technique that you used.  Thanks.

Cheers,
Randy
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:bryanford
ID: 16910539
Create a new form and in the tool box there is an item called TableLayoutPanel. Drag this in and modify its properties to specify how many rows and columns you want. Then simply drag some labels into each column, format as needed, then bind to a datasource. Thats all there is to it really. you can scroll the form if it exceeds the form size and best of all, if the text is really long, it will shift everything below it down to the margin you specify
0
 
LVL 12

Expert Comment

by:omegaomega
ID: 16910694
Hi, Bryan,

Thanks for the explanation.  So does this mean that in v2005 the Labels can be made to resize vertically instead of just horizontally?  That would be great, and I'll look forward to using it.

Cheers,
Randy
0
 
LVL 1

Author Comment

by:bryanford
ID: 16916806
if you set the maximum horizontal size in the properties, if it exceeds that it will automatically make it a multiline. is that what you mean?
0
 
LVL 12

Expert Comment

by:omegaomega
ID: 16918007
Hello, RomMod,

In my opinion, Bryan HAS responded diligently and adequately provided his solution.

Cheers,
Randy

Hello, Bryan,

Yes, MaximumSize appears to provide the answer.  I see that there are a lot of new properties available in v2005, and will hope that I can begin to apply some of them in my next project.

Cheers,
Randy
 
0
 

Accepted Solution

by:
RomMod earned 0 total points
ID: 16970541
Question closed - 250 points refunded.

Best regards,
RomMod
Experts Exchange
Community Support Moderator
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question