Software Development — Category

May
10
2009

Using the standard Windows font in .Net

0

Perhaps one of the subtle differences between Windows Vista and Windows XP is the new font that Microsoft decided to use for the user interface. Tahoma 8.25pt has been used since Windows 2000 (but was available before then) and it has been replaced with Segoe UI 9pt, which is a much nicer looking font, with its tighter and rounder letters, but larger spacing. The bigger point size also helps increase the readability.

But how do you deal with different user interface fonts in .Net? Especially when the default for Windows Forms is the horrible MS Sans Serif (why?). Well, one method is to use the Environment class to detect which version of Windows the user is using and set the font,

if (Environment.OSVersion.Platform == PlatformID.Win32NT &&
  Environment.OSVersion.Version.Major >= 6) {
    // Vista+
    this.Font = new Font("Segoe UI", 8.0f);
} else if (Environment.OSVersion.Platform == PlatformID.Win32NT &&
  Environment.OSVersion.Version.Major < 6) {
    // XP and below
    this.Font = new Font("Tahoma", 8.0f);
} else ... (Unix/Mac code if you want to go that far)

But what if the user has custom fonts selected, or is using the Mono framework, or Microsoft decide to change the default font again in the future? The fonts are probably going to be messed up.

Fortunately, .Net has the SystemFonts class, which is a small collection of the default fonts used by the system. But, the names aren’t actually what is advertised. DefaultFont is not actually the Windows default font, but the .Net default font… MS Sans Serif, ahhh!

The only one that seems to return the real system default font is MessageBoxFont. So, we can turn that whole if statement into…

this.Font = SystemFonts.MessageBoxFont;

You can also use this font when dealing with larger sizes…

HeadingLabel.Font = new Font(SystemFonts.MessageBoxFont.FontFamily, 15f, FontStyle.Regular);

Pretty fonts for all occasion, that even follow the users preferences. Yay!

Jul
8
2005

RSS readers viewing

0

While I have been working on Now. I realised a problem that I haven’t really seen discussed before, probably because others haven’t really seen it as a problem.

What am I talking about? How we view RSS feeds in RSS readers.
(more…)

Jul
3
2005

Still working on Now.

0

Sometimes after an initial release of a program my mind still buzzes with things that I can add to it. Well, it has happened again. After releasing Now. the other day and playing around with real feeds I noticed that it could be made better. Now. 1.1 was started, and here’s the new:

  • Atom feed support (uses MagpieRSS now).
  • OPML feed import (very handy when migrating your feed list from a real program over to Now.)
  • Edit feed properties.
  • Options pane.

And the improved:

  • Better handling of feeds with no title text.
  • Fall-back for when feeds don’t provide handy date/times.
  • Gets feed names from the feed itself.
  • Most settings in config.php now reside in the database. Config.php still requires editing for the database settings though.
  • Automatic cache handling.

It should be easy to upgrade. If you already have Now. 1.0, you’ll get notified of updates through the welcome page. Anything else people want fixed?

Jul
2
2005

Damn names

0

I thought I would release my online RSS reader now. But unfortunately I realised that the name I gave it is a registered trademark and hence shouldn’t be used unless I want lawsuits against me. So it is back to the drawing board, sorry folks!

Plus it is great.

Jun
14
2005

One more down, one to go

1

Where the hell am I? Oh, right. It was another night where I didn’t get to bed until 2am and had to wake between 8 and 9 in the morning. So now I’m quite shattered. Unfortunately I’m quite “awake,” if you know what I mean, and hence probably won’t sleep. But that won’t help because I have a meeting at 2pm and a movie to go see.

So, what was this assignment. It involved Visual Basic .net, and it hurt all of us. We had to link to a database and edit results and stuff. Visual Basic is one screwed up language. We had finished by 12 midnight, but then had to go on to try and link the real database in the program. This took another hour and three quarters. The computers were incredibly slow for some reason.

Now to get on with my ethics essay…