Click here to Skip to main content
16,003,953 members
Home / Discussions / C#
   

C#

 
GeneralRe: Forcing repainting the cell Pin
Christian Graus21-Aug-06 23:31
protectorChristian Graus21-Aug-06 23:31 
GeneralRe: Forcing repainting the cell Pin
e_LA21-Aug-06 23:34
e_LA21-Aug-06 23:34 
QuestionMigration Problem Pin
Ravikumar Patra21-Aug-06 21:01
professionalRavikumar Patra21-Aug-06 21:01 
AnswerRe: Migration Problem Pin
Ed.Poore21-Aug-06 23:01
Ed.Poore21-Aug-06 23:01 
QuestionIn C#, how should I use a VB ocx that is dependent on a win32 dll ? Pin
TinyTin21-Aug-06 20:59
TinyTin21-Aug-06 20:59 
AnswerRe: In C#, how should I use a VB ocx that is dependent on a win32 dll ? Pin
Ed.Poore21-Aug-06 22:52
Ed.Poore21-Aug-06 22:52 
Questionregistry handling Pin
Mostafa Siraj21-Aug-06 20:52
Mostafa Siraj21-Aug-06 20:52 
AnswerRe: registry handling Pin
JacquesDP21-Aug-06 22:44
JacquesDP21-Aug-06 22:44 
This piece of code helped me alot, hope it'll work for you.

/* ***************************************
* ModifyRegistry.cs
* ---------------------------------------
* a very simple class
* to read, write, delete and count
* registry values with C#
* ---------------------------------------
* if you improve this code
* please email me your improvement!
* ---------------------------------------
* by Francesco Natali
* - fn.varie@libero.it -
* ***************************************/

using System;
// it's required for reading/writing into the registry:
using Microsoft.Win32;
// and for the MessageBox function:
using System.Windows.Forms;

namespace Utility.ModifyRegistry
{
/// <summary>
/// An useful class to read/write/delete/count registry keys
/// </summary>
public class ModifyRegistry
{
private bool showError = false;
/// <summary>
/// A property to show or hide error messages
/// (default = false)
/// </summary>
public bool ShowError
{
get { return showError; }
set { showError = value; }
}

private string subKey = "SOFTWARE\\" + Application.ProductName.ToUpper();
/// <summary>
/// A property to set the SubKey value
/// (default = "SOFTWARE\\" + Application.ProductName.ToUpper())
/// </summary>
public string SubKey
{
get { return subKey; }
set { subKey = value; }
}

private RegistryKey baseRegistryKey = Registry.LocalMachine;
/// <summary>
/// A property to set the BaseRegistryKey value.
/// (default = Registry.LocalMachine)
/// </summary>
public RegistryKey BaseRegistryKey
{
get { return baseRegistryKey; }
set { baseRegistryKey = value; }
}

/* **************************************************************************
* **************************************************************************/

/// <summary>
/// To read a registry key.
/// input: KeyName (string)
/// output: value (string)
/// </summary>
public string Read(string KeyName)
{
// Opening the registry key
RegistryKey rk = baseRegistryKey ;
// Open a subKey as read-only
RegistryKey sk1 = rk.OpenSubKey(subKey);
// If the RegistrySubKey doesn't exist -> (null)
if ( sk1 == null )
{
return null;
}
else
{
try
{
// If the RegistryKey exists I get its value
// or null is returned.
return (string)sk1.GetValue(KeyName.ToUpper());
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Reading registry " + KeyName.ToUpper());
return null;
}
}
}

/* **************************************************************************
* **************************************************************************/

/// <summary>
/// To write into a registry key.
/// input: KeyName (string) , Value (object)
/// output: true or false
/// </summary>
public bool Write(string KeyName, object Value)
{
try
{
// Setting
RegistryKey rk = baseRegistryKey ;
// I have to use CreateSubKey
// (create or open it if already exits),
// 'cause OpenSubKey open a subKey as read-only
RegistryKey sk1 = rk.CreateSubKey(subKey);
// Save the value
sk1.SetValue(KeyName.ToUpper(), Value);

return true;
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Writing registry " + KeyName.ToUpper());
return false;
}
}

/* **************************************************************************
* **************************************************************************/

/// <summary>
/// To delete a registry key.
/// input: KeyName (string)
/// output: true or false
/// </summary>
public bool DeleteKey(string KeyName)
{
try
{
// Setting
RegistryKey rk = baseRegistryKey ;
RegistryKey sk1 = rk.CreateSubKey(subKey);
// If the RegistrySubKey doesn't exists -> (true)
if ( sk1 == null )
return true;
else
sk1.DeleteValue(KeyName);

return true;
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Deleting SubKey " + subKey);
return false;
}
}

/* **************************************************************************
* **************************************************************************/

/// <summary>
/// To delete a sub key and any child.
/// input: void
/// output: true or false
/// </summary>
public bool DeleteSubKeyTree()
{
try
{
// Setting
RegistryKey rk = baseRegistryKey ;
RegistryKey sk1 = rk.OpenSubKey(subKey);
// If the RegistryKey exists, I delete it
if ( sk1 != null )
rk.DeleteSubKeyTree(subKey);

return true;
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Deleting SubKey " + subKey);
return false;
}
}

/* **************************************************************************
* **************************************************************************/

/// <summary>
/// Retrive the count of subkeys at the current key.
/// input: void
/// output: number of subkeys
/// </summary>
public int SubKeyCount()
{
try
{
// Setting
RegistryKey rk = baseRegistryKey ;
RegistryKey sk1 = rk.OpenSubKey(subKey);
// If the RegistryKey exists...
if ( sk1 != null )
return sk1.SubKeyCount;
else
return 0;
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Retriving subkeys of " + subKey);
return 0;
}
}

/* **************************************************************************
* **************************************************************************/

/// <summary>
/// Retrive the count of values in the key.
/// input: void
/// output: number of keys
/// </summary>
public int ValueCount()
{
try
{
// Setting
RegistryKey rk = baseRegistryKey ;
RegistryKey sk1 = rk.OpenSubKey(subKey);
// If the RegistryKey exists...
if ( sk1 != null )
return sk1.ValueCount;
else
return 0;
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
ShowErrorMessage(e, "Retriving keys of " + subKey);
return 0;
}
}

/* **************************************************************************
* **************************************************************************/

private void ShowErrorMessage(Exception e, string Title)
{
if (showError == true)
MessageBox.Show(e.Message,
Title
,MessageBoxButtons.OK
,MessageBoxIcon.Error);
}
}
}

