Hallo,
ich versuche momentan verzweifelt, eine Trackbar in mein vb.net Projekt angezeigt zu bekommen. Ich habe ein einfaches Projekt gemacht, bei dem der Wert der Trackbar in einem Label angezeigt wird.
Das funktioniert! Ich kann mit der Trackbar den Text vom Label1 verändern. Nun habe ich das 1:1 in mein aktuelles Projekt übernommen. Allerdings wird die Trackbar nicht angezeigt... Sie soll sich in einer Groupbox (Groupbox4) befinden.Code:Public Class Form1 Private TB As TrackBar Private WithEvents TrackB As TrackBar Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TB = New TrackBar With TB .Orientation = Orientation.Vertical .Name = "TrackBar" .SetRange(0, 100) .SetBounds(10, 40, 30, Me.ClientSize.Height - 50) .SmallChange = 1 .LargeChange = 10 .TickFrequency = 10 .TickStyle = TickStyle.Both End With Me.Controls.Add(TB) AddHandler TB.ValueChanged, AddressOf TrackB_ValueChanged Label1.Text = TB.Value.ToString End Sub Private Sub TrackB_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackB.ValueChanged Label1.Text = TB.Value.ToString End Sub End Class
Egal, wie ich den Wert von Location auch verändere, ich sehe die Trackbar einfach nicht... Vielleicht kann mir jemand helfen und sieht den Fehler?Code:Public Class Form1 Dim output(9) As Byte Dim textboxtext As String Dim crc8_string As String Dim tmp_string As String Private tb As TrackBar Private WithEvents TrackB As TrackBar Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load brake_combobox.SelectedIndex = 0 battery_type_combobox.SelectedIndex = 0 cutoff_mode_combobox.SelectedIndex = 0 cutoff_threshold_combobox.SelectedIndex = 1 startup_mode_combobox.SelectedIndex = 0 timing_combobox.SelectedIndex = 0 disconnectbutton.Enabled = False connectbutton.Enabled = True refreshbutton.PerformClick() baudratecombobox.SelectedIndex = 9 minthrottletextbox.Text = "990" maxthrottletextbox.Text = "1020" refreshbutton.PerformClick() comcombobox.SelectedIndex = 0 tb = New TrackBar With tb .Orientation = Orientation.Horizontal .Name = "TrackBar" .SetRange(0, 255) .SetBounds(400, 450, 300, 30) .SmallChange = 1 .LargeChange = 10 .TickFrequency = 10 .TickStyle = TickStyle.Both .BringToFront() End With Me.Controls.Add(tb) AddHandler tb.ValueChanged, AddressOf TrackB_ValueChanged End Sub Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.Closing If serialport.IsOpen() = True Then serialport.Close() End If End Sub Private Sub connectbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles connectbutton.Click If comcombobox.SelectedItem = "" Or baudratecombobox.SelectedItem = "" Then MsgBox("Please check your RS232 Settings!") Else serialport.BaudRate = Val(Str(baudratecombobox.SelectedItem())) serialport.Open() connectbutton.Enabled = False disconnectbutton.Enabled = True End If End Sub Private Sub disconnectbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles disconnectbutton.Click serialport.Close() connectbutton.Enabled = True disconnectbutton.Enabled = False End Sub Private Sub refreshbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles refreshbutton.Click Dim ports As String() comcombobox.Items.Clear() ports = IO.Ports.SerialPort.GetPortNames() For Each port In ports Try With serialport .PortName = port .ReadTimeout = Int32.Parse(500) .Open() End With Catch es As Exception Finally If serialport.IsOpen = True Then Me.comcombobox.Items.Add(port) End If serialport.Close() End Try Next port End Sub Private Sub i2cstandardbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles i2cstandardbutton.Click minthrottletextbox.Text = "990" maxthrottletextbox.Text = "1020" End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles setalltodefaultbutton.Click brake_combobox.SelectedIndex = 0 battery_type_combobox.SelectedIndex = 0 cutoff_mode_combobox.SelectedIndex = 0 cutoff_threshold_combobox.SelectedIndex = 1 startup_mode_combobox.SelectedIndex = 0 timing_combobox.SelectedIndex = 0 MsgBox("Default Setting set!") End Sub Private Sub ToolTip1_Popup(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PopupEventArgs) Handles ToolTip1.Popup End Sub Private Sub setthrottlebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles setthrottlebutton.Click End Sub Private Sub transferbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles transferbutton.Click output(1) = brake_combobox.SelectedIndex + 1 output(2) = battery_type_combobox.SelectedIndex + 1 output(3) = cutoff_mode_combobox.SelectedIndex + 1 output(4) = cutoff_threshold_combobox.SelectedIndex + 1 output(5) = startup_mode_combobox.SelectedIndex + 1 output(6) = timing_combobox.SelectedIndex + 1 output(7) = Val(minthrottletextbox.Text) / 10 output(8) = Val(maxthrottletextbox.Text) / 10 output(9) = Docrc8(output, 8) If serialport.IsOpen() = True Then serialport.Write(output, 1, 9) End If End Sub Private Sub minthrottletextbox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles minthrottletextbox.KeyPress Select Case Asc(e.KeyChar) Case 48 To 57, 8 ' Zahlen und Backspace zulassen Case Else ' alle anderen Eingaben unterdrücken e.Handled = True End Select End Sub Private Sub maxthrottletextbox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles maxthrottletextbox.KeyPress Select Case Asc(e.KeyChar) Case 48 To 57, 8 ' Zahlen und Backspace zulassen Case Else ' alle anderen Eingaben unterdrücken e.Handled = True End Select End Sub Private Sub serialport_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialport.DataReceived tmp_string = serialport.ReadLine() If tmp_string = "sd!" Then transferbutton.PerformClick() Else textboxtext = textboxtext + tmp_string + vbNewLine End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick TextBox1.Text = textboxtext End Sub Private Sub cleardialogbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cleardialogbutton.Click textboxtext = "" End Sub Function Docrc8(ByVal bytear() As Byte, ByVal cnt As Byte) As Byte Dim j As Byte Dim k As Byte Dim crc8 As Byte Dim m As Integer Dim x As Integer crc8 = 0 For m = 1 To cnt x = bytear(m) For k = 0 To 7 j = 1 And (x Xor crc8) crc8 = Fix(crc8 / 2) And &HFF x = Fix(x / 2) And &HFF If j <> 0 Then crc8 = crc8 Xor &H8C End If Next k Next Docrc8 = crc8 End Function Private Sub halfspeedbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles halfspeedbutton.Click For i As Byte = 2 To 8 output(i) = 0 Next output(1) = 127 output(9) = Docrc8(output, 8) If serialport.IsOpen = True Then serialport.Write(output, 1, 9) End If End Sub Private Sub fullspeedbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fullspeedbutton.Click For i As Byte = 2 To 8 output(i) = 0 Next output(1) = 255 output(9) = Docrc8(output, 8) If serialport.IsOpen = True Then serialport.Write(output, 1, 9) End If End Sub Private Sub TrackB_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles trackb.ValueChanged Label11.Text = TB.Value.ToString End Sub End Class
Vielen Dank & Gruß
Chris
Lesezeichen