4

これについても同様のスレッドがあります。しかし、自動幅の複数行 TextBox が必要です(幅をより大きな行に合わせる)。

このコードを使用すると、複数行の TextBox (自動高さ) を使用できます

     <div style="float:left; white-space:nowrap ">
        <asp:TextBox style="display:inline; overflow:hidden"  
                     ID="txt1" 
                     runat="server" 
                     Wrap="false" 
                     ReadOnly="true" 
                     TextMode="MultiLine" 
                     BorderStyle="none" 
                     BorderWidth="0">
        </asp:TextBox>
    </div>
    <div style="float:left">
        <asp:TextBox ID="txt2" runat="server" Text="Example textbox"></asp:TextBox>
    </div>

コードビハインド:

txt1.Rows= text.Split("|").Length ' Sets number of rows but with low performance
txt1.Text = text.Replace("|", Environment.NewLine)

もう一度、あなたの助けに感謝します。

4

3 に答える 3

3

linq アプローチを試すことができます。

string[] rows = text.Split('|');
int maxLength = rows.Max(x => x.Length);

txt1.Rows = rows.Length;
txt1.Columns = maxLength;
于 2012-07-11T18:19:09.730 に答える
1

jquery などのプラグインの使用にオープンな場合は、autoresize プラグインを検討する必要があります。

これらもユーザーが入力するとサイズが変更されます。

1 つの自動サイズ変更を確認する

$(document).ready(function(){
    $('textarea').autosize();  
});
于 2012-07-11T18:28:13.757 に答える
0

Joel Ethertonは、Linqを使用してこれを解決する方法の実際に機能するコード例を教えてくれますが、残念ながら、Linqを使用することはできません。

Linqを使用した複数行のTextBox自動幅(Joel Ethertonのソリューション):C#

string[] rows = text.Split('|');
int maxLength = rows.Max(x => x.Length);

txt1.Rows = rows.Length;
txt1.Columns = maxLength;

VB

    Dim rows() As String = text.Split("|")
    Dim maxLength As Integer = rows.Max(Function(x) x.Length)
    txt1.Rows = rows.Length
    txt1.Columns = maxLength
    text = text.Replace("|", Environment.NewLine)
    txt1.Text = text

複数行のTextBox自動幅ソリューション2 これを「手動で」実現するために、このメソッドを実行して、より大きな行の長さを確認しました。最も効率的なものではありませんが、それは私のために働きました:

    Dim textRows() As String = text.Split("|")

    For Each row As String In textRows
        row = row.Trim
        textToDisplay = String.Format("{0}{1}{2}", textToDisplay, row, Environment.NewLine)
        If row.Length > maxRowLenght Then
            maxRowLenght = row.Length
        End If
    Next
    txt1.Rows = textRows.Length
    txt1.Columns = maxRowLenght
    txt1.Text = textToDisplay
于 2012-07-12T05:10:11.813 に答える