英語で読む

次の方法で共有


TextBox.MaxLines プロパティ

定義

表示行の最大数を取得または設定します。

public int MaxLines { get; set; }

プロパティ値

表示行の最大数。 既定値は Int32.MaxValue です

例外

MaxLinesMinLines より小さい値です。

次の例は、値が 5 の を TextBox 作成する方法を MaxLines 示しています。

<Page  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <StackPanel>
    <TextBox 
      Text="Initial text in TextBox" 
      Width="200" 
      TextAlignment="Center"
      TextWrapping="Wrap" 
      MaxLength="500"
      MinLines="1" 
      MaxLines="5" />
  </StackPanel>
</Page>
StackPanel myStackPanel = new StackPanel();

//Create TextBox
TextBox myTextBox = new TextBox();
myTextBox.Width = 200;

// Put some initial text in the TextBox.
myTextBox.Text = "Initial text in TextBox";

// Set the maximum characters a user can manually type
// into the TextBox.
myTextBox.MaxLength = 500;
myTextBox.MinLines = 1;

// Set the maximum number of lines the TextBox will expand to 
// accomidate text. Note: This does not constrain the amount of 
// text that can be typed. To do that, use the MaxLength property.
myTextBox.MaxLines = 5;

// The text typed into the box is aligned in the center.
myTextBox.TextAlignment = TextAlignment.Center;

// When the text reaches the edge of the box, go to the next line.
myTextBox.TextWrapping = TextWrapping.Wrap;

myStackPanel.Children.Add(myTextBox);
this.Content = myStackPanel;

注釈

このプロパティを取得すると、 の現在の MaxLines値が返されます。 このプロパティを設定すると、表示される行の数が で MaxLines指定された制限を超えた場合、テキスト ボックスのサイズが変更されます。

このプロパティは、表示されている線にのみ適用され、実際の行数を制限しません。 その構成によっては、テキスト ボックスに、スクロールしてアクセスできる表示されない行が追加されている場合があります。

プロパティが Height で明示的にTextBox設定されている場合、 および MinLines プロパティのMaxLines値は無視されます。

依存プロパティ情報

識別子フィールド MaxLinesProperty
に設定されたメタデータ プロパティ true AffectsMeasure

適用対象

製品 バージョン
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

こちらもご覧ください