So etwas sollte für Sie funktionieren:
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'Your combo box should be built and populated when the form loads, not when the combo box is changed ComboBox1.Items.Add("6") ComboBox1.Items.Add("10") ComboBox1.Items.Add("12") ComboBox1.SelectedIndex = 0 'This Auto-Selects the first entry to prevent you having to handle "null"'s End Sub Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged Dim tryParseResult As Boolean 'holds the True/False for whether conversion to a number worked Dim parsedNumber As Integer 'Holds the number after conversion tryParseResult = Int32.TryParse(ComboBox1.SelectedItem, parsedNumber) 'try converting to number - "parsedNumber" will contain the number on success - "tryParseResult" will contain a true/false for success 'If tryPArseResult = False - conversion failed - tell the user and stop. If tryParseResult = False Then MessageBox.Show("Conversion of " & ComboBox1.SelectedItem & " To Number Failed") 'Tell the user it failed Exit Sub 'Stop processing End If 'Set TextBox1's Font to the same font with a new size TextBox1.Font = New Font(TextBox1.Font.Name, parsedNumber) End Sub End Class
Wenn Sie dies mit Multiplikator-Steuerelementen ausführen möchten, müssen Sie sich das Durchlaufen von Steuerelementen in einem Formular ansehen, OfType
wenn Sie nur mit bestimmten Steuerelementen arbeiten möchten