Pages

Ads 468x60px

Monday, April 29, 2013

Visual Studio 2012 Keeps Crashing All The Time

The Problem:
I recently decided to upgrade to VS 2012 on a Windows 7 machine. Well, it seemed like anytime I did something, it would crash. For example in C#, expanding the toolbox would crash it, and so would double-clicking, say, a button to get to the click even handler. Furthermore I couldn't compile either. Basically  VS 2012 was worthless.


The Solution:
I re-installed but to no avail. I updated, and still no luck. Finally all that was left was the .NET Framework. I noticed it had installed 4.5 but in turn windows features on an off, only 3.5 was listed.
--------------
I uninstalled the .NET Framework 4.5, and then 4.0. Then I installed 4 and 4.5. Worked great.

What Caused it?
Possibly because I had Visual Studio 2010 installed too, but that's just a guess.

Sunday, January 6, 2013

How to center a form in the screen that currently holds the cursor.


Hi all! Ever needed a way to center a form in the display that currently harbors the mouse pointer? With the below code and my class, which you can download here, this is very easy. All my code does is take a Point and return the index number of the Screen.AllScreens element that contains the point. You could do many things with this class, and the below is just one of many. The below code will center the form on loading, to the screen the mouse pointer is in. In this way if the user has a multi-monitor system and double clicks the program shortcut icon, the program will start in the screen where the icon resides.

private void Form1_Load(object sender, EventArgs e)

        {

          

            Point location = new Point();

            int CurrentScreencall = CurrentScreencall.CurrentScreenOfPointer(MousePosition);

            location.X = (Screen.AllScreens[CurrentScreencall].Bounds.Width - this.Width)/2;

            location.X = (Screen.AllScreens[CurrentScreencall].Bounds.Height - this.Height) / 2;

            location.Offset(Screen.AllScreens[CurrentScreencall].Bounds.Location);





            this.Location = location;

        }


If you guys have any questions leave comments! Hope this helps someone! :)


Sunday, December 30, 2012

How to keep your cursor from slipping into your second monitor.

It seems as if Microsoft does not take multi-monitor support too seriously. With their new OS (Windows 8) they have added some additional multi-monitor features, but still did not address the common problem of the cursor slipping into your second screen so easily. With the addition of "charms" in Windows 8 the need to limit your cursor to the boundaries of a specific screen is essential because charms are only activated when your pointer is within just a few pixels of the edge of the display.

The solution to this problem can be found through Mouse Trapper, which I developed.  Mouse Trapper is a program that prevents the cursor from slipping into another display in a multi-monitor setup by requiring a hotkey to be pressed in order to allow the pointer to pass into another screen. After which, the pointer is trapped in that display until the hotkey is pressed again.  The interface is very simple and self explanatory. 

A new an enhanced version has just been released, featuring the ability to select which monitors have slipping protection, and a wonderful cursor locator. You can find all the details about Mouse Trapper and then newest version here.

Mouse Trapper has been featured on several sites, including CNET:

http://download.cnet.com/Mouse-Trapper/3000-2317_4-75878300.html?tag=rb_content;contentBody

And others:

http://operating-systems.wonderhowto.com/how-to/use-hot-corners-more-easily-dual-monitor-windows-8-setup-using-mouse-trapper-0140289/

http://www.softepic.com/windows/system-utilities/system-miscellaneous/mouse-trapper/

http://www.soft82.com/download/windows/mouse-trapper/

http://www.addictivetips.com/windows-tips/stop-mouse-cursor-from-slipping-to-secondary-monitor-in-windows-8/ 











Thursday, August 16, 2012

ProgressBar not Updating Fix - C#

It has been sited by many StackOverflow questions that, usually when using a BackgroundWorker, your ProgressBar will not update correctly when using C#. I do not know why this happens, however some people suggest that it is because of the threaded interface in Windows Vista and Windows 7.The ProgressBar would get to about 75% full when it should have been at its maximum, and would revert back to 0% before it was fully drawn. Here is what that looked like:

And this is the example code I used:
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            for (int i = 1; (i <= 100); i++)
            {
                    // Perform a time consuming operation and report progress.
                    System.Threading.Thread.Sleep(20);
                    backgroundWorker1.ReportProgress((i ));
            }
        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
            if (progressBar1.Maximum == e.ProgressPercentage)
                progressBar1.Value = 0;
        }

However, Mark Lansdown from StackOverflow found a very useful solution, taken from this question.

What he suggested is to draw the value, then draw the value minus 1, because that would force a redraw on the ProgressBar. To to that, I just changed my ProgressChanged event to:

private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
            if (e.ProgressPercentage != 0)
                progressBar1.Value = e.ProgressPercentage - 1;
            progressBar1.Value = e.ProgressPercentage;
            if (progressBar1.Maximum == e.ProgressPercentage)
                progressBar1.Value = 0;
        }

And the result is that the ProgressBar will now be smoothly redrawn to 100% before it is reverted.

And while this is most certainly strange behavior, I can verify that it works, and now the ProgressBar will fill all the way up.

I hope you enjoyed!

Center A Form to another form in C#

Recently, while I was using C#, I had an issue. I wanted to center a form in the middle of another form. After drawing a chart and doing some math, I have come up with this piece of code:

form2.SetDesktopLocation(form1.Location.X + ((form1.Width / 2) - form2.Width / 2), form1.Location.Y + ((form1.Height / 2) - form2.Height / 2));
What this code actually does, is it first gets the location of form1 X. It then adds that to form1 Width / 2, and subtracts that from form2's width / 2, and does the same for Y. It does that, because you get the X position, and that position needs to be in the center of form1's width. Then, you need to factor in half of form2's width per side, because form1's width was divided by 2. Don't worry if you do not understand. This code assumes the form you want to center is form2, and the form you want to center it around is form1. You have to create a variable for the current instance of form1 and form2. Here is an example of that:

Form1 form1 = (Form1)Application.OpenForms[0];
What this code does, is it gets a current array of the open forms. If form2 is your child form, and form 1 is your main form, form1 would be position [0] and form2 would be position [1].

Here is a picture of this:



I hope it helps!