« November 2002 | Main | January 2003 »

December 23, 2002

AssemblyVersion equals build time

As documented , using an asterisk for build and revision numbers  yields a build equal to the number of days since January 1, 2000 local time, and for revision to be equal to the number of seconds since midnight local time, divided by 2.

 

Thus a revision number can be turned into a build time with the formula:

 

AssemblyName an = Assembly.GetEntryAssembly().GetName();

DateTime d = new DateTime(2000, 1, 1, 0, 0, 0);

d += TimeSpan.FromDays(an.Version.Build) + TimeSpan.FromSeconds(an.Version.Revision * 2);

 

DataGrid, IsSelected method’s row argument’s domain is the DataView

Another case of the documentation omitting a key piece of information.

 

The IsSelected method’s row argument’s domain is the DataView.

December 22, 2002

Windows Forms Order of Events

Key MSDN document  on Windows Forms event sequences for various controls and actions.

December 11, 2002

XPath default namespace hack

/// TODO: Unsatisfying hack. The XPath treats an empty prefix as the null namespace (not the default namespace).

/// To find nodes that aren't in the null namespace, but are in the default namespace, an explicitly prefixed

/// namespace must be added to the namespace manager and used within the xpath string.

XmlNamespaceManager mgr = new XmlNamespaceManager(rowNode.OwnerDocument.NameTable);

mgr.AddNamespace("xpathnullns", rowNode.NamespaceURI);

XmlNode nextPageNode = rowNode.SelectSingleNode("xpathnullns:"+nextPageXPath, mgr);

 

December 04, 2002

OnResized, OnSizeChanged, OnLayout

All three events see the same overall size at the same time.

OnLayout sees the target size but the contained controls may have modified sizes.

For splitters, OnLayout appears to see the reduced or enlarged sizes of the docked controls prior to adjustment for container bounds.

December 03, 2002

Window Forms, Control Layout, Docking Padding

Tricks to effective layout using docking:

1.       Use “Docking Padding” property of panels and group boxes to inset docked controls.

2.       Individual controls will dock against the next most front control. Check that the control you’re about to dock is in front by dragging it so that it partially covers the controls it is meant to dock against.

3.       Splitters are only needed if user adjustments of control (panels generally) is needed.

4.       Haven’t found a way yet to set splitter behavior to a percentage of available space.

5.       If you lose a control behind other controls, find it in the combo box at the top of the properties window.

6.       “6” works well as an “All” Docking Padding setting.

7.       Splitter width is adjustable. Its either the X or Y size depending on how the splitter is docked.

8.       When you add controls thru the designer, they appear in an AddRange method call as an array in the inverse order of creation. When you add controls one at a time with the Add method, immediately call BringToFront on the just added control to force them into creation order. Alternatively, you can add them backwards in “designer” time. Logically this means you’d first add the control with fill docking and then add the controls working from the center to the edges.

December 02, 2002

XML, Embedding HTML in XML

The comment syntax <!-- this is a comment --> generates an error if the comment contains “--“. Seems a bit stupid to complain about an invalid comment terminator when it isn’t intended to be a comment terminator. What gives? Do comments need to be escaped in some way?

 

SelectNodes returns a Count == 0 XMLNodeList if the xpath query matches nothing.

 

Can’t have “]]>” inside a CDATA block.

 

Encoding HTML for placement within an XML file:

XmlElement htmlNode = xqargResult.OwnerDocument.CreateElement("ds:html", nsmgr.LookupNamespace("ds"));

xqargResult.AppendChild(htmlNode);

htmlNode.InnerText = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(html));

 

Decoding the XML file to recover embedded HTML:
string html = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(result.SelectSingleNode(@"ds:html", nsmgr).InnerText));