[]
In the previous steps you set up the application's user interface and added C1NumberBox, Label, and Button controls to your application. In this step you'll add code to your application to finalize it.
Complete the following steps:
Double-click Button1 to switch to Code view and create the Button1_Click event handler.
Add the following imports statements to the top of the page:
Imports C1.WPF
Imports System.Windows.Media
Imports System.Diagnosticsusing C1.WPF;
using System.Windows.Media;
using System.Diagnostics;Initialize the following global variables just inside class Window1 or Page:
Dim nb1 As Integer = 5
Dim nb2 As Integer = 2
Dim nb3 As Integer = 3
Dim nb4 As Integer = 7
Dim nb5 As Integer = 9int nb1 = 5;
int nb2 = 2;
int nb3 = 3;
int nb4 = 7;
int nb5 = 9;These numbers will be used as the correct 'code' in the application. When the user enters the correct combination of numbers at run time the button will appear.
Add code to the Button1_Click event handler so that it appears like the following:
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btn1.Click
HtmlPage.PopupWindow(New Uri("https://developer.mescius.com"), "new", Nothing)
End Subprivate void btn1_Click(object sender, RoutedEventArgs e)
{
HtmlPage.PopupWindow(New Uri("https://developer.mescius.com"), "new", null);
}Next add the following custom NBValidation event to your code:
Private Sub NBValidation()
If Me.c1nb1.Value = nb1 And Me.c1nb2.Value = nb2 And Me.c1nb3.Value = nb3 And Me.c1nb4.Value = nb4 And Me.c1nb5.Value = nb5 Then
Me.lbl2.Foreground = New SolidColorBrush(Colors.Green)
Me.lbl2.Content = "Combination Valid"
Me.c1nb1.IsReadOnly = True
Me.c1nb2.IsReadOnly = True
Me.c1nb3.IsReadOnly = True
Me.c1nb4.IsReadOnly = True
Me.c1nb5.IsReadOnly = True
Me.btn1.Visibility = Windows.Visibility.Visible
End If
End Subprivate void NBValidation()
{
if (this.c1nb1.Value == nb1 & this.c1nb2.Value == nb2 & this.c1nb3.Value == nb3 & this.c1nb4.Value == nb4 & this.c1nb5.Value == nb5)
{
this.lbl2.Foreground = new SolidColorBrush(Colors.Green);
this.lbl2.Content = "Combination Valid";
this.c1nb1.IsReadOnly = true;
this.c1nb2.IsReadOnly = true;
this.c1nb3.IsReadOnly = true;
this.c1nb4.IsReadOnly = true;
this.c1nb5.IsReadOnly = true;
this.btn1.Visibility = Windows.Visibility.Visible;
}
}When the user enters the correct numbers (as indicated in step 3 above) the C1NumericBox controls will be set to read only and will no longer be editable, the text of the label below the controls will change to indicate the correct code has been entered, and a button will appear allowing users to enter the ComponentOne Web site.
Add C1NumericBox_ValueChanged event handlers to initialize NBValidation. The code will look like the following:
Private Sub c1nb1_ValueChanged(ByVal sender As System.Object, ByVal e As C1.Silverlight.PropertyChangedEventArgs(Of System.Double)) Handles c1nb1.ValueChanged
NBValidation()
End Sub
Private Sub c1nb2_ValueChanged(ByVal sender As System.Object, ByVal e As C1.Silverlight.PropertyChangedEventArgs(Of System.Double)) Handles c1nb2.ValueChanged
NBValidation()
End Sub
Private Sub c1nb3_ValueChanged(ByVal sender As System.Object, ByVal e As C1.Silverlight.PropertyChangedEventArgs(Of System.Double)) Handles c1nb3.ValueChanged
NBValidation()
End Sub
Private Sub c1nb4_ValueChanged(ByVal sender As System.Object, ByVal e As C1.Silverlight.PropertyChangedEventArgs(Of System.Double)) Handles c1nb4.ValueChanged
NBValidation()
End Sub
Private Sub c1nb5_ValueChanged(ByVal sender As System.Object, ByVal e As C1.Silverlight.PropertyChangedEventArgs(Of System.Double)) Handles c1nb5.ValueChanged
NBValidation()
End Subprivate void c1nb1_ValueChanged(object sender, PropertyChangedEventArgs<double> e)
{
NBValidation();
}
private void c1nb2_ValueChanged(object sender, PropertyChangedEventArgs<double> e)
{
NBValidation();
}
private void c1nb3_ValueChanged(object sender, PropertyChangedEventArgs<double> e)
{
NBValidation();
}
private void c1nb4_ValueChanged(object sender, PropertyChangedEventArgs<double> e)
{
NBValidation();
}
private void c1nb5_ValueChanged(object sender, PropertyChangedEventArgs<double> e)
{
NBValidation();
}In this step you completed adding code to your application. In the next step you'll run the application and observe run-time interactions.