Reading and writing values in the registry is the same regardless of the format. In the case of REG_BINARY the returned object is of type byte. The following code would convert that to a string. You would reverse the process to write it back.
RegistryKey regKey3 = Registry.CurrentUser;
RegistryKey regSub3 = regKey3.OpenSubKey("Software or whatever");
byte ans = (byte)regSub3.GetValue("Value I need");
string sString = System.Text.Encoding.ASCII.GetString(ans);
string  sArray = sString.Split('\0');
sString = "";
foreach (string s in sArray)
sString += s;
Now sString should have your string from the reg_binary ready for processing.
private int RandomNumber(int min, int max)
Random random = new Random();
return random.Next(min, max);
and i am clalling this method in for loop. my expectation is for every iteration in the loop i am expecting some new random number. code for that is like below:
Don't instantiate a new Random every time. Treat random as a singleton.
Random will (by design) give you the same sequence of numbers every time unless you start with a different seed. Right now you are getting the first number of the sequence every time.
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
The default constructor for the Random class uses the system clock to seed the random number generator. Your code is running fast enough that the system clock has not changed between calls to the constructor, resulting in the same random numbers being generated each iteration. See the MSDN documentation for the Random constructor[^] for more clarification and a good example.
it is very easy to detect if someone work with mouse move event of picturebox. but i want to detect mouse over picturebox in mouse move event of the form so first i did set the keypreview property of form to true and then i wrote the code in mouse move event of form.
so my code is ---
private void Form1_MouseMove(object sender, MouseEventArgs e)
if ((X >= pic.Left && X <= pic.Left + pic.Width) && (Y >= pic.Top && Y <= pic.Top + pic.Height))
lblMsg.Text = "Mouse over picturebox";
lblMsg.Text = "";
this code is not working. where i am making the mistake. please rectify me.
lblMsg.Text = "Mouse over picturebox";
lblMsg.Text = pic.Bounds.ToString() + ":" + e.Location.ToString();
You will see what the problem is:
The location only changes when the mouse is not over any control, and never becomes "Mouse over picturebox".
This is because the individual controls are expected to handle their own events, so they get the mouse move events instead of the form.
As stancrm said: handle it in the PictureBox MouseMove event instead.
Oh, and it is much easier to read if you use the Rectangle.Contains method, rather than write it in longhand - and less prone to errors too!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
I have an XMLDocuemt supplied by a 3rd party. I have an xpath expression checking for value for element "x". The problem is sometimes element "x" does not exist and im getting a error "bject reference not set to an instance of an Object".
How do i check if element x (using xpath) exist
Hi, I have an asp.net web application, I have read/write a word file with the help of openxml sdk. Now I need to convert that word file to a pdf format. Is there anyway to convert word file to pdf with the openxml sdk ?
Ok Guys I'm facing a strange problem here, and I dunno if its a bug or I am doing something wrong.
Here's the code:
privatestaticvoid Main(string args)
var webClient = new WebClient();
//var progressBar = new ProgressBar();
webClient.DownloadProgressChanged += (o, e) => Debug.WriteLine(e.ProgressPercentage);
webClient.DownloadFileCompleted += (o, e) => Debug.WriteLine("Download completed.");
webClient.DownloadFileAsync(new Uri("http://cdimage.debian.org/debian-cd/5.0.4/i386/iso-cd/debian-504-i386-netinst.iso"), "debian-504-i386-netinst.iso");
Everything works fine like this, events are raised normally.
Now try to uncomment the progressbar initialization and events will stop to be fired (I noticed the problem with the progress bar because I needed to add a progress bar dynamically to the form, dunno if there are other scenarios where this happens) even if the download proceeds normally.
Maybe is just me or maybe I have convinced myself this code is right that I cant no longer see where I epic fail.
Anyone having the same problem?