Sunday 16 September 2012

Custom Key Combinations for Swapping Windows Keyboard Language

Occasionally I pair program with a developer who uses a Mac keyboard with his Windows machine. In order to use the Mac keyboard accurately, his default keyboard language is English (US). Although there's also a regular UK windows keyboard plugged in and ready to use, it requires time and effort to navigate the mouse to the language bar and swap to UK layout. This breaks the flow required to successfully pair program.

Good news - the language bar allows keyboard shortcuts to switch between languages. The default key combination SHIFT + LEFT ALT will loop through all the installed keyboard languages, in this instance toggling between US and UK keyboard layouts. But you can also set key combinations that will jump to a specific language.

From the Control Panel or the Start Menu, open the Region and Language settings page, navigate to the Keyboards and Languages tab and click the "Change keyboards" button:
On the Advanced Key Settings tab of the keyboards form, you can see the current settings for keyboard shortcuts:
To set up a shortcut combination to jump to a specific language, select the language (in the above case, English (UK), and click the Change Key Sequence button. This shows the following dialog box which can be used to define the keystroke required to jump directly to that keyboard language:

Thursday 13 September 2012

Treat Warnings as Errors: Exclude specifics warnings

As every Visual Studio user knows, you should build your project with the "Treat warnings as errors" switched on. This gives you very quick feedback when your project has problems that could otherwise get ignored.

This setting is toggled on the Build tab of the project's properties page:

As it says on the tin, this causes any problem that would normally be reported as a warning to be reported as an error, and prevent the project building:

If there are warnings that you don't want to break your build, you can suppress them specifically. You'll need the warning number, which will be reported in the Output window:

This number, without the CS prefix, needs to be entered in the "Suppress warnings" box, on the Build tab. Multiple warnings can be suppressed, by separating multiple warning codes with a comma.

Victory!

Alternatively, you can use a #pragma compiler directive in the code to suppress your warning:



Sunday 2 September 2012

Double Buffering Windows DataGridView

Years ago I wrote a WinForms application, that I still use every day. I tinker with the source code pretty much every day too. One of my recent issues to address was the rendering speed of the DataGridView controls; they'd take, roughly, forever to display around 30 items.

I did what I could think of to speed up the rendering (mainly around optimising data access) but couldn't get the rendering time down. Then I Googled it, and it appears that I'm not the first developer to have this problem; the DataGridView is notoriously slow to render. The annoying part is that the problem is so easy to fix - set the grid's DoubleBuffered property on.

This property is protected, so you need to either use Reflection to set it on your grid instance, or create a specialised DataViewGrid. I created a DoubleBufferedDataGridView:

When I use this in place of the DataGridView, the results are pretty good. A test app shows the time taken (ms) to render a sample datasource of 16 items on a standard DataGridView, versus a DoubleBufferedDataGridView.

It's so easy to fix, it seems odd that DoubleBuffered is not set to true by default, but hey.
The code for the sample form above is available as a GitGist