How to use Windows Registry in C#

Sajjad Arif Gul - January 3, 2016 - 0 comments

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

Author avatar

Sajjad Arif Gul
Hi! I am Sajjad Arif Gul, Software Engineer, Web & Mobile Developer from Karachi Pakistan. I love sharing my knowledge that could possibly help someone’s life in some capacity. Happy Coding.

Related posts

Post a Comment

Your email address will not be published. Required fields are marked *