DataGridView Flickering When Changing Background Colour

Date August 4th, 2010 Comment No Comments

Since implementing crossfading of tracks in Karaokidex, I’ve indicated the crossfading by gradually fading out the background colour of the first track’s row in the playlist DataGridView and fading in the background colour of the second track’s row. This caused a really annoying flickering.

The problem is the DataGridView is not double-buffered by default, nor is there any visible property on the DataGridView object to set it as double-buffered.

Google to the rescue!

Thanks to the guys at StackOverflow.com for this elegant solution that uses reflection rather than defining a custom class.

typeof(DataGridView).InvokeMember(
   "DoubleBuffered",
   BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty,
   null,
   myDataGridViewObject,
   new object[] { true });

[Via: stackoverflow]

Tags: , , , ,

BBC BullyProof Campaign

Launching Single-Instance ClickOnce Apps From File Association

Date August 2nd, 2010 Comment No Comments

Since Service Pack 1 of Visual Studio 2008, setting file associations has never been easier. The publish options dialog has four pages; once of which is the “File Associations” page. After one or more entries has been added, and the app published, the ClickOnce app will now be launched whenever an associated file is opened from explorer.

This is fine, unless you only want one instance of your app to be running at any one time. Each time an associated file is opened, a new instance of the ClickOnce app will be launched. If your single-instance app is open and you try to open an associated file, the reference to the file will be lost when the new instance detects that the original instance is running and terminates. Grrr.

However, you can get round this. After detecting that there is another instance of your app running, simply pass the file reference to the original instance before closing.

Note the callback is made using an IpcChannel rather than a TcpChannel. If a TcpChannel is specified, Vista and Windows 7 will require permission from the user to allow communication through the firewall.

Here is the code:

            // Single instance checked
            bool IsFirstInstance;
            Mutex theMutex =
                new Mutex(false, "Local\\" + Application.ProductName, out IsFirstInstance);
            string[] theActivationData =
                AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;

            if (IsFirstInstance)
            {
                IpcChannel theChannel =
                    new IpcChannel(Application.ProductName);

                try
                {
                    ChannelServices.RegisterChannel(theChannel, false);
                    RemotingServices.Marshal(this._MainView, "MainView");

                    this.MainView_Show();

                    this.ConsumeLaunchParameters(theActivationData);

                    Application.Run(this._AppContext);
                }
                catch (SocketException) { }
                finally
                {
                    ChannelServices.UnregisterChannel(theChannel);
                }
            }
            else
            {
                if (null != theActivationData &&
                    theActivationData.Length > 0)
                {
                    try
                    {
                        MainView theOriginalMainView =
                            (MainView)RemotingServices.Connect(
                                typeof(MainView),
                                "ipc://" + Application.ProductName + "/MainView");

                        theOriginalMainView.ConsumeArguments(theActivationData);
                    }
                    catch (SocketException) { }
                }
            }

            theMutex.Close();
            Application.Exit();

Since my app uses a centralised controller system, I had to add the following code to the MainView form to pass the arguments back to the controller:

        public void ConsumeArguments(
            string[] theArguments)
        {
            // Note that it is not allowed for non-UI thread to access
            // controls on the form, instead, we should use the Invoke method of the form
            // to execute a delegate on the UI thread that own's the control's underlying
            // windows handle.
            if (this.InvokeRequired)
            {
                this.Invoke(
                    new MethodCallback(ConsumeArguments),
                    new object[]
                        { theArguments });

                return;
            }
            else
            {
                if (null != this.ArgumentsConsumed)
                {
                    this.ArgumentsConsumed(theArguments);
                }
            }
        }

        public event MethodCallback ArgumentsConsumed;

        public delegate void MethodCallback(string[] args);

Tags: , , , ,

Removing The Need For UACLauncher

Date August 2nd, 2010 Comment No Comments

Up ’til now, when I’ve been developing and ClickOnce application, I’ve had to include a UACLauncher as a default option to support any user that is not the administrator on their own machine.

UACLauncher

The console app has elevated privileges that are passed on to the re-launched ClickOnce app.

