How to edit the registry's string value using c#?

CS1401
Posted by CS1401 under C# category on | Points: 40 | Views : 2712
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string runKey = "SOFTWARE\\myapp";
Microsoft.Win32.RegistryKey mykey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey,true);
string days = textBox1.Text;
int c = Convert.ToInt32(textBox1.Text);
if (c <= 30)
{
mykey.SetValue("Name", days);
label1.Text = "Added";
}
else
{
textBox1.Text = "Enter < 30 days";
label1.Text = "";
}

}
}
}

Explanation:
If your i/p above 30 only it will accept otherwise show alert.

Comments or Responses

Posted by: T.saravanan on: 7/17/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Kindly post your code inside the code tag.
Posted by: CS1401 on: 7/21/2011 Level:Starter | Status: [Member] | Points: 10
THanks

Login to post response