Thursday, 19 November 2009

C# Textbox with numbers only

I wanted to allow the user to modify the size of an image by entering a new width and heigth into textboxes. I was surprised to find that there was no really simple way of doing this like a property of the textbox (or maybe I missed it). This is how I solved it:

private void textBox_imageHeight_KeyPress(object sender, KeyPressEventArgs e)
{
int isNumber = 0;
if(!Char.IsControl(e.KeyChar.ToString().ToCharArray()[0]))
e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber);
}

The IF statement checks for backspace and other control input.

Thursday, 2 July 2009

Mouse Gestures in Windows

StrokeIT is a great program that enables mouse gestures for most windows applications.

Here, opening a new tab in Firefox

It speeds up window management (minimize, maximize or close windows) , navigation in e.g. Firefox and Copy-Paste in most applications. Gestures can also be customized for each application.

Wednesday, 24 June 2009

ÅÄÖ in LaTeX

I'm writing my master thesis in Latex (eclipse/texlipse). The thesis is written in Enlish but I wanted to write an abstract in swedish as well and had some trouble adding the swedish characters ÅÄÖ. After searching the net for a while I finally found a solution that didn't require the use of any additional packages:

å: \aa
ä: \"{a}
ö: \"{o}

Å: \AA
Ä: \"{A}
Ö: \"{O}

Note that \aa and \AA requires a blank space at the end! If they are at the end of a word you might have to force this extra space by adding "\ ", e.g. the words "små bollar" would look like: sm\aa \ bollar.

If you have a lot of these characters in a text (and use a swedish keyboard), write them as usual and make a search-replace for each character when you're done.