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.