Exercise 2: Create Dialog Box

From AutoCount Resource Center
Jump to navigation Jump to search
Objectives: Create an “About” Dialog Box to display information of this plug-in. 
This exercise shows the steps to create Dialog Box using Class Attributes.

1. Open the Plug-in project “Tutorial.PRG201” from Exercise 1.

2. Amend the plug-in version to “1.0.2”

3. Right-Click on “Tutorial.PRG201” (Project),

  • Select -> Add | Windows Forms…

4. Type the form name as “FormAbout.cs”

201a.AboutDialogBox.png

5. Edit the Form Text

[Properties]
Text = "About"

6. Add a Label onto FormAbout at Form Design

[Properties]
(Name) = lblAbout
Text = "Plug-in Tutorial : Getting Started version 1.0.2"

7. Add a button

[Properties]
(Name) = btnOK
Text = &OK

8. Make “About” form appear at the menu.

  • Declare the attribute class, using BCE.AutoCount.PlugIn.MenuItem
  • Define 1 parameter, and 3 optional parameters
    1. Menu Caption = "About"
    2. BeginNewGroup = true
      (Draw a line one top of this menu)
    3. MenuOrder = 99
      (Set this menu item at bottom)
    4. ShowAsDialog = true
      (Form will not be maximized)

9. Constructor of MenuItem requires one argument

Insert “BCE.Data.DBSetting dbSetting” in the constructor.

201a.Code.MenuItem.8.png

[BCE.AutoCount.PlugIn.MenuItem("About", BeginNewGroup = true, MenuOrder = 99, ShowAsDialog = true)]
public partial class FormAbout : Form
{
    public FormAbout(BCE.Data.DBSetting dbSetting)
    {
        InitializeComponent();
    }
}

10. Add below statements into the constructor, which changes FormAbout properties.

11. Add Button [OK] event

  • At the “FormAbout” Design, double clicks the button [OK].
  • Insert “Close()” in the click event.

201a.Code.FormProperties.10.png

public FormAbout(BCE.Data.DBSetting dbSetting)
{
    InitializeComponent();

    StartPosition   = FormStartPosition.CenterScreen;
    FormBorderStyle = FormBorderStyle.FixedDialog;
    MaximizeBox = false;
    MinimizeBox = false;
}

private void btnOK_Click(object sender, EventArgs e)
{
    Close();
}



201a.AboutDialogComplete.png

See Also

Go to menu

IconAC81.png Go to top
ProgrammerGo.jpg Resources For AutoCount Software Developers