次の方法で共有


ユーザー入力を使用してテキスト ボックスのサイズを自動的に設定する

The following example demonstrates the effects of the AutoSize property with a single-line TextBox and a multiline TextBox. The user can enter text into either of the TextBox controls and turn AutoSize on or off independently of the contents of the TextBox. このコード サンプルでは 、Text プロパティも使用します。

この例を利用するには、次のコード例をフォームのスクリプト エディターにコピーします。 コードを実行するには、 Open イベントが生じるようにフォームを開く必要があります。 フォームには次のコントロールが含まれている必要があります。

  • 2 つのテキスト ボックス ( TextBox ) コントロール (TextBox1 と TextBox2)

  • トグル ボタン ( ToggleButton ) コントロール (ToggleButton1)

Dim ToggleButton1 
Dim TextBox1 
Dim TextBox2 
 
Sub Item_Open() 
 Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton1 
 Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").TextBox1 
 Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").TextBox2 
 
 TextBox1.Text = "Single-line TextBox. Type your text here." 
 
 TextBox2.MultiLine = True 
 TextBox2.Text = "Multi-line TextBox. Type your text here. Use SHIFT+ENTER to start a new line." 
 
 ToggleButton1.Value = True 
 ToggleButton1.Caption = "AutoSize On" 
 TextBox1.AutoSize = True 
 TextBox2.AutoSize = True 
End Sub 
 
Sub ToggleButton1_Click() 
 If ToggleButton1.Value = True Then 
 ToggleButton1.Caption = "AutoSize On" 
 TextBox1.AutoSize = True 
 TextBox2.AutoSize = True 
 Else 
 ToggleButton1.Caption = "AutoSize Off" 
 TextBox1.AutoSize = False 
 TextBox2.AutoSize = False 
 End If 
End Sub

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。