以编程方式更改以图例控件结尾的行,c#
全部, 我在我的 asp.net 应用程序中使用 HTML 控件。我将其作为服务器控件运行,并从我的代码隐藏 (C#) 类中以编程方式访问它。请查看标记。 。 innerHTML 属性是从代码动态设置的。我的问题是,如果 InnerHTML 真的很长,我会以特定的字符间隔设置换行符。除了文本之间出现的水平线之外,看起来还不错。
我需要显示这样的文本
-----------This is my name
blah blahhhhhh------------------
,但现在它显示为
--------This is my name---------------
blah blah blah
Is there a way to set the lineprogramaticaly or using style? 谢谢你的帮助
All,
I am using an HTML control in my asp.net app.I run this as a server control and programatically access this from my code behind(C#) class.Plase see the markup.
. The innerHTML property is set dynamically from code.My issue is if the InnerHTML is really long , i set line breaks at specific char intervals. That looks ok except for the horizontal line that appears between the text.
I need to display text like this
-----------This is my name
blah blahhhhhh------------------
but right now it displays as
--------This is my name---------------
blah blah blah
Is there a way to set the line programaticcaly or using style?
thanks for help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行以下操作:
设置控件的宽度,以便内部文本自动换行到下一行
编辑控件的内容,在需要的地方插入换行符
没有方法可以自动转换文本,如示例所示。这是可能的,但您可能需要自己编写。
这里警告:您可以使用
"string".Length
轻松测量字母,但它不能保证字符串的实际宽度(以像素为单位)(考虑"iii"
> 在非固定宽度字体中比"www"
占用的空间更少)。如果你想测量像素,它会很快变得复杂,所以你最好测量字母的数量。You can do a few things :
set the width of your control so the text inside wraps automatically to the next line
Edit the content of the control, inserting line breaks where needed
There's no method to automatically transform text as your example shows. It is possible, but you might need to write it yourself.
A warning here : you can measure the letters easily with
"string".Length
but it gives no guarantee to the actual width, in pixels, of the string (consider"iii"
takes less room than"www"
in non-fixed width fonts). If you want to measure pixels, it gets complicated fast, so your better off measuring the number of letters.我认为你需要用样式来做到这一点:
I think you need to do it with styles: