Friday, April 30, 2010

WPF School Part.1 - Timers and Checkboxes

I use the dispatchtimer with wpf applications. Here a short example.
Rename Window to MainWindow, add a checkbox.

Class Window1
Dim WithEvents MyTimer As New System.Windows.Threading.DispatcherTimer
Dim n As Integer = 0
Private Sub CheckBox1_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CheckBox1.Checked, CheckBox1.Unchecked
' Combined Checked and UnChecked event.
If CheckBox1.IsChecked Then
MyTimer.Start()
Else
MyTimer.Stop()
n = 0
End If
End Sub
Private Sub MyTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyTimer.Tick
n += 1
MainWindow.Title = n.ToString
End Sub
Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MainWindow.Loaded
MyTimer.Interval = New TimeSpan(500000) ' 50 ms, 100 ns/bit
End Sub
End Class


Note also how to handle the Checkbox Check event, there is no CheckChanged event in wpf.
In Windows Form Application you write like below:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
' To something when checked....
Else
' To something when unchecked....
End If
End Sub

In wpf you have to combine two events, .Checked and .Unchecked. The property .Checked is in wpf replaced with .IsChecked.

MySQL to MariaDB

 Here is a good description how to migrate to MariaDb MySQL to MariaDb Example of how to dump data from MySQL port=3307: mysqldump --user=ro...