SSW Foursquare

Rules to Better Windows Forms - 2 Rules

Did you know that Windows Forms was recently updated with the release of .NET 8? See the changes on Microsoft Learn!


This category has been archived
Archived Reason: Category contains outdated references to windows forms
  1. Do you know Windows Forms should have a minimum size to avoid unexpected UI behavior

    If windows form does not setup a minimum size, your users could have unpredictable form behaviour as seen below:Bad window form

    Figure: Bad Example - Unexpected window form

    Therefore, a standard has been built to ensure Windows forms have a minimum size.

    Good window form

    Figure: Good Example - User friendly window form

  2. Do you know how to format your MessageBox code?

    You should always write each parameter of MessageBox in a separate line. So it will be more clear to read in the code. Format your message text in code as you want to see on the screen.

    Private Sub ShowMyMessage()
     MessageBox.Show("Are
     you sure you want to delete the team project """ + strProjectName
     + """?" + Environment.NewLine + Environment.NewLine + "Warning:
     Deleting a team project cannot be undone.", strProductName + "
     " + strVersion(), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)

    Figure: Bad example of MessageBox code format

    Private Sub ShowMyMessage()
     MessageBox.Show( _ 
     "Are you sure you want to delete the team project """ + strProjectName + """?"
     _ + Environment.NewLine _ +
     Environment.NewLine _ +
     "Warning: Deleting a team project cannot be undone.", _
     strProductName + " " + strVersion(), _
     MessageBoxButtons.YesNo, _
     MessageBoxIcon.Warning, _
     MessageBoxDefaultButton.Button2)
    End Sub

    Figure: Good example of MessageBox code format

We open source. Powered by GitHub