|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionA common need for Windows forms is to remember the last position, size and state of the form. One way to do this is to call a function when your form loads and closes. I decided to do it the Object Oriented way. If your form inherits this class, it will automatically load and save the the form settings; Left, Top, Height, Width, and State; to a .config file. Using the codeTo use this class in a C# project
That's it! When the form is loaded, the saved values are set to the form. When the form is closed, the settings are saved. To use this class in a VB.NET project
Inherits System.Windows.Forms.Form
to: Inherits PersistentForm
That's it! When the form is loaded, the saved values are set to the form. When the form is closed, the settings are saved. OverviewThis class is very straightforward. It simply inherits the
public class PersistentForm : System.Windows.Forms.Form
{
public PersistentForm()
{
}
protected override void OnCreateControl()
{
LoadSettings(); // Load the saved settings from the file
base.OnCreateControl ();
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
SaveSettings(); // Save the settings to the file
base.OnClosing(e);
}
}
History
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||