In the previous steps you set up the application's user interface and added controls to your application. In this step you'll add code to your application to finalize it.
Complete the following steps:
1. Click once on the first C1ColorPicker control (C1ColorPicker1) to select it.
2. In the Properties window, click the lightning bolt Events icon to view control events.
3. Double-click in the text box next to the SelectedColorChanged event to switch to Code view and create the event handler.
4. In Code view, add the following import statements to the top of the page:
Imports C1.WPF
Imports C1.WPF.Extended
•C#
using C1.WPF;
using C1.WPF.Extended;
5. Add the following code just after the page's constructor to update the gradient values:
Private Sub UpdateGradient()
If C1ColorPicker1 IsNot Nothing And C1ColorPicker2 IsNot Nothing Then
Me.col1.Color = Me.C1ColorPicker1.SelectedColor
Me.col2.Color = Me.C1ColorPicker2.SelectedColor
End If
End Sub
•C#
void UpdateGradient()
{
if (c1ColorPicker1 != null & c1ColorPicker2 != null)
{
this.col1.Color = this.c1ColorPicker1.SelectedColor;
this.col2.Color = this.c1ColorPicker2.SelectedColor;
}
}
6. Add code to the C1ColorPicker1_SelectedColorChanged event handler so that it appears like the following:
Private Sub C1ColorPicker1_SelectedColorChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles C1ColorPicker1.SelectedColorChanged
UpdateGradient()
End Sub
•C#
private void c1ColorPicker1_SelectedColorChanged(object sender, C1.WPF.PropertyChangedEventArgs<System.Windows.Media.Color> e)
{
UpdateGradient();
}
7. Return to Design view.
8. Click once on the second C1ColorPicker control (C1ColorPicker2) to select it.
9. In the Properties window, double-click in the text box next to the SelectedColorChanged event to switch to Code view and create the event handler (you may need to click the lightning bolt Events icon to view control events if events are not listed).
10. Add code to the C1ColorPicker_SelectedColorChanged event handler so that it appears like the following:
Private Sub C1ColorPicker2_SelectedColorChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles c1cp1.SelectedColorChanged
UpdateGradient()
End Sub
•C#
private void c1ColorPicker2_SelectedColorChanged(object sender, C1.WPF.PropertyChangedEventArgs<System.Windows.Media.Color> e)
{
UpdateGradient();
}
In this step you completed adding code to your application. In the next step you'll run the application and observe run-time interactions.