Click here to Skip to main content
13,090,426 members (51,483 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 22 Apr 2011

Simple class to save your Form's Size To Registry

, 22 Apr 2011
Rate this:
Please Sign up or sign in to vote.
Simple class to save your Form's Size To Registry
using System;
using System.Windows.Forms;
using Microsoft.Win32;
namespace Chico.Registry
    public class SizeRegistry
        private RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default);
        private RegistryKey mKey;
        public SizeRegistry(string subkey)
            mKey = key.CreateSubKey(subkey, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryOptions.Volatile);
            key.Close(); key.Dispose();
        public void GetSize(out int width, out int height)
            width = (int)mKey.GetValue("FormWidth",320);
            height = (int)mKey.GetValue("FormHeight", 240);           
        public void SetSize(int FormWidth, int FormHeight)
            mKey.SetValue("FormWidth", FormWidth, RegistryValueKind.DWord);
            mKey.SetValue("FormHeight", FormHeight, RegistryValueKind.DWord);            
        public void Close()

Here is an example of using this class:

using System;
using System.Drawing;
using System.Windows.Forms;
using Chico.Registry;
namespace WindowsFormsApplication1
    public partial class Form1 : Form
       SizeRegistry key = new SizeRegistry(Application.ProductName);
        int width, height;
        public Form1()
            key.GetSize(out width, out height);
            this.Size = new Size(width, height);            
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            key.SetSize(this.Width, this.Height);


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

charles henington
United States United States
I do not claim to be wrong! I just rarely ever write.

You may also be interested in...

Comments and Discussions

GeneralWhat about forms other than the application form? Pin
Marc Clifton22-Apr-11 17:52
protectorMarc Clifton22-Apr-11 17:52 
GeneralRe: What about forms other than the application form? Pin
charles henington2-May-11 2:06
membercharles henington2-May-11 2:06 
General[My vote of 2] My thoughts... Pin
kornman0022-Apr-11 7:25
memberkornman0022-Apr-11 7:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 22 Apr 2011
Article Copyright 2011 by charles henington
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid