Hi guys!
I'm pretty new with this WPF, and now I'm trying to make a countdowner. The option is here that you can type min and sec into to several text boxes and they show up as label (? or what should I use for countdown), and when someone press Start it counts down from the minutes and seconds that was typed in. You guys can see a picture of how far I have come:
PICTURE
For now I have those zeros as label, but I want them to count down when time (added time under Game time) is placed and when button Start is pressed.
And I also want when someone press "point team 1" the label will show number 1, 2 and up.
I want mine to look like this flash based program:
PICTURE
I can't get that style on the number either.
So can you guys help me out here?
I have added System.Timer and System.Windows.Threading under "imported namespaces" but I can't find timer or dispatchertimer in the toolbox!
I have also tried something another guy showed me:
<TextBlock x:Name="clockText" TextWrapping="Wrap" Text="0:00" VerticalAlignment="Top" Margin="8,8,0,0" FontSize="32" HorizontalAlignment="Left" Width="340"/> <Button x:Name="startBtn" Content="Start" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Margin="8,54.563,0,0" Click="startClock"/>
private void startClock(object sender, System.Windows.RoutedEventArgs e) { TimeSpan t1 = new TimeSpan(0, 0, 0, 10); TimeSpan t2 = new TimeSpan(0, 0, 0, 1); int counter = 0; DT.Tick += delegate { counter++; t1 = t1 - t2; string a = t1.ToString(); string b = a.Substring(3); this.clockText.Text = b; if (b == "00:00") { DT.Stop(); } }; DT.Interval = new TimeSpan(0, 0, 0, 1); DT.Start(); }
But when I copied that into the code (.vb) I got alot of blue lines under there and 20 errors. See picture:
PICTURE
Hope you guys can help me out here.. I really appreciate it! :)
Loading
Sam HobbsPosted Jan 2, 2012, 11:06 AM
Sam HobbsPosted Jan 4, 2012, 5:33 PM
Simen S MPosted Jan 4, 2012, 4:55 PM
But now I'm stressing with "multibinding".
Is it possible to "multibind"? You know I have like this when someone type in the two textbox with minutes and seconds, the labels minutes and seconds update, is it possible to do the same with a combobox? I have for example now, 3:00 one of the option in combobox, when someone select this, label min and sec updates?
I have tried this but it didnt work:
Simen S MPosted Jan 2, 2012, 5:23 PM
Dim tsend As TimeSpan = New TimeSpan(0, 0, 0, 10)
That it counts up to 10, that if I add a - so it will be -10, it will count downwards, but no..
Or maybe:
Dim tsi As TimeSpan = New TimeSpan(0, 0, 0, 1)
Add -1, but then it must be like this:
DT.Interval = -tsi
instead of:
DT.Interval = tsi
But that didnt work either.. Ill have to figure it out tomorrow ;) thanks for answer.
Sam HobbsPosted Jan 2, 2012, 4:44 PM
I don't know WPF well enough to know how to use a label instead.
Simen S MPosted Jan 2, 2012, 12:17 PM
I FINALLY got it working! It finally counts upwards! But I want it to count downwards. Is that possible?
EDIT: And can I only use textblock to make it count down? I can't make Labels count down?
Simen S MPosted Jan 2, 2012, 8:21 AM
Yes, the guy that showed me the code also said now that it was for C#, but I tried to convert the code from C# to VB.NET, and that gave me this code:
Private Sub startClock(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
Dim t1 As TimeSpan = New TimeSpan(0, 0, 0, 10)
Dim t2 As TimeSpan = New TimeSpan(0, 0, 0, 1)
Dim counter As Integer = 0
counter = (counter + 1)
t1 = (t1 - t2)
Dim a As String = t1.ToString
Dim b As String = a.Substring(3)
Me.clockText.Text = b
If (b = "00:00") Then
DT.Stop
End If
DT.Interval = New TimeSpan(0, 0, 0, 1)
DT.Start
End Sub
But there was nothing called "DT", VB just said "not declared".
But maybe I can try using DispatcherTimer Class? But I'm not really sure how I begin with this code. I can't really just copy the example from the link into the code text either, because "dispatcherTimer" is not declared/declaration expected. This does not work:
Private Sub Label1(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Public NotInheritable Class Dispatcher
dispatcherTimer = New Threading.DispatcherTimer()
AddHandler dispatcherTimer.Tick, AddressOf dispatcherTimer_Tick
Dispatcher.Timer = New TimeSpan(0, 0, 1)
dispatcherTimer.Start()
Or maybe TimeSpan?
Please help me out here guys :(
Thanks for answers.
Pravin GhadgePosted Jan 1, 2012, 9:26 PM
Code which u have copy pasted is of C# & u r working on VB.net application.
So plz check ur syntax.
Sam HobbsPosted Jan 1, 2012, 6:57 PM