Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to change the style of every character within any control dynamically by choosing a color,font,shadow from drop down list

i am using this code
C#
string first = txttext.Text;
        ViewState["first"] = first;
            //ViewState["first"] += first;
            //first = ViewState["first"].ToString();
            textsize();

            Label1.Height = Convert.ToInt32(txtheight.Text);
            Label1.Width = Unit.Parse(txtwidth.Text);
            Label1.ForeColor = System.Drawing.Color.FromName(ddlMultiColor.SelectedValue);
            Label1.BorderColor = System.Drawing.Color.FromName(ddlMultiColor1.SelectedValue);
            Label1.Font.Size = FontUnit.Parse(ddlborder.SelectedItem.Text);
            this.font = ddlfont.SelectedValue;
            this.fcolor = ddlMultiColor.SelectedValue;
            this.text = txttext.Text;
            this.border = ddlborder.SelectedValue;
            this.bcolor = ddlMultiColor1.SelectedValue;
            //Size maxsize = new Size(495, int.MaxValue);
            //Label1.Height = TextRenderer.MeasureText(Label1.Text, fobj, maxsize).Height;
            Label1.Font.Name = ddlfont.SelectedItem.Text;
            Label1.BorderWidth = Convert.ToInt32(ddlborder.SelectedValue);

            Label2.Text = Label1.Width.ToString();
            lblheight.Text = Label1.Height.ToString();
            //ViewState["first"] = txttext.Text;
           second = ViewState["first"].ToString();
           ViewState["second"] += second;
           second = ViewState["second"].ToString();

           Label1.Text += second;

but style of text is same as of the last character inserted.......
Posted
Updated 19-Nov-13 12:47pm
v2
Comments
CHill60 19-Nov-13 18:45pm    
Cool. What code are you using to do that?

1 solution

Each character should be in a different inline element, such as span. Use individual CSS class attribute or even unique id attribute and learn how to use CSS:
http://en.wikipedia.org/wiki/CSS[^],
http://www.w3.org/standards/webdesign/htmlcss#whatcss[^],
http://www.w3schools.com/css/[^],
http://www.mediawiki.org/wiki/Manual:CSS[^].

In cannot be a usual input control. If you want this "individual-style" feature and editable behavior at the same time, use the attribute contenteditable:
http://www.w3schools.com/tags/att_global_contenteditable.asp[^].

Please see my past answer: How can i insert different letters with different color for each letter in textbox[^].

[EDIT]

And, by the way: please don't re-post your question. If you did not get anything in this answer, ask some follow-up questions. As I can see, you last question has been deleted due to multiple abuse reports. It usually happens when members re-post questions and ignore existing answers. Some heavy abusers even lost their CodeProject accounts.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900