i have likes this equation; "label1.text = textbox.text" when my users click my button my form get the index of textbox to label but it arrange auto size for label and enlarge the width of label ;;;
but i want this, when text is reached to 10 letter so text must continue to new line;
summary i need multiline property in label;
is it posssible and if it is yes how???
can anyone help to me;
your sincerely; |
| Radith Wednesday, July 26, 2006 8:36 AM |
If you set the AutoSize property of the label to False and give the label a height so it can display mutiple lines of text, the label will take care of wrapping the text. |
| Rick van den Bosch OLD Wednesday, July 26, 2006 8:43 AM |
If you set the AutoSize property of the label to False and give the label a height so it can display mutiple lines of text, the label will take care of wrapping the text. |
| Rick van den Bosch OLD Wednesday, July 26, 2006 8:43 AM |
but it must be autosize for height; now it is auotsize for width i want it autosize for height;
when i did like that you said height have stable size but i wantautosize; |
| Radith Wednesday, July 26, 2006 1:50 PM |
You can calculate the text height your self some thing like
| |
private void SetLabelHeight(string text) { //Get Graphic object
Graphics g = label1.CreateGraphics(); //Get Text Height
SizeF size = g.MeasureString(text, label1.Font,label1.Width); //set label Height
label1.Height = (int)size.Height; //set label text
label1.Text = text; }
|
|
| Mohammad Al Husseiny Wednesday, July 26, 2006 2:04 PM |
Well try leaving AutoSize on until the text goes beyond 10 chars in length then switching it off. You could always writeyour own control. |
| Anthony D. Green Wednesday, July 26, 2006 11:47 PM |
protected void Button1_Click(object sender, EventArgs e) { string text = TextBox1.Text; Label1.Text = ""; int i = 0; for (; i < text.Length / 10; i += 10) { Label1.Text += text.Substring(i, 10) + "<br>"; }
Label1.Text += text.Substring(i, text.Length % 10); }
i tried like this click handler but it doesnt change anthing ;where is the mistake i couldnt find?? |
| Radith Thursday, July 27, 2006 9:16 AM |
hi radith
did you tried the solution i provide to you above? if yes?what happend
|
| Mohammad Al Husseiny Thursday, July 27, 2006 9:19 AM |
hi muhammed ;
it gives to me like this
the type or namespace graphics couldnt found ; and same error for sizeF and my label name is label1 too, like you write,so still it gives to me label1 doesnt exist in the current content;
it gives to me this errors
|
| Radith Thursday, July 27, 2006 11:30 AM |
are you sure that
using System.Drawing;
imported check it |
| Mohammad Al Husseiny Thursday, July 27, 2006 11:34 AM |
sorry i forgot it i addnamespace; but now it gives label1 doesnt exist current content; |
| Radith Thursday, July 27, 2006 12:10 PM |
are you sure that your control name is label1 and was created before you call the method
check it again |
| Mohammad Al Husseiny Thursday, July 27, 2006 12:16 PM |
sorry for my absent-mindedness and novice behavior muhammed;
but now it igves to me;
Error1'System.Web.UI.WebControls.Label' does not contain a definition for 'CreateGraphics'C:\Documents and Settings\Developer\My Documents\Visual Studio 2005\AddNewsModule\TextDisplay.ascx.cs7029C:\...\AddNewsModule\
Error2The best overloaded method match for 'System.Drawing.Graphics.MeasureString(string, System.Drawing.Font, System.Drawing.SizeF)' has some invalid argumentsC:\Documents and Settings\Developer\My Documents\Visual Studio 2005\AddNewsModule\TextDisplay.ascx.cs7322C:\...\AddNewsModule\
Error3Argument '2': cannot convert from 'System.Web.UI.WebControls.FontInfo' to 'System.Drawing.Font'C:\Documents and Settings\Developer\My Documents\Visual Studio 2005\AddNewsModule\TextDisplay.ascx.cs7344C:\...\AddNewsModule\
Error4Argument '3': cannot convert from 'System.Web.UI.WebControls.Unit' to 'System.Drawing.SizeF'C:\Documents and Settings\Developer\My Documents\Visual Studio 2005\AddNewsModule\TextDisplay.ascx.cs7357C:\...\AddNewsModule\
|
| Radith Thursday, July 27, 2006 12:26 PM |
you do not tell me that you use web forms my answer about winforms so i look for it again
|
| Mohammad Al Husseiny Thursday, July 27, 2006 12:32 PM |
selamin aleykum muhammed ;
muhammed have youread my this topic;
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=586510&SiteID=1
this is the my main problem about labels; ihow can i do thiswith multiline problem i have to do two of them;
i want to tell my purpose i have anwebpart page andit have catalog user can chose from it add newswhenit is clicked it add to form multiview ; view1=textbox and save news button;view2= label for displaying this input news; but ilabelmust have anpicture like apost it for news soand label mustwritenews verticalyauto size
this is my purpose which i asked my two topic;
thank you very much for your interest to me;
your sincerely ;
|
| Radith Thursday, July 27, 2006 12:37 PM |
oh really sory but i tell you all of my problems with my post now you can see in this section ; i tell all of them; |
| Radith Thursday, July 27, 2006 12:38 PM |