2012-07-11 5 views
3

similar thread about this이 있습니다. 하지만 자동 너비 (더 큰 행에 맞게 너비가)와 함께 여러 줄 TextBox를 갖고 싶습니다. 당신의 도움에 대한 자동 텍스트 상자 너비

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

다시 한번 감사 :

이 코드와 나는

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

코드 뒤에 여러 줄로 구성된 TextBox (자동 높이)를 가질 수있다. 당신은 당신이 자동 크기 플러그인 보라, JQuery와 같은 을 플러그인을 사용하여 열려있는 경우

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

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

답변

2

당신은 LINQ의 접근 방법을 시도 할 수 있습니다.

사용자 유형에 따라 크기가 조정됩니다.

체크 아웃 한 autoresize

$(document).ready(function(){ 
    $('textarea').autosize(); 
}); 
1

:

+0

멋진 팁 nunespascal,하지만 jQuery, 감사를 사용할 수 없습니다. – Coyolero

0

조엘 Etherton 나에게 Linq에를 사용하여이 문제를 해결하는 방법에 대한 정말 좋은 작업 코드 예제를 제공하지만, unfurtenly 내가 Linq에 사용할 수 없습니다.

Linq에 (조엘 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 

여러 줄 텍스트 상자의 자동 폭 솔루션이 이 "수동"을 달성하기 위해 , 나는 더 큰 줄의 길이를 알기 위해이 방법을 사용했다. 가장 효율적인 것은 아니지만 그것은 나를 위해 일했습니다 :

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