如果我添加下划线的任何文本长度不应该更改

如果我添加下划线的任何文本长度不应该更改

本文介绍了如何为固定长度插入下划线,如果我添加下划线的任何文本长度不应该更改,并且文本将在c#.net中带下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如何为固定长度插入下划线,如果我在下划线中添加任何文字,下划线的长度不应该增加,而且文字也会带下划线。



例如,



我给出100个空格并加下划线,现在我要在这里添加任何文字,长度100应该保持不变,它不应该增加取决于文本长度。



100下划线空格+任何文字长度是10 = 90 + 10.



可以帮我解决上面的问题。



谢谢提前

Gok

Hi All,

How to insert underline for a fixed length, if I add any text into that underline the lenght of the Underline should not increse and also the text also will come with underline.

For Example,

I given 100 spaces and it is underlined, now I'm going to add any text here, the length 100 should remain constant it should not increse depends on the text length.

100 underlined space + any text length is 10 = 90 + 10.

Can any help me on the above one.

Thanks in advance
Gok

推荐答案

private void textBox1_Validating(object sender, CancelEventArgs e)
{
    textBox1.Text = textBox1.Text.PadRight(100, '_');
}



请注意,这假设已使用普通文本框,并且当用户开始使用例如文本框输入时清除内容。


Note that this assumes that a normal textbox has been used and that you clear the contents when the user starts typing with e.g.

private void textBox1_Enter(object sender, EventArgs e)
{
    textBox1.SelectAll();
}





OP现在修改了他的问题并回复了评论。这是一个不是Winform的网页,OP需要所有的最终文本加下划线。

所以我把这个



OP has now amended his question and responded to comments. This is a Webpage not a Winform and OP requires all of the final text to be underlined.
So I put this

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        TextBox1.Font.Underline = true;
        TextBox1.Text = new String(' ', 100);
    }
}



然后这个


and then this

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    TextBox1.Text = TextBox1.Text.PadRight(100, ' ');
}


这篇关于如何为固定长度插入下划线,如果我添加下划线的任何文本长度不应该更改,并且文本将在c#.net中带下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:56