Our First Form

There should already be a Form1 in your project, created automatically by Visual Studio when you created the WinForms projects. There’s nothing in the form, and before putting things in it, we’re going to set a few properties on the form itself. First, size the form to something like 800 x 600. Then, set the form’s font to Segoe UI, 9pt. and set KeyPreview to True. That’s all the properties we need to set in the form.

Now drop a Menu Strip, a Tool Strip, and a Status Strip onto the form. They will automatically be called menuStrip1, toolStrip1, and statusStrip1. My philosophy with these one-of controls is to let them live with their default names. We don’t need to change the properties of any of these controls except to add a Status Label to the Status Strip. Add the Status Label to the Status Strip, and change the Spring property to True. The Status Label will let us display text in the Status Strip. The Status Strip control itself does not have a property that does this.

Now drop a Split Container onto the form. This control contains two Panels, Panel1 and Panel2, and will automatically dock to fill the remaining space in the form. This control also has a behavior that can drive you nuts — you can’t click to select the Split Container once you drop it in the form. What selects when you try is one of the two panels. The trick is to click to select either panel and then press Escape. Then you will see the properties for the Split Container itself. We need to change two properties. Set Panel1MinSize to 120, and set SplitterDistance to 120 as well. This will give us an column on the left for buttons, commands, etc.

Now drop a Data View Grid into Panel2. We’re going to change a lot of properties this time!

AllowUserToAddRows = False
AllowUserToDeleteRows = False
AllowUserToOrderColumns = True
AllowUserToResizeRows = False
Dock = Fill
ColumnHeadersHeightSizeMode = DisableResizing
MultiSelect = False
ReadOnly = True
RowHeadersVisible = False
SelectionMode = FullRowSelect
StandardTab = True

Ok, so at this point, you can go ahead, save the form, and even run the application. Just press F5. Here’s what your project should look like.

Leave a Reply

Your email address will not be published. Required fields are marked *