He who laughs last is a bit on the slow side
QuestionApplication.CurrentCulture Pin
M Riaz Bashir21-Aug-06 20:36
M Riaz Bashir21-Aug-06 20:36 
AnswerRe: Application.CurrentCulture Pin
Andrei Ungureanu21-Aug-06 21:02
Andrei Ungureanu21-Aug-06 21:02 
QuestionHow to Extend Datagrid Pin
sanah s21-Aug-06 19:16
sanah s21-Aug-06 19:16 
QuestionDataGrid control scrolls unexpectedly when you use the arrow keys to move (Visual Studio .NET 2003) [modified] Pin
Kiterq21-Aug-06 18:08
Kiterq21-Aug-06 18:08 
QuestionArrayList & Sub ArrayList Import CSV? Pin
gman4421-Aug-06 17:15
gman4421-Aug-06 17:15 
AnswerRe: ArrayList & Sub ArrayList Import CSV? Pin
leppie21-Aug-06 17:54
leppie21-Aug-06 17:54 
Questionerror 80040154 at instantiation of COM object Pin
mkrelli21-Aug-06 13:21
mkrelli21-Aug-06 13:21 
AnswerRe: error 80040154 at instantiation of COM object Pin
mav.northwind21-Aug-06 23:30
mav.northwind21-Aug-06 23:30 
GeneralRe: error 80040154 at instantiation of COM object Pin
mkrelli25-Aug-06 14:03
mkrelli25-Aug-06 14:03 
QuestionThe ConnectionString property has not been initialized ! Pin
mostafa_h21-Aug-06 13:11
mostafa_h21-Aug-06 13:11 
AnswerRe: The ConnectionString property has not been initialized ! Pin
Nader Elshehabi21-Aug-06 13:21
Nader Elshehabi21-Aug-06 13:21 
GeneralRe: The ConnectionString property has not been initialized ! Pin
mostafa_h21-Aug-06 13:32
mostafa_h21-Aug-06 13:32 
GeneralRe: The ConnectionString property has not been initialized ! Pin
Steve :)21-Aug-06 14:36
Steve :)21-Aug-06 14:36 
GeneralRe: The ConnectionString property has not been initialized ! Pin
mostafa_h21-Aug-06 20:26
mostafa_h21-Aug-06 20:26 
GeneralRe: The ConnectionString property has not been initialized ! Pin
Nader Elshehabi22-Aug-06 3:47
Nader Elshehabi22-Aug-06 3:47 
GeneralRe: The ConnectionString property has not been initialized ! Pin
Steve :)22-Aug-06 12:42
Steve :)22-Aug-06 12:42 
AnswerRe: The ConnectionString property has not been initialized ! Pin
Coding C#21-Aug-06 20:26
Coding C#21-Aug-06 20:26 

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.