Archive

Archive for the ‘Windows Forms’ Category

Setup App.Config during .msi install, msi re-installing

17 August, 2011 Leave a comment

The Issue

I wrote a windows form application that deployed  via an .msi installer.

The application has an App.Config file which contains a single configuration value. I wanted to prompt the user for this value during the installation wizard and write it to the application.exe.config file as part of the installation process.

I used the built in Setup project in Visual Studio 2010.

The solution

I could write it all here in my post but I have found one that was created earlier:

http://raquila.com/software/configure-app-config-application-settings-during-msi-install/

I essentially implemented the same solution but I wrote my .config file using a StringBuilder and deleted and re-wrote the.config file in the Post install custom action.

The other thing is that I created short cuts to the application by right-clicking on the primary output and chosing “Create Shortcut”, then I copied this to the desktop and users program menu locations.

The problem

I was installing this for “Everyone” and it would work fine for me, but when other people logged in and tried to launch the program the .msi would run and the application.exe.config file was being overwritten with the orginal version that was deployed with the .msi, which does not contain the users input.

The Fix

The problem is complicated and is related to the application short-cut.

It appears that by default the short-cuts created in the msi are “Advertised ShortCuts”.

According to microsoft when an advertised shortcut is activated “.. the installer verifies that all the components in the feature are installed before launching this file”.

This means that if you delete any of the files that were deployed to the installation location then the .msi will attempt to fix them and re-install the missing components, which in my case means that the application.exe.config is overwritten.

You can identify the “Advertised” short cut by looking at the “Properties” of a short-cut and the “Target” will be greyed out.

I found the post below that identifies an easy way to disable advertised shortcuts.

You need to set the “DISABLEADVTSHORTCUTS” property on the .msi. This can be done easily in the installer, I have my custom UI that is getting details from the user for the “Edit1Property” so in the Edit2Property I set these values and keep it invisible.

  • Edit2Property: DISABLEADVTSHORTCUTS
  • Edit2Value: 1
  • Edit2Visible: false

This updates the property table in the .msi and now all your short-cuts will be normal standard shortcuts.

http://social.msdn.microsoft.com/forums/en-US/winformssetup/thread/b0a3e6d5-38f0-4a37-9418-dd8d9297ef97/

Cheers 🙂

Final Tip: Setting the shortcut icon

Another tip is to set the icon based on the icon embeded in your .exe.

  • In the File System Editor, click on the ShortCut and view the properties
  • Click on the icon property
  • choose browse,
  • change from .ico to .exe
  • browse to the “Primary-Output for…” and choose OK.

It will show you the icons embeded in your .exe and this way you don’t need to deploy a seperate .ico file.

Advertisements
Categories: c#, Windows Forms

Windows form Label Control Autosize and wrap text vertically

27 October, 2009 Leave a comment

The other day I was trying to get a label control to autosize vertically and struggled to do it… but there is a simple trick…

Set the maximum width.

If you say “AutoSize=true” but set no MaximumSize.Width property it will just disappear off the right hand side of you form.

Set the MaximumSize.Width and the control autosizes correctly and wraps the text in the label control.

Cheers

 

Categories: Windows Forms

XP – MouseMove Event fired repeatedly by File Search Animation

This is a bug with windows XP, caused by the dog animation, that appears by default when you perform a file search.

I had a standard Windows Form Application with a ListView control on it. I setup a MouseMove event on the control.

The normal way this operates is as you move the mouse over the control the MouseMove event fires. Stop moving the mouse and the event does not fire. Seems simple.

Today however I noticed that the MouseMove event was firing repeatedly, even when the mouse was not moving!!

I wrote a very simple windows form test app with only this code and put debug logging on the MouseMove event and found that it was not happening on some other machines.

On the machine where things were going pear shaped I started closing applications until the only things open were some folders that I had been using, and the test app. It was still doing it. I closed all the folders and the MouseMove event stopped firing.

I tracked it down to the following:

  1. Open an file explorer window –> no problem
  2. Press Ctrl + F (find) (the dog annimation apears) –> problem the MouseMove event fires repeatedly even when the mouse is stationary over the control with the MouseMove event
  3. Go “Change Preferences”, and choose “Without an animated screen character”, the dog buggers off and –> No problem.

The animation must be taking control of the mouse and when it gives it back to my form it causes the mouse move event to fire.

Thats 1.5 hours of my life I will never get back.

Thanks Microsoft 😛

Categories: Windows Forms