Windows Develop Bookmark and Share   
 index > Windows Forms General > Standardizing base windows and base modal windows
 

Standardizing base windows and base modal windows

 
Hi everyone,
I am trying to streamline the look and feel through out a number of applications, by providing a base window form and a base modal window.

I wanted to share those thoughts with you guys in case someone has some recommendations/suggestion :

A : All base windows can have a logo in the top left corner, and some other basic things in it. I intend to have everyone developing Inherit from that base window.
B : For modal windows, that can be standardized too, with each one having an OK and Cancel button. Any modal window should react to an enter button click (an equivalent of hitting OK), and
An escape button click (Equivalent to a Cancel hit).
Those base windows really have nothing in them, other developers will use them to contain there each individual business logic, I want to manage the basic interaction within them, and overall
application lifecycle ( i.e: Anything you might want to To do when an application load, or on shutdown, now for this I have no examples but I perceive it as an area where I might want to have)
2 : All UI work within a specific area should Inherit from those windows. Now that provides the flexibility when working on the framework level. A manifestation of this
Would be standardizing the message boxes we show to users when in error, as in the message boxes would have a predefined enumeration ( or set ) of icons (: Exclamation, Question Mark), and a
standard collection of strings to display to users when we reach an a specific stage in the application lifecycle. The owners of this framework can have the flexibility of implementing this framework
and asking users to inherit and place all their business logic on it.


thank you guys.

kalamantina  Monday, October 05, 2009 4:15 PM

Hi kalamantina,

It is appreciated that you said a lot about your requirement and ideas. Since there is no exact issue in this thread, I can only provide some ideas as follows:

1.    A base windows form.

If we want to create a base form to encapsulate some common functions, this would be fine. These are some cases:

1)     Add some common properties and methods in the base form. For example, we can add a method to set the cursor to a wait cursor and save the old cursor to indicate that a process which would cost a long time would start. We can also add another method to restore the old cursor to indicate the process ends.

2)    Set some properties of the form to standardize the look and style of all the forms in our application. For example, we can set the back color to green, set font to “Times New Roman, 10” and so on. This would reduce the error to produce inconsistent UI.

3)    Do some custom drawing on the form. We can override the OnPaint or OnPaintBackground method to draw something commonly. For example, we can draw an image on the top left corner.

But it is suggested that we drag and drop some controls on the base form, such as add a OK button on the right bottom corner. It is because if add a child form, we would find the controls added to the base form are locked and cannot be modified in design time. In fact, we suggest use the component model to organize the UI element, but not use inheritance. Of course, if the added controls would not be modified. In other words, we would not modify any properties and hand any events of it in design time, we can add them to the base form on the designer.

Below are the replies of question A and B:
A.  
All base windows can have a logo in the top left corner, and some other basic things in it. I intend to have everyone developing Inherit from that base window.
Reply: We can follow my idea 3 to do that. This is a code snippet:

        protected override void OnPaintBackground(PaintEventArgs e)

        {

            base.OnPaintBackground(e);

            //Draw the image.

            Image img = GetLogoImage();

            e.Graphics.DrawImage(img, new Point(2, 2));

  }

B. For modal windows, that can be standardized too, with each one having an OK and Cancel button. Any modal window should react to an enter button click (an equivalent of hitting OK), and An escape button click (Equivalent to a Cancel hit).
Reply: Based on my understanding, we can follow the steps below to add them:

                     I.        Add a panel on the form at first. Then add OK, Cancel buttons on that panel.

                   II.        Change the Anchor property of the panel to Bottom, Right.

                  III.        Add Click handlers to the buttons and set their access modifier to protected.

The code shows the handlers:

             

protected virtual void button1_Click(object sender, EventArgs e)

              {

                     //Do something here.

              }

       Then In the child form, we can override these handlers to do some custom things:
                  
protected override void button1_Click(object sender, EventArgs e)

{

    base.button1_Click(sender, e);

    //Do some custom things.

    MessageBox.Show("click in the child form");

}

2.    A stand module form, which is mostly used to show an message.
Based on my understanding, we can create a special form to cope with message showing. These are something we need to do:

1)    Create a form and set its access modified to public sealed to  avoid it to be inherited.

2)    Modify some properties to have the form look like a message module form. For example, we can set some properties as follows:
FormBorderStyle: FixedDialog.
MinimizeBox: false.
MaximizeBox: false.
… …

3)    Add a TextBox on the form. Set its Dock property to Top.

4)    Add OK, Cancel buttons on the form like what we discussed before.

The steps above would create the UI of the message form, we also to add some functions to it programmatically. For example, we need to add a ImageList component to the form which contains some icons. We also need to add an enum which refers to the message type. Each item in the enum would be related to an icon in the ImageList. We also need to add some static messages to show a message in different styles. We can take MessageBox class as a reference.

The sample below shows a custom MessageBox in C#. You can get some ideas from its document and sample code.
http://www.codeproject.com/KB/cs/A_Custom_Message_Box.aspx

Regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, October 07, 2009 9:46 AM

You can use google to search for other answers

Custom Search

More Threads

• Add dropdown in a toolstrip runtime
• Updating .sln files with relative paths at runtime or complie time (win forms 2005)
• Outlook Calendar Look and Feel
• Need help on way of storing Data - Any advice would rock.
• Strange VS crash when adding Controls to a form
• Dont know where to keep files to be accesed by app(including mdb, txt, ini files)
• How to specify XML file Path relative to application
• Allow only ONE (1) checked item on CheckedListBox Control
• Removing Cell Highlighting around the cell datagridview
• How to Use List view or a gridview control as a note to treeview control in C# Windows Application