31 October 2006

A Developer’s Best Friends

Filed under: Programming — Laura @ 9:19 pm

After having a couple of friends share useful links with me recently, I decided to do a search for other helpful add-ins and related tools for Visual Studio 2005. Following are what I tried, along with my first impressions:

The Visual Studio 2005 SDK comes with a set of power toys. I won’t detail them all, but SuperDiff and Source Outliner both look to be extremely useful, while the Event Toaster seems quite the opposite — I have no need for the notification it provides, and there’s no straightforward way I’ve found to remove it from the system tray. SuperDiff seems like a decent diff tool with a well thought-out UI. Source Outliner looks like it’s going to be a great way to easily manage and navigate in large files, such as those with a lot of properties or methods, or those with nested classes.

CopySourceAsHTML (CSAH) — this one I’ve got mixed feelings about. On the one hand, it’s a handy tool for generating pre-formatted code to paste to a web page. On the other hand, it can generate some pretty nasty-looking HTML (particularly if you leave all the default settings turned on); and if you’re using a custom color for the text background in the IDE, it has some serious problems with reproducing that accurately. On the third hand (yes, I know, I’m a mutant), it’s relatively customizable and also open-source, so it shouldn’t be too hard to tweak to meet any specific needs.

Alex Papadimoulis, of TheDailyWTF fame, has written Smart Paster, which allows you to paste text in several different formats. I believe this will be quite a handy time-saver, and I’m really impressed with how configurable it is, in a very clean, unobtrusive way.

And finally, I’ve installed TestDriven.NET, which other reviewers seem to applaud as the cadillac of add-ins. This one’s a complete experiment for me, as I’m only beginning to explore TDD, and also have yet to compare it with Team Suite’s built-in testing tools. More later when I get time to give it a thorough “test.”

28 May 2006

Resizing Label Control for VB.NET

Filed under: Programming — Laura @ 11:02 pm

…And now for something completely different, as they say.

I’ve tried and failed to do something similar to this before, but finally with the help of jo0ls on XVBT, the problem has been tracked down to a rounding error. The idea is to have a control (a label in this case, although the same method should work for a textbox or other type of control as well) that automatically adjusts its height to fit its contents. A simple concept, one would think. And at first glance, one might also think that the AutoSize property of a label would already do that, but no, a look at MSDN explains that AutoSize is of no use once you have text that wraps.

So here’s my solution; feel free to use it as you see fit (and leave a comment if you find it useful, problematic, etc.).

Public Class SmartSizeLabel
  Inherits System.Windows.Forms.Label
#Region " Local declarations "
  Private _noReentry As Boolean = False
#End Region

#Region " Public properties "
  Public Overrides Property AutoSize() As Boolean
    'Force AutoSize to false; there's not much point in this control if we aren't word-wrapping
    Get
      Return False
    End Get
    Set(ByVal value As Boolean)
      MyBase.AutoSize = False
    End Set
  End Property
#End Region

#Region " Overridden methods "
  Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
    MyBase.OnResize(e)

    If Not _noReentry Then _SetBestHeight()
  End Sub

  Protected Overrides Sub OnStyleChanged(ByVal e As System.EventArgs)
    MyBase.OnStyleChanged(e)

    _SetBestHeight()
  End Sub

  Protected Overrides Sub OnMarginChanged(ByVal e As System.EventArgs)
    MyBase.OnMarginChanged(e)

    _SetBestHeight()
  End Sub

  Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
    MyBase.OnTextChanged(e)

    _SetBestHeight()
  End Sub

  Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    'No need to take the bottom margin into account here; it's already been done
    '  in _SetBestHeight(), when adjusting the size of the control itself (and
    '  thus its ClientRectangle).
    Dim rect As New RectangleF(Me.Margin.Left, Me.Margin.Top, _
        Me.ClientRectangle.Width - Me.Margin.Left - Me.Margin.Right, Me.ClientRectangle.Height)

    e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), rect, _
        StringFormat.GenericDefault)
  End Sub
#End Region

#Region " Local methods "
  Private Sub _SetBestHeight()
    Dim gfx As Graphics = Me.CreateGraphics()

    _SetBestHeight(gfx)
    gfx.Dispose()
  End Sub

  Private Sub _SetBestHeight(ByVal gfx As Graphics)
    'This takes into account any space taken up by the control border
    Dim diff As Integer = Me.Height - Me.ClientSize.Height

    'This will get called from OnResize, and also will generate a resize event, so
    '  use a flag to avoid unnecessary recursion
    _noReentry = True

    'Adjust height for border and margins
    Me.Height = _BestHeight(gfx) + diff + Me.Margin.Top + Me.Margin.Bottom
    _noReentry = False
  End Sub

  Private Function _BestHeight(ByVal gfx As Graphics) As Integer
    'Get size of the part of the ClientRectangle that the text will go in; use a really
    '  big height so that all the string will fit (hopefully -- if the height's larger
    '  than MaxValue, we've got other issues =P) in order to measure it accurately.
    Dim srcSize As New SizeF(Me.ClientRectangle.Width - Me.Margin.Left - Me.Margin.Right, _
        Single.MaxValue)
    Dim bestSize As SizeF = gfx.MeasureString(Me.Text, Me.Font, srcSize, _
       Drawing.StringFormat.GenericDefault)

    Return Convert.ToInt32(Math.Ceiling(bestSize.Height))
  End Function
#End Region
End Class

5 May 2006

Extreme Programming

Filed under: Programming — Laura @ 10:38 pm

A friend in the game development industry recently pointed out this article to me. It’s an interesting walkthrough of a typical day at software engineer Noel Llopis’ job. Reading the description of the work flow, however, I found it anything but typical. Perhaps I’ve been under a rock for awhile, but the concept of pair programming was quite new to me, and a rather fascinating idea. Is this approach a practical one for other industries? For smaller teams? It’s definitely one that deserves more thought and research.

Edit: Thanks to Adam, here is a related study: Crosstalk article

23 April 2006

Teamwork

Filed under: Programming — Laura @ 9:10 pm

I just received this image via email:

I must say, I haven’t seen a poster quite so appropriate to my workplace in awhile, aside from of course the gems at despair.com.

Unfortunately, I have been unable to find the source of this image, so if it is your creation or if you have information about its copyright, please contact me and I will remove or credit as appropriate.

13 April 2006

Microsoft Freebies: A Pleasant Surprise

Filed under: > Certification, Programming — Laura @ 1:56 pm

I got an email about a Microsoft promotion at around the same time my friend and coworker, Adam, was discussing it.  He showed me the link, which required watching a set of ASP.NET webcasts in order to qualify for the free offer.  When I finally got around to doing so, I followed the link from my email, which also mentioned watching the 3 webcasts to receive a book, exam discount voucher, etc.  What I didn’t realize, until I got my loot today and noticed that it was different loot than what Adam had gotten, was that the two offers are subtly different. 

 Visual Studio 2005 Discovery Pack

Different books, different vouchers, different expiration dates.  So I’m excited that both book and exam voucher should serve me well for my current MCTS certification path.  Now I wonder…. can one qualify for both free offers?

Top of Page ©2006 Laura Barkman. All rights reserved.