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?
Oh - and the standard is to use UPPERCASE for SQL keywords.
In every code shop and software house I've been in for over 20 years the standard has always been lower case! Don't want to start an argument, just saying that the real standard is that there are no real standards...