If I didn’t include this, the application would fail with (what I assumed was the first of many permissions errors) a registry access error. I decided to remove the UACLauncher and debug each error as it occurred. All my ClickOnce applications that require registry access to store settings store them in the LocalMachine hive. After googling the registry permission error, the main suggestion that came back was to move the settings to the CurrentUser hive.

Fair enough, but upon publishing the new version, there were no more errors. It seems that the only thing the app was doing that required administrator-level access was to attempt to write to the LocalMachine hive of the registry.

Tags: , , , ,

Hosting Transferred

Date May 27th, 2010 Comment No Comments

I’ve just completed the transfer of all the websites I host to NearlyFreeSpeech.NET.

For as little as $0.25, you can set up web sites at NearlyFreeSpeech.NET, the original home of only pay for what you use hosting.

This is the penultimate service that this server provides as I have already transferred email to Google Mail and ClickOnce hosting to Dropbox.com.

I believe this is better for the long term. I was thinking of decommissioning the server anyway, as the last service it provides is media server that works with my XBOX360. For this purpose, I am now looking at the LaCie Network Space MAX 4Tb.

Tags: , , , , ,

Dropbox.com for ClickOnce

Date May 7th, 2010 Comment 2 Comments

I’ve recently been using Dropbox.com to keep my files in sync between home and work. I’ve also been on the hunt for a (free) site to host ClickOnce deployments.

It was only in a revelation whilst I was in bed last night that I wondered if I could use Dropbox’s Public directory as the target to publish my files.

It works! Here’s how…

  1. Install the Dropbox client,
  2. Once installed, navigate to the Public sub-directory in whichever directory you assigned as the Dropbox directory,
  3. Right-click on the “How to use the Public folder.rtf” file,
  4. In the Dropbox menu item, click “Copy Public Link”,
  5. Paste it into any notepad application,
  6. In Visual Studio, in the Publish tab of your project’s properties, use the following information (substituting your own locations as required):
    • Publishing Folder Location: C:\My Documents\My Dropbox\Public\Project1\
    • Installation Folder Location: http://dl.dropbox.com/u/xxxxxx/Project1/ (Paste the link from step 4, removing the How to use the Public folder.rtf portion and adding the project directory)
    • Click the “Updates” button,
    • Update Location: http://dl.dropbox.com/u/xxxxxx/Project1/ (I always do this just to be on the safe side)
  7. Publish
  8. That’s it! The files will sync to the Dropbox servers, and the project is deployed!

Now all you have to give out is the URL to either the http://dl.dropbox.com/u/xxxxxx/Project1/index.html file if you chose to generate one in your publishing options, or http://dl.dropbox.com/u/xxxxxx/Project1/setup.exe directly.

Easy-peasy, lemon-squeezy.

Tags: , , , ,

Alfie's First Birthday Party

Date April 14th, 2010 Comment No Comments

I’ve updated Alfie’s blog with videos from his first birthday party.

Click here to view them.

Tags: ,

Jivin' Jim

Date April 7th, 2010 Comment No Comments

Jivin’ Jim now has his own website, including videos, with a theme customised by yours truly!

Jim, as you may remember, is currently using Karaokidex to run the karaoke parts of his gigs. He asked me to give him a website, so there it is.

Click here to visit.

Tags: , ,

Beautiful

Date February 18th, 2010 Comment No Comments

Tags: , ,

Full Screen Weather

Date February 15th, 2010 Comment No Comments

We’ve always liked Weather Underground for its no-nonsense, real-time weather info. Today they’ve released a new service called Full Screen Weather that mashes up Google Maps with weather data for nothing but maps and up-to-the-minute weather info.

[Via: Lifehacker]

Tags: , , ,

Lego Cubestormer Robot Solves Rubik's Cube in Sub-12 Second Whirlwind

Date February 15th, 2010 Comment No Comments

Robots born with the sole purpose of solving the Rubik’s Cube are nothing new, but we’re pretty sure we haven’t seen one crack the code in under a dozen seconds before.

[Via: engadget]

Tags: , , ,