Showing posts with label UI. Show all posts
Showing posts with label UI. Show all posts

Monday, March 24, 2014

WPF: Loading RTF document in RichTextBox from Embeded Resouce.

While developing a UI interface for Wix based bootstrapper,  I found that in WPF, Richtextbox Control is not same as it was in Windows Forms. So loading an RTF document in it was a little mess. However, while finding and digging for about two days, I finally came to a simple solution. Let’s say, my WPF project name is Surf.
  1. In your WPF projects, add a Resources.resx file (if its not already there).
  2. Add your RTFDoc.rtf in your Resources.resx file.
  3. Along with your Resources.resx file, there would be code behind file:Resources.Designer.cs. Open it and copy its namespace and Class name. In my case it is  Surf.Resources.Resource1

I used this to load rtf data in my WPF RichTextBox control. Here are the lines from the code behind of my XAML:

using Surf.Resources;
void Surface_Loaded(object sender, RoutedEventArgs e)         
{             
//Loading License Agreement document data.
MemoryStream memLicStream = new MemoryStream(ASCIIEncoding.Default.GetBytes(Resource1.RTFDoc));             

this.MyRTFDocument.Selection.Load(memLicStream, DataFormats.Rtf);
}

System.IO.MemoryStream class is used here to load the rtf data from RTFDoc stored in Resource1.resx. And then it is loaded as a Selection in my RichTextBox Control (MyRTFDocument), while specifying Data Format as Rtf.

Wednesday, October 17, 2012

How to force GUI uninstall using ARPNOREMOVE property?

 

Background:

Whenever you install a product using its .msi installer, it shows itself in Add/Remove programs list. To modify it, you mostly have 3 options:

  1. Uninstall
  2. Change
  3. Repair
 

AddRemoveProgramsOptions
(Screen shot from Add Remove applet)

If you choose “Uninstall” from this menu, it would simply shows you the Windows Installer progress bar dialog and may remove your product during that i.e. no user input required. Here is the progress bar dialog you may have observed:

NoGUI_Uninstall

And if you choose option 3 i.e. Repair, same progress bar dialog would be presented while reinstalling your product.

In these two options, certain things are absent which are normally available in GUI mode. For instance, custom actions scheduled in InstallUISequence. Custom actions to be executed through Button click events in any dialog, properties defined during UI mode, custom dialogs etc. That is, this would simply skip all these. However custom action scheduled in InstallExecuteSequence may execute here.

However, if you choose option 2 i.e. Change, (Or double click on the program in Add/Remove list) you are presented with a Windows Installer Maintenance Dialog box which leads you to this option dialog:

image

Now again, you have 3 same options, but this time, there would be full GUI mode unlike only progress bar dialog.

Change will let you modify your installer product i.e. you may add/remove features etc.
Repair would simply reinstall the product with the options used to install it last time.
Remove would allow you to uninstall the product, but unlike simple progress bar mode, you will have a full GUI mode with progress bar, buttons etc.

 

Problem:

I got a situation in which I was asked to prevent the users from uninstalling the product using progress bar mode. And I also faced another problem with another product that whenever I was uninstalling using progress bar mode, it only shows that it is removing the product, but was doing nothing. However problems where not there whenever we used GUI mode.

So initially I defined ARPNOREMOVE like:

<Property Id="ARPNOREMOVE" Value="1" />

But this would actually remove the option to Uninstall your product from both Control Panel and its Maintenance Dialog box as shown in following shots:







image image

The only option left to remove this product was from original msi. It will always giving you the option Uninstall in its context menu, even if ARPNOREMOVE is define, as shown in this shot:
image


And this would remove product using progress bar mode.


But this has solved nothing. We want our users to use GUI mode and should be able to uninstall properly.


So to achieve this, I had to redefine Maintenance Dialog while enabling the Remove button forcefully using Condition element so that users would only be able to remove the product from Maintenance Dialog by clicking Remove button.




