- Login or register to hide this ad -


From SimonDotException

Jump to: navigation, search


About CommonForms

Why CommonForms?

CommonForms contains a few Windows Forms components which I found myself repeatedly writing into various applications, so I thought, why not put them into one library rather than having multiple variations of them across different applications?

Technical info

CommonForms is a Windows Forms control library written in C# targeting version 2.0 of the .net framework.

The project files in the repository were created using SharpDevelop so users of Visual Studio may find that they can't open them. If this is the case for you, then create a new project in Visual Studio and add each of the source code files to it.

The project files in the repository reference a .snk file which isn't in the repository, and attempting to build them will result in a cryptographic failure because the file is not found. To resolve this, either turn assembly signing off in the project options, or create your own strong name key file if you want to be able to install your build of the assembly in the GAC.

Installing CommonForms

Windows installer

Download and run the installer from the CommonForms project summary page. This will install CommonForms.dll, CommonForms.Example.exe (sample application demonstrating use of the components, CommonForms.NUnit.dll (unit test project) and any dependencies in the Global Assembly Cache. It will also copy these files into the Program Files folder, along with the license and HTML help file and add shortcuts to your start menu.

Build from source

Download the CommonForms project from the SVN browse page, either as a tarball or using your favourite Subversion client.

If you want to build the unit test project from source then you will also need NUnit.Extensions and GetFeedback.

Using CommonForms

For more detailed usage information, see the Sandcastle-built help file installed with the application.

Telling the user about your application

Use the AboutForm, AboutFormParameters and CreditableWork classes to display a dialogue box with information about your application, including its license and the details of any other people's work which you have re-used or created a derived work from.

Handling exceptions

If you have caught an exception and want to tell the user about it, pass it to the ExceptionForm constructor and call the form's ShowDialog method.

CA1300-compliant MessageBox

Microsoft's code analysis tool FxCop demands that if you display a MessageBox, you tell it whether the current control displays text from left to right or right to left. If this property is not set on the current control, you need to check its parent control, and that control's parent control, until you find one where the property is set.

Or you can use a CleverMessageBox which does all this for you.

Keep the application responsive whilst working

Use ResponsiveForm rather than System.Windows.Form as the base type for your form and you can use its StartAsynchronousOperation method to start an instance of a AsynchronousOperation on a separate thread to the UI.

While the operation is running, a ProgressForm will be displayed, containing progress bars and narratives to indicate the progress of the operation and any sub operations, and the user can continue to interact with the form from which the operation was launched. The ProgressForm also includes a Cancel button to allow the user to cancel the operation.

If the user attempts to close the application whilst an operation is running, they will be warned that the operation is still running and asked if they are sure that they want to close the application. If they still choose to, then any running operations will be cancelled.

If the operation throws an unhandled exception, the ResponsiveForm will handle it by displaying an ExceptionForm. If you want to implement additional exception handling, add an event handler to the operation's Failed event.

To pass user input from the UI to the operation whilst it is running, override the UpdateProcessObject method. Likewise, to update the UI with information from the operation whilst it is running, override the UpdateUI method.

To change the frequency with which the operation, progress form and UI are synchronised, set the TimerInterval property.

Personal tools