close







如何更改VB下拉式選單的點選結果?




立即點擊


我使用的編輯環境是VB2008想要做下拉式選單,選單中有111、222、333選擇111就會變成AAA選擇222就會變成BBB選擇333就會變成CCC以下是我寫的程式---------------------------------------------------------------------------------------------PublicClassForm1PrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handles...顯示更多我使用的編輯環境是VB2008想要做下拉式選單,選單中有111、222、333選擇111就會變成AAA選擇222就會變成BBB選擇333就會變成CCC以下是我寫的程式---------------------------------------------------------------------------------------------PublicClassForm1PrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.LoadComboBox1.Items.Add("111")ComboBox1.Items.Add("222")ComboBox1.Items.Add("333")EndSubPrivateSubComboBox1_SelectedIndexChanged(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesComboBox1.SelectedIndexChangedIfComboBox1.SelectedIndex=0ThenComboBox1.Text="AAA"ElseIfComboBox1.SelectedIndex=1ThenComboBox1.Text="BBB"ElseIfComboBox1.SelectedIndex=2ThenComboBox1.Text="CCC"EndIfEndSubEndClass-----------------------------------------------------------結果點了111仍顯示111點了222仍顯示222點了333仍顯示333請問VB高手們要怎樣修改才可以改變點選結果顯示?更新:謝謝Wu的解答我想做的ComboBox總共有7個如果用Timer來防止Text值變回預設值的話,就需要做7個Timer是否有甚麼方法可以只共用1個Timer或者完全不使用Timer就可以防止Text值變回預設值?





這是因為 SelectedIndexChanged 事件後,VB將使用默認的處理更新回選定的值。需要使用計時器以達到您的目的 Public Class Form1 Private strMessage As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.Items.Add("111") ComboBox1.Items.Add("222") ComboBox1.Items.Add("333") End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If ComboBox1.SelectedIndex = 0 Then strMessage = "AAA" UpdateCombo() ElseIf ComboBox1.SelectedIndex = 1 Then strMessage = "BBB" UpdateCombo() ElseIf ComboBox1.SelectedIndex = 2 Then strMessage = "CCC" UpdateCombo() End If End Sub Private Sub UpdateCombo() Timer1.Interval = 1 Timer1.Start() End Sub Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick ComboBox1.Text = strMessage ComboBox1.Refresh() Timer1.Stop() End Sub End Class 2010-03-16 12:45:12 補充: 只共用1個Timer: Private strMessage As String Private objCombo As ComboBox Private Sub UpdateCombo(ByVal strMsg As String, ByVal objSender As ComboBox) objCombo = objSender strMessage = strMsg Timer1.Interval = 1 Timer1.Start() End Sub 2010-03-16 12:45:55 補充: Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick objCombo.Text = strMessage objCombo.Refresh() Timer1.Stop() End Sub 2010-03-16 12:48:21 補充: strMessage = "AAA" UpdateCombo() 改為 UpdateCombo("AAA", sender) 在這種情況下,許多 Combobox 可以調用相同UpdateCombo 函數








以上文章來自奇摩知識家,如有侵犯請留言告知


https://tw.answers.yahoo.com/question/index?qid=20100311000016KK03725

C902071D09AF7660
arrow
arrow

    訂飯店 發表在 痞客邦 留言(0) 人氣()