Maintenance Dialog Redefined



  1. <Dialog Id="My_MaintenanceTypeDlg" Width="370" Height="270" Title="!(loc.MaintenanceTypeDlg_Title)">

  2.         <Control Id="ChangeButton" Type="PushButton" X="40" Y="65" Width="80" Height="17" ToolTip="!(loc.MaintenanceTypeDlgChangeButtonTooltip)" Default="yes" Text="!(loc.MaintenanceTypeDlgChangeButton)">

  3.           <Publish Property="WixUI_InstallMode" Value="Change">1</Publish>

  4.           <Condition Action="disable">ARPNOMODIFY</Condition>

  5.         </Control>

  6.         <Control Id="ChangeText" Type="Text" X="60" Y="85" Width="280" Height="20" Text="!(loc.MaintenanceTypeDlgChangeText)">

  7.           <Condition Action="hide">ARPNOMODIFY</Condition>

  8.         </Control>

  9.         <Control Id="ChangeDisabledText" Type="Text" X="60" Y="85" Width="280" Height="20" NoPrefix="yes" Text="!(loc.MaintenanceTypeDlgChangeDisabledText)" Hidden="yes">

  10.           <Condition Action="show">ARPNOMODIFY</Condition>

  11.         </Control>

  12.         <Control Id="RepairButton" Type="PushButton" X="40" Y="118" Width="80" Height="17" ToolTip="!(loc.MaintenanceTypeDlgRepairButtonTooltip)" Text="!(loc.MaintenanceTypeDlgRepairButton)">

  13.           <Publish Property="WixUI_InstallMode" Value="Repair">1</Publish>

  14.           <Condition Action="disable">ARPNOREPAIR</Condition>

  15.         </Control>

  16.         <Control Id="RepairText" Type="Text" X="60" Y="138" Width="280" Height="30" Text="!(loc.MaintenanceTypeDlgRepairText)">

  17.           <Condition Action="hide">ARPNOREPAIR</Condition>

  18.         </Control>

  19.         <Control Id="RepairDisabledText" Type="Text" X="60" Y="138" Width="280" Height="30" NoPrefix="yes" Text="!(loc.MaintenanceTypeDlgRepairDisabledText)" Hidden="yes">

  20.           <Condition Action="show">ARPNOREPAIR</Condition>

  21.         </Control>

  22.         <Control Id="RemoveButton" Type="PushButton" X="40" Y="171" Width="80" Height="17" ToolTip="!(loc.MaintenanceTypeDlgRemoveButtonTooltip)" Text="!(loc.MaintenanceTypeDlgRemoveButton)">

  23.           <Publish Property="WixUI_InstallMode" Value="Remove">1</Publish>

  24.         </Control>

  25.         <Control Id="RemoveText" Type="Text" X="60" Y="191" Width="280" Height="20" NoPrefix="yes" Text="!(loc.MaintenanceTypeDlgRemoveText)">

  26.         </Control>

  27.         <Control Id="RemoveDisabledText" Type="Text" X="60" Y="191" Width="280" Height="20" NoPrefix="yes" Text="!(loc.MaintenanceTypeDlgRemoveDisabledText)" Hidden="yes">

  28.           <Condition Action="hide">ARPNOREMOVE</Condition>

  29.         </Control>

  30.         <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />

  31.         <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Disabled="yes" Text="!(loc.WixUINext)" />

  32.         <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">

  33.           <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>

  34.         </Control>

  35.         <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.MaintenanceTypeDlgBannerBitmap)" />

  36.         <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />

  37.         <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />

  38.         <Control Id="Title" Type="Text" X="15" Y="6" Width="340" Height="15" Transparent="yes" NoPrefix="yes" Text="!(loc.MaintenanceTypeDlgTitle)" />

  39.         <Control Id="Description" Type="Text" X="25" Y="23" Width="340" Height="20" Transparent="yes" NoPrefix="yes" Text="!(loc.MaintenanceTypeDlgDescription)" />

  40.       </Dialog>





Please note that following are the original lines which are modified in above code segment:


<Control Id="RemoveButton" Type="PushButton" X="40" Y="171" Width="80" Height="17" ToolTip="!(loc.MaintenanceTypeDlgRemoveButtonTooltip)" Text="!(loc.MaintenanceTypeDlgRemoveButton)">
<Publish Property="WixUI_InstallMode" Value="Remove">1</Publish>
<Condition Action="disable">ARPNOREMOVE</Condition>
</Control>
<Control Id="RemoveText" Type="Text" X="60" Y="191" Width="280" Height="20" NoPrefix="yes" Text="!(loc.MaintenanceTypeDlgRemoveText)">
<Condition Action="hide">ARPNOREMOVE</Condition>
</Control>
<Control Id="RemoveDisabledText" Type="Text" X="60" Y="191" Width="280" Height="20" NoPrefix="yes" Text="!(loc.MaintenanceTypeDlgRemoveDisabledText)" Hidden="yes">
<Condition Action="show">ARPNOREMOVE</Condition>
</Control>


That is, RemoveButton and RemoveText controls are no more bound to APRNOREMOVE property, so these would be active in any case, while RemoveDisabledText would be hidden if ARPNOREMOVE property is present.


Now that would result in forcing the user to be only able to remove product using our Maintenance Dialog –> Remove button which makes sure that we would have InstallUISequence and any other UI related thingies available.


TIP: From above dialog code, you can also extract the use of ARPNOREPAIR and ARPNOMODIFY properties in different ways according to your requirements.

Friday, April 23, 2010

Tool Palettes in AutoCAD:

 

In AutoCAD, Tool Palettes provides the flexibility to have quick access to Drawings, Tools, and Commands etc.

These can be docked, undocked, resize and move at different locations in AutoCAD UI.

Users can easily customize these according to their needs. This involves:

  • Addition/deletion of Palettes.
  • Rename existing Palettes
  • Addition/removal of Commands,  Icons etc

Etc…

There can be large number of palettes which can easily be accessible using context menu while showing the list of available palettes.

 

Users can even place their drawings, templates etc on these tools palettes and can access them while working

  ToolPalettes_List

   

Arranging in Groups

AutoCAD brings a great number of Tool Palettes. In addition, users can add/remove their own. In addition, as more tool palettes can be created, this could lead to a very large number of tools and palettes and list can be very long and would be difficult to use.

Tool Palettes can be arranged in Palette groups and Sub Groups, which will show only selected Palettes.

Tool Palettes Groups are very useful when you have a large number of Tool Palettes and you have to use limited number of tools and wish to have only your required tools in palettes.

You can switch between Tool Palette Groups and can display all tool palettes at once.

  ToolPalettes_Groups

How to create Palette Groups:

As there is a good number of Tool Palettes available already and you might want to add your own. At this point you might want to arrange yours into groups. So here is the way, to create Palette Groups and arrange your tool palettes in these:

Click Right Mouse Button on Tool Palette Panel and choose Customize Palettes. This should open Customize Dialog box:

From the right panel (Palette Groups:), you can define your Groups and Sub Groups.

From the left panel (Palettes), you can choose which Tool palettes to be added into your groups.

Simply Draw your Tool Palettes from Left Panel (Palettes) to the Right Panel (Palette Groups:) and drop on your group. When you are done, press Close Button.

And your groups would be available immediate and could be accessed using Context Menu of Tool Palette Panel (right mouse button on Palette Panel Window).

 

PaletteGroups