Absolute positioning in VS2005 HTML designer

In Visual Studio .NET 2003, ASPX pages included a property called pageLayout, which defaulted to “GridLayout” – essentially, CSS absolute positioning for all form elements. Although this is a horrible idea in a production application (I assume MS did it to make it easier to demo rapid application building), it does turn out to have a handy use – it makes it easy to quickly sketch out web forms for UI design or prototyping.

Visual Studio 2005 did away with the pageLayout property on web forms, but it did include a similar capability in the HTML Designer. The Tools/Options/HTML Designer settings page includes positioning options that allow you to create a very similar (though exactly the same) experience to pageLayout=”GridLayout”. To enable it, check the “Change positioning to the following for controls added using the Toolbox, paste, or drag and drop” option, and select “Absolutely positioned” in the combo box. This recreates most of the GridLayout experience, with one exception – new controls that are dropped onto the design surface always show up initially in the upper-left hand corner. They can then be dragged to any position on the form. In VS2003, controls appear exactly where they are dropped.

The option described above is a global setting, which can make it inconvenient to use. Fortunately, it’s not too hard to cruft up a macro that toggles the state of the CSS position option:

Sub ToggleCssPositioning()
   Dim autoPositioningProperty As [Property] = DTE.Properties("TextEditor", "HTML Specific").Item("AutoPositioning")
   Dim autoPositioningModeProperty As [Property] = DTE.Properties("TextEditor", "HTML Specific").Item("AutoPositionMode")

   If (autoPositioningProperty.Value = 0) Then
      |
autoPositioningProperty.Value = 1
      autoPositioningModeProperty.Value = 0
   ElseIf (autoPositioningProperty.Value = 1) Then
     
autoPositioningProperty.Value = 0
   End If
End Sub

Hook the macro up to a toolbar button, and you can easily switch between the two modes. Unfortunately, it doesn’t seem that VS2005 macros that are assigned to toolbar buttons can be represented as toggle buttons, so the UI doesn’t give you a clear indication of what mode you’re in. Maybe some day I’ll think about wrapping this up into an addin.

 

 

14 Comments

Comments have been disabled for this content.