如何動態設定TextBox的靠左、右、中

來源:cww

其實這是不可能一下子完成的,因為Alignment屬性是唯讀的,所以只好在Form中
使用三個TextBox來完成,Text1.Alignment = 0, Text2.Alignment = 1,
Text3.Alignment = 2,而且三者的MultiLine設為True。
並在Form中放三個Option Control,一開始Text2, Text3 Move到Text1的位置與大小,
而後看選擇哪個Option會來決定何者Display出來,而達效果

Option Explicit

Private Sub Form_Load()

Text2.Visible = False
Text3.Visible = False
Text2.Move Text1.Left, Text1.Top, Text1.Width, Text1.Height
Text3.Move Text1.Left, Text1.Top, Text1.Width, Text1.Height
Text2.Text = Text1.Text
Text3.Text = Text1.Text
End Sub

Private Sub Option1_Click()
If Option1.Value = True Then
   Text1.Visible = True
   Text2.Visible = False
   Text3.Visible = False
End If

End Sub

Private Sub Option2_Click()
If Option2.Value = True Then
   Text2.Visible = True
   Text1.Visible = False
   Text3.Visible = False
End If

End Sub

Private Sub Option3_Click()
If Option3.Value = True Then
   Text3.Visible = True
   Text1.Visible = False
   Text2.Visible = False
End If

End Sub

Private Sub Text1_Change()
Text2.Text = Text1.Text
Text3.Text = Text1.Text
End Sub

Private Sub Text2_Change()
Text1.Text = Text2.Text
Text3.Text = Text2.Text

End Sub

Private Sub Text3_Change()
Text1.Text = Text3.Text
Text2.Text = Text3.Text

End Sub