我一直在尋找同樣不久前,最終執行以下操作。你可能不喜歡它,但我會分享它以防萬一。我使用TableLayoutPanel
來安排表單上的控件,然後交換所需控件的位置。
比如我創建了以下項目:
Form1 Design
TableLayoutPanel1
(兩列,三列)
TextBox1
只讀=真,背景色=白色
ComboBox1
Visible = False,DropDownStyle = DropDownList,FlatStyle = Popup
Button1
(將其命名爲更改)
Button2
(其命名爲Done) - >可見=假
Runtime - Screenshots
這裏是我的代碼:
Public Class Form1
Private Sub SwapControls(tlp As TableLayoutPanel, ctr1 As Control, ctr2 As Control)
Dim ctl1pos As TableLayoutPanelCellPosition = tlp.GetPositionFromControl(ctr1)
ctr1.Visible = False
tlp.SetCellPosition(ctr1, tlp.GetPositionFromControl(ctr2))
ctr2.Visible = True
tlp.SetCellPosition(ctr2, ctl1pos)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SwapControls(TableLayoutPanel1, TextBox1, ComboBox1)
SwapControls(TableLayoutPanel1, Button1, Button2)
Label1.Select()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
SwapControls(TableLayoutPanel1, ComboBox1, TextBox1)
SwapControls(TableLayoutPanel1, Button2, Button1)
Label1.Select()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label1.Select()
ComboBox1.SelectedIndex = 0
TextBox1.Text = ComboBox1.SelectedItem
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
TextBox1.Text = ComboBox1.SelectedItem
End Sub
End Class
什麼屬性的組合框的你具體改變? – 2012-02-06 05:15:59
好吧,這就是你實際禁用它時的樣子。 – Isuru 2012-02-06 05:33:47
您是否嘗試將您提及的任何項目轉換爲VB.Net? – 2012-02-06 06:54:28