Posts Tagged ‘Windows Forms’

Windows Forms controls and the red X

Thursday, December 17th, 2009

I have been working on a project where certain controls randomly seem to come up with a red X and a red border around it.  I wasn’t sure what was causing it, but it turns out it is when an exception is thrown by code in the paint event.  For more details, see the following blog from sturmnet.org:  WinForms controls and the red X.

Setting the .NET WebBrowser Control’s DocumentText Property

Tuesday, June 30th, 2009

The .NET framework comes with a nice WebBrowser control, which is a wrapper around MS Internet Explorer.  The problem is that it can be rather quirky at times, and one of these times is when you try to set the DocumentText property from code.  It might work, and then again it might not.  It is quite difficult to pin down exactly when it does work and when it doesn’t, but the following bit of code seems to set it for me…

  wbMsg.AllowNavigation = False
        wbMsg.AllowNavigation = True

        If wbMsg.Document Is Nothing Then
            wbMsg.DocumentText = s
        Else
            wbMsg.Document.OpenNew(True)
            wbMsg.Document.Write(s)
        End If

Windows Forms DateTimePicker ShowCheckBox and not Checked bug in .NET 2.0

Monday, March 9th, 2009

I recently upgraded a project that I had inherited from another programmer to .NET 2.0. Shortly after, I received an email complaining that a date field had stopped saving correctly. I tried it out, and all looked fine in the user interface, but sure enough, the value was not being written to the database.

It took me some time to work out what was going on. The ShowCheckBox property was set to False, but the Checked property also was. For some reason, the DateTimePicker in .NET 2.0 interprets this as meaning that the value that is in the control is to be ignored, and it returns today’s date if you access the Value property.

This was a pretty simple fix – all it took was to set Checked to True, and it all worked fine again. It is an interesting gotcha to look out for though – I haven’t seen it documented anywhere as a breaking change of .NET 2.0