.net
Archived Posts from this Category
Archived Posts from this Category
comments off Friday 17 Aug 2007 | Guy Mahieu | .net(t) , c#(t) , msbuild(t) , regex(t)
Some Windows Forms controls come with copy/paste functionality out of the box. This is great when you just want the standard copy/paste behaviour, but what if you want to do some transformation of the data on the clipboard prior to displaying it in the Windows Forms control?
In my case I needed to convert a selection copied from Excel to a comma-delimited list of values when they were pasted in a TextBox. Since there is no OnPaste() method on the TextBox to override, I had to dig deeper to get the job done.
Usually something like this can be done by creating a subclass of the component and overriding the WndProc method to capture the right message. So I created a class called MyTextBox which extends TextBox and I trapped the windows Paste message, like this:
private const int WM_PASTE = 0x302; protected override void WndProc(ref Message m) { if (m.Msg == WM_PASTE) { // trigger our custom paste logic OnPaste(); } else { base.WndProc(ref m); } } protected virtual void OnPaste() { // put custom logic here }
There you go, now my own protected virtual OnPaste() method is called when the control receives a PASTE message, and the message is not passed to the base class to prevent the default paste behavior from being executed.
All that is left to do now is get the text data from the clipboard, do my own transformations and change the Text property of the TextBox accordingly.
3 comments Saturday 03 Mar 2007 | Guy Mahieu | .net(t) , c#(t) , tips&tricks(t) , winforms(t)
I guess people put todo’s in their code for different reasons, it can be lazyness (I’ll write this hard/boring piece of code later), unclear requirements or maybe a debate is needed before a certain choice can be made.
Be that as it may, some todo’s need to be solved more urgently than others: “TODO: implement database logic” could be more urgent than “TODO: remove obsolete method”, but removing an obsolete method will probably be easier to do, so it might make sense to do it right away.
Visual Studio 2003 gave you a nice list of all the todo’s in your solution, but for some reason Visual Studio 2005 only does this for currently opened files. In the project I am current working on, we wanted a clear report of all todo’s in our code to make sure that they are solved as soon as possible. Since we already have a CruiseControl.NET server running, we decided to have our continuous integration build generate the TODO report for us. The samples in this post are valid for CruiseControl 1.1.
2 comments Monday 22 Jan 2007 | Guy Mahieu | .net(t) , continuous integration(t) , cruisecontrol(t) , xslt(t)