Wrox Programmer Forums
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 21st, 2004, 02:54 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default length of label

How to give the maximum length of label in .Net.
I have to display 4000 characters in a label.

 
Old July 21st, 2004, 08:12 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You want to show 4000 characters but it won't? I don't understand the question.
 
Old July 22nd, 2004, 01:22 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is nothing difficult to understand. I want to display 4000 characters in a label. So that all the 4000 characters can be visible to the user.How to set the maximum length of the label?

 
Old July 22nd, 2004, 01:48 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

I don't think so we can set label's maximum length.You can show the 4000 characters to the user by increasing Width property.

 
Old July 22nd, 2004, 04:43 AM
Authorized User
 
Join Date: Mar 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

why don't you do a function to maximize your 4000 character? it is like

If Len(lblSample) > 4000 Then
 lblSample = Left(lblSample, 4000)
End If


 
Old July 22nd, 2004, 12:09 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

(I appologize for my inability to understand your question, despite its lack of detail.)

What kind of application are you building? You have not specified if this is a windows or web form application, though I can assume from the fact that you have not been able to get it to work that you are building a windows form application. Perhaps more detail about your application would be helpful.

I do not know if there are any "visual metrics" capabilities in windows forms controls such that you can determine if the contents of a control such as a label are getting "clipped".
 
Old July 22nd, 2004, 02:00 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Your question *was* difficult to understand. Since you didn't specify your target application, it was hard to guess what you wanted. By default, a Web "label" will adjust its size to display all 4,000 characters automatically.

Anyway, if you want to measure the size of a String look into the MeasureString method. The following code will tell you how large String to Measure will be:
Code:
string measureString = "String to Measure";
Font stringFont = new Font("Arial", 12);
Bitmap myBitmap = new Bitmap(100, 100);
SizeF stringSize = new SizeF();
Graphics myGrahpics = Graphics.FromImage(myBitmap);
stringSize = myGrahpics.MeasureString(measureString, stringFont);
You'll need the System.Drawing namespace for this work.

The SizeF struct, stringSize, exposes a Height and a Width property of your string in Pixels as a float, so you may need to do some rounding.

I haven't found a way yet to do this without creating the intermediate Bitmap object, but there may be ways around it.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Was Besonderes by Guano Apes (Track 3 from the album: Proud Like a God) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
length crmpicco Classic ASP Basics 1 February 11th, 2005 11:24 AM
Get the length of Attachment rekha_jsr Javascript How-To 1 January 7th, 2005 12:15 AM
How to get the "Length" of a column Guillermo Hdez ADO.NET 0 October 29th, 2004 07:31 AM
Record length ?!? hcweb Classic ASP Basics 2 November 1st, 2003 11:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.