How to use Windows Registry in C#

This article is about using Windows Registry functions in C#.Net application. Today I learned some basic functions of registry in Visual Programming Lab. In this example we will learn how to store a value in registry. This example will save the current Height & Width of windows form at Form1_FormClosing event.


First of all we have to add using Microsoft.Win32; in our assemblies because we are using Registry Class of Microsoft.

Creating Event :

Now this is form closing Event’s Method. You can create it using Events table in properties windows.

Click on Events in properties window

Double click on Form Closing option in Events Window & Automatically Form1_FormClosing Method will be created.

Code for Form1 Closing method.

How to See Stored Values in Registry :

Go to Run & write “RegEdit” & press OK.

Press OK & Registry Window will be Opened.

You can see the values of Height & width stored in Registry.

Output :

Here is the output video where I am using Windows Registry for saving Form’s size at closing event & then looking up the size from registry at loading event.

Click on the image below to play Video