ComponentOne Windows 7 Control Pack for WinForms
Windows 7 Control Pack for WinForms Quick Starts / C1TaskDialog Quick Start / Step 3 of 4: Adding Code to the C1TaskDialog Application
In This Topic
    Step 3 of 4: Adding Code to the C1TaskDialog Application
    In This Topic

    In the last step you created a new application and added Button and C1TaskDialog controls. You also customized the appearance and behavior of the C1TaskDialog control. In this step you'll add code to complete an action when the Command Link buttons are click and to open the dialog box when the button on the form is clicked at run time.

    Complete the following steps:

    1. In Design view, double-click the Button control to switch open the Code Editor and create the Button_Click event handler.
    2. Add code to the Button_Click event handler so that the dialog box will open when the button is clicked; the event handler will appear similar to the following:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Me.C1TaskDialog1.Show()
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void button1_Click(object sender, EventArgs e)
      {
          this.c1TaskDialog1.Show();
      }
      
    3. Return to Design view and select the C1TaskDialog control.
    4. Navigate to the Properties window and select the lightning bolt Events button to view the C1TaskDialog control's events.
    5. Double-click the ButtonClick event to create a new event handler and return to Code view.
    6. Add code to the ButtonClick event handler so that click each Command Link navigates to a Web site; the event handler will appear similar to the following:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub C1TaskDialog1_ButtonClick(ByVal sender As System.Object, ByVal e As C1.Win.C1Win7Pack.TaskDialogButtonClickEventArgs) Handles C1TaskDialog1.ButtonClick
          If e.DialogResult = TaskDialogResult.[Custom] Then
              Select Case e.CustomButton.Name
                  Case "Button1"
                      System.Diagnostics.Process.Start("https://www.grapecity.com/en/docs")
                      e.Cancel = True
                      Exit Select
                  Case "Button2"
                      System.Diagnostics.Process.Start("https://www.grapecity.com/en/forums")
                      e.Cancel = True
                      Exit Select
                  Case "Button3"
                      System.Diagnostics.Process.Start("https://www.grapecity.com/en/support/contact")
                      Exit Select
                      e.Cancel = True
              End Select
          End If
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void c1TaskDialog1_ButtonClick(object sender, TaskDialogButtonClickEventArgs e)
      {
          if (e.DialogResult == TaskDialogResult.Custom)
          {
              switch (e.CustomButton.Name)
              {
                  case "Button1":
                      System.Diagnostics.Process.Start("https://www.grapecity.com/en/docs");
                      e.Cancel = true;
                      break;
                  case "Button2":
                      System.Diagnostics.Process.Start("https://www.grapecity.com/en/forums");
                      e.Cancel = true;
                      break;
                  case "Button3":
                     System.Diagnostics.Process.Start("https://www.grapecity.com/en/support/contact");
                     break;
                     e.Cancel = true;
              }
          }
      }
      

    What You've Accomplished

    In this step you added code to your application to customized and initialized the C1TaskDialog control. In the next step you'll run the application to view some of the possible run-time interactions.