Skip to content


Rolling back to previous ClickOnce versions

I’ve been deploying software using Microsoft’s ClickOnce mechanism a lot lately and despite enjoying  its simplicity, especially in comparison to some of the more complicated MSI Setup Projects I’ve inherited, I’ve found myself slightly nervous about its abililty to turn a simple software code update into a potentially massively distributed network of fail with its Auto Updating feature.

Because of this, you occasionally have a rather urgent need to roll back everyone to the last working version, and this turns out to be rather easy. Continued…

Did you like this? Share it:

Posted in .Net, Microsoft, Software Development.

Tagged with , , , , , , , , .


RichTextBox ScrollToCaret() bug

I recently needed to add selective colour to text in a Windows Forms TextBox. TextBox doesn’t support this, but its close sibling RichTextBox does and as they both derive from TextBoxBase, the conversion in code was painless.

The original TextBox control would automatically set the caret (cursor) position to the end of the text and use ScrollToCaret() to ensure the last line was always visible after dynamically adding content. This doesn’t quite work the same when called on a RichTextBox as it appears to scroll until just the very top of the caret is visible, resulting in at best a few pixels of the last line’s text visible.

Quite a bit of googling of the problem reveals lots of discussion but not much in the way of a suggested solution.

Fortunately, user32.dll provides calls we can use to set the scroll position and we can access these unmanaged functions through P/Invoke as follows:

[StructLayout(LayoutKind.Sequential)]
public class POINT
{
    public int x;
    public int y;

    public POINT()
    {
    }

    public POINT(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
}

const int SB_VERT = 1;
const int EM_SETSCROLLPOS = 0x0400 + 222;

[DllImport("user32", CharSet = CharSet.Auto)]
static extern bool GetScrollRange(IntPtr hWnd, int nBar, out int lpMinPos, out int lpMaxPos);

[DllImport("user32", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, POINT lParam)

Then, when you want to set the scroll position (“control” is your RichTextBox instance):

int min, max;
GetScrollRange(control.Handle, SB_VERT, out min, out max);
SendMessage(control.Handle, EM_SETSCROLLPOS, 0, new POINT(0, max - control.Height));
Did you like this? Share it:

Posted in C#, Software Development, Windows Forms.

Tagged with , , , , , , , , .


Microsoft 70-511 Exam Passed

Last week I passed the Microsoft 70-511: Windows Application Development with Microsoft .NET Framework 4 exam, making me a Microsoft Certified Technology Specialist!

This is the first of four exams I’m aiming to complete in order to become a Microsoft Certified Professional Developer.

Did you like this? Share it:

Posted in C#, Microsoft, Software Development, WPF.

Tagged with , , , , , , , , .


How to handle Command Line Arguments in WPF Applications

I’ve not considered it before as up to now I haven’t required it, but obviously in a WPF Application you don’t have a nice

static void Main(string[] args)
{
...
}

with a useful string array of arguments like you do in a regular C# console app, so how do you access them?

In a default WPF application, the entry point to the program is Continued…

Did you like this? Share it:

Posted in C#, Software Development, WPF.

Tagged with , , , , , , , , .


How to fix the iTunes 10 compilation album grouping bug

I’ve been encoding a lot of my CDs in iTunes (10.1.2) lately. It generally does a great job of encoding to Apple Lossless and grabbing the appropriate track data and cover art from the internet I’ve have come across an annoying problem. Occasionally, despite ALL of the tags being the same, and numerous combinations of “Compilation, Sort Album, etc…” being set, iTunes still insists on listing a compilation album as individual tracks like this:

A google search of the problem shows that I’m not alone. There seems to be as many solutions as there are people posting so in case it’s of any use, here’s what has worked for me every time. Continued…

Did you like this? Share it:

Posted in Apple, iTunes.

Tagged with , , , , , , , , , , , , .


DoshTracker Update #5 – 16 months later…

It has been a while, but not completely quiet on the DoshTracker front. Although last year my Project 365 took up most of my free time, I have been slowly working on another UI design using a new Javascript framework (jQuery) and this time it’s really coming together.

We have:

  • Full Google Maps interaction, plotting all our note hits on a map.
  • International support, now you can plot your notes anywhere the Google Maps API can geocode.
  • The complete old database! All of your original DoshTracker notes and user accounts have been preserved. These will be imported during the beta.

Check out the new logo and design on www.doshtracker.co.uk and please sign up for our mailing list so we can keep in touch.

Invites to the closed beta test will be going out soon to the mailing list and former users of the old site.

Did you like this? Share it:

Posted in Doshtracker.

Tagged with , , .


How to find the Hash key on a UK Mac Keyboard

I’m a Microsoft .Net programmer by day and yet a Mac user by night, but occasionally I still need to type the ‘#’ key on my UK Mac keyboard and always forget the shortcut as it’s not immediately apparent. I usually end up copying and pasting it from somewhere else.
It’s ALT-3, #########, there!
Did you like this? Share it:

Posted in Apple, OS X.

Tagged with , , , , .


OK – Cancel behaviour with data binding in WPF

As much as I am a fan of the Mac OSX and iPhone approach of modifying a setting and having it apply immediately without any further user interaction, my current work involves designing GUIs for Industrial Control and Automation systems where the old <OK> <Cancel> buttons are still required (often by law) which brought up the question of how to do this in WPF with data binding where, depending on the control, updates are triggered either in real-time or on loss of focus.

The answer is in one of the attributes of Binding called “UpdateSourceTrigger” which has the following options:

  • LostFocus – Update bound property when the control loses focus (TextBox default).
  • PropertyChanged – Update bound property in real-time.
  • Explicit - Update bound property when UpdateSource() is called

It is this last setting which allows us to delay updating our bound property until we tell it to.

Let’s say we have a UserControl containing a TextBox, ‘MyTextBox’ which is bound to some Dependency Property and two buttons, ‘OK’ and ‘Cancel’. Depending on how you hook your buttons up (with RoutedCommands or click handlers (eugh!)) the ‘OK’ button’s code looks like this:

BindingExpression be = MyTextBox.GetBindingExpression(TextBox.TextProperty);
if (be!=null) be.UpdateSource();

The ‘Cancel’ button’s code does the reverse:

BindingExpression be = MyTextBox.GetBindingExpression(TextBox.TextProperty);
if (be!=null) be.UpdateTarget();

Et voila! Your dependency property will now only update when you want it to.

Did you like this? Share it:

Posted in C#, Software Development, WPF.

Tagged with , , , .


Handling events from within a ControlTemplate in WPF

Here’s an interesting one that had me stumped for a few hours.

Following on from my previous post, where I explained how to create a ControlTemplate to style a TextBox in WPF, I’ve got an object, TextEntryBox, which dervies from a TextBox (it provides some custom event handlers when text is entered, but to all intents and purposes, it’s a regular TextBox).

I wanted to style my TextEntryBox, this time including a button within my ControlTemplate (this will eventually toggle an on-screen keyboard pop-up, but that’s another blog post!). I came up with this:
Continued…

Did you like this? Share it:

Posted in C#, Software Development, WPF.

Tagged with , , , , , , , , , , , .


How to create a ControlTemplate for a WPF TextBox

This is a short post, but has one specific piece of information I want to keep.

Q: If you want to create a ControlTemplate to provide a custom style for a TextBox, how do you specify where the text goes when it’s used in WPF?

A: The answer was hidden in the depths of the MSDN Documentation. You have to include a <ScrollViewer> within your ControlTemplate with an x:Name value of “PART_ContentHost”.

Here’s a noddy example:


Did you like this? Share it:

Posted in C#, Software Development, WPF.

Tagged with , , , , , , , , , , .