PiecesProgram Pieces Tutorial: Hello, User! Display

Chapter 4: How to make a program piece display

The most familiar program pieces to the user are those that display in the display area of Mountain Meadow, and can be selected by clicking on its title in the vertical navigation bar. This tutorial shows how to take the simple "Hello, World" program piece made in the previous tutorial and convert it to show a display in the display area when its name is clicked.

Make the program piece that will reference the display

Retrace the steps you took making the HelloWorld project with a new project named HelloUser:

  1. Make a new project, named HelloUser
  2. Add a reference to MM3Common.dll
  3. Add a class named HelloUserProgramPiece
  4. Make HelloUserProgramPiece inherit from ProgramPieceBase
  5. Add the using MM3Common; statement at the top of the code for the class HelloUserProgramPiece:

{short description of image}

We will come back to this class later to make it reference our display after we create it.

The additional steps you will take to make a display so show in the program's main form are:

  1. Make a User Control (i.e. just a Windows control that is custom-made) to display
  2. Make a method in the User Control (called LoadData() ) that will do some work, like say hello.
  3. Make the program piece instantiate the User Control, passing a reference of itself in the constructor.
  4. Override the OnCallBeforeShow() method in the program piece to call the LoadData() method in the User Control.

Make the display

Add a new User Control to the project and call it "HelloUserDisplay"

{short description of image}

Add a new class to the project, called "HelloUser" (the program adds the .cs suffix)

Resize the user control to 706,514 to fit in the display space (when in the default 800x600 main form size)

Drag a panel onto the surface, and set its Dock property to Fill.

Drag a label onto its surface. You should have something like this:

{short description of image}

Give it something to do

The beauty of program pieces is that they have access to the database and to the program state information through the objects MM3Data and MM3State. For example, we can access the name of the current user through MM3State. To do this we make a constructor for our new user control that requests a reference to the Program Piece that calls it.

Right click on the surface of the user control and choose View Code.

add the line using MM3;

create a local variable for the program piece reference and create a constructor for the user control as shown:

{short description of image}

We'll make a method called LoadData() to make the connection to the database and display the user's name on the label control. Notice the intellisence type-ahead feature of Microsoft Visual Studio works as you type in this code because of the reference made to MM3Common where those types are declared.

The code looks like this now:

{short description of image}

Attach the display to the program piece class

Now go back to the HelloUserProgramPiece class we made at first. We will override a couple of the methods of ProgramPieceBase in order to specify how we want to call our piece (name,color, etc in the vertical navigation bar, and what display to show when called) and to actually call a method in our display piece.

Type in the following code:

(note the lines for description, LabelSuggested, etc are optional and are just suggestions to the Administrator for what properties to give the program piece when plugging it in to the program. They can be left out. The important line is 'display=new HelloUserDisplay(this)'

{short description of image}

That should do it

Plug in the piece

Run the programs Administrator's console (described elsewhere) to plug in your newly created piece.

Then when you run Mountain Meadow, it should work like this:

{short description of image}

Finally: the Plugin Interface: PPInterface.htm