Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dynamic labels on a form

Posted on 2006-06-14
9
Medium Priority
?
258 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

670 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