改变任何控件中每个角色的风格 [英] changing the style of every character within any control

查看:62
本文介绍了改变任何控件中每个角色的风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过从下拉列表中选择颜色,字体,阴影来动态更改任何控件中每个字符的样式



i am using this code

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

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.......

推荐答案

每个字符应位于不同的内联元素中,例如 span 。使用单独的CSS 属性,甚至是唯一的 id 属性,并学习如何使用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不能成为通常的输入控件。如果您希望同时使用此个人风格功能和可编辑行为,请使用属性 contenteditable

http://www.w3schools.com/tags/att_global_contenteditable.asp [ ^ ]。



请参阅我过去的回答:如何为每个字母插入不同颜色的不同字母文本框 [ ^ ]。







并且,顺便说一句:请不要重新发布你的问题。如果您在这个答案中没有得到任何答案,请询问一些后续问题。我可以看到,由于多次滥用报告,您的上一个问题已被删除。当成员重新发布问题并忽略现有答案时,通常会发生这种情况。一些沉重的滥用者甚至丢失了他们的CodeProject帐户。



-SA
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[^].



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


这篇关于改变任何控件中每个角色的风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