Top Banner
Using Whidbey Layout Using Whidbey Layout Building a non-resizable dialog Building a non-resizable dialog
31

Using Whidbey Layout Building a non-resizable dialog.

Dec 14, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Using Whidbey Layout Building a non-resizable dialog.

Using Whidbey LayoutUsing Whidbey LayoutBuilding a non-resizable dialogBuilding a non-resizable dialog

Page 2: Using Whidbey Layout Building a non-resizable dialog.

Building a login dialogBuilding a login dialogPart 1Part 1

Page 3: Using Whidbey Layout Building a non-resizable dialog.

Sizing RequirementsSizing Requirements

Grow and shrink Grow and shrink depending on depending on text/fonttext/font

{

Page 4: Using Whidbey Layout Building a non-resizable dialog.

Sizing RequirementsSizing Requirements

Grow and shrink Grow and shrink depending on depending on text/fonttext/font

{Fill up the remaining spaceFill up the remaining space

Page 5: Using Whidbey Layout Building a non-resizable dialog.

Sizing RequirementsSizing Requirements

Grow and shrink Grow and shrink depending on depending on text/fonttext/font

{Fill up the remaining spaceFill up the remaining space

{Label Label vertically vertically centered centered relative relative to their to their matching matching TextBoxTextBox

Page 6: Using Whidbey Layout Building a non-resizable dialog.

Sizing RequirementsSizing Requirements

Grow and shrink Grow and shrink depending on depending on text/fonttext/font

{Fill up the remaining spaceFill up the remaining space

{Label Label vertically vertically centered centered relative relative to their to their matching matching TextBoxTextBox

} Dialog Dialog should should size to fit size to fit contentscontents

Page 7: Using Whidbey Layout Building a non-resizable dialog.

Start off with a blank form.Start off with a blank form.

Page 8: Using Whidbey Layout Building a non-resizable dialog.

Drag and Drop a new TableLayoutPanel onto the form.Drag and Drop a new TableLayoutPanel onto the form.

Page 9: Using Whidbey Layout Building a non-resizable dialog.

Add two labels and two text boxes from the toolbox to the Add two labels and two text boxes from the toolbox to the newly added TableLayoutPanel.newly added TableLayoutPanel.

Page 10: Using Whidbey Layout Building a non-resizable dialog.

Are we there yet?Are we there yet?

Nope! We have the controls, but no Nope! We have the controls, but no sizing behavior yet. sizing behavior yet.

Lets start out by fixing up the Lets start out by fixing up the columns, then we’ll address the columns, then we’ll address the rows.rows.

Page 11: Using Whidbey Layout Building a non-resizable dialog.

Choose Edit Rows and Columns off the context menu.Choose Edit Rows and Columns off the context menu.

Page 12: Using Whidbey Layout Building a non-resizable dialog.

By editing the rows and columns we can control the By editing the rows and columns we can control the sizing behavior of our table.sizing behavior of our table.

Page 13: Using Whidbey Layout Building a non-resizable dialog.

In this case, we want the first column to be autosized, and the second In this case, we want the first column to be autosized, and the second column to fill up the remaining space in the table.column to fill up the remaining space in the table.

Page 14: Using Whidbey Layout Building a non-resizable dialog.

Set the Label Set the Label column to be column to be AutoSize so that AutoSize so that the width of the the width of the column is the size column is the size of the largest of the largest label.label.

In this case, we want the first column to be autosized, and the second In this case, we want the first column to be autosized, and the second column to fill up the remaining space in the table.column to fill up the remaining space in the table.

Page 15: Using Whidbey Layout Building a non-resizable dialog.

Set the Label Set the Label column to be column to be AutoSize so that AutoSize so that the width of the the width of the column is the size column is the size of the largest of the largest label.label.

Set the TextBox Set the TextBox column to be column to be 100% so as to fill 100% so as to fill up the remaining up the remaining space in the table space in the table with TextBoxes.with TextBoxes.

In this case, we want the first column to be autosized, and the second In this case, we want the first column to be autosized, and the second column to fill up the remaining space in the table.column to fill up the remaining space in the table.

Page 16: Using Whidbey Layout Building a non-resizable dialog.

Back on the form, we see the results of our edits. Now that we’ve fixed up Back on the form, we see the results of our edits. Now that we’ve fixed up the columns, lets address the rows.the columns, lets address the rows.

Page 17: Using Whidbey Layout Building a non-resizable dialog.

Going back into the same editor, we can access the RowStyles by Going back into the same editor, we can access the RowStyles by

switching the ComboBox to Rows.switching the ComboBox to Rows.

Page 18: Using Whidbey Layout Building a non-resizable dialog.

Since we want both rows to be as tall as the largest control (most likely Since we want both rows to be as tall as the largest control (most likely

the height of the text box) – use AutoSize for both rows.the height of the text box) – use AutoSize for both rows.

Set both rows to Set both rows to be AutoSize so be AutoSize so that they are as that they are as large as the large as the largest control in largest control in the rowthe row

Page 19: Using Whidbey Layout Building a non-resizable dialog.

The results of the changes to RowStyles.The results of the changes to RowStyles.

We’re closer, but the last row is way too big!We’re closer, but the last row is way too big!

Page 20: Using Whidbey Layout Building a non-resizable dialog.

We need to shrink up the table itself in order to collapse the last row. We need to shrink up the table itself in order to collapse the last row.

Set AutoSize = true Set AutoSize = true and AutoSizeMode and AutoSizeMode to GrowAndShrinkto GrowAndShrink

Page 21: Using Whidbey Layout Building a non-resizable dialog.

Rows are fixed.Rows are fixed. …but the table isn’t stretching the width of the dialog. …but the table isn’t stretching the width of the dialog.

There are several ways to fix this, we’ll use the Dock property.There are several ways to fix this, we’ll use the Dock property.

Page 22: Using Whidbey Layout Building a non-resizable dialog.

Selecting the TableLayoutPanel can be difficult when it is AutoSized. Selecting the TableLayoutPanel can be difficult when it is AutoSized.

At this point we should bring up Document Outline to help us select At this point we should bring up Document Outline to help us select what we need. what we need.

This window can be found at:This window can be found at:View->Other Windows -> View->Other Windows -> Document OutlineDocument Outline

Page 23: Using Whidbey Layout Building a non-resizable dialog.

Select the table and Dock fill it. Select the table and Dock fill it.

It may look like we’re back to square one, but stay with it….It may look like we’re back to square one, but stay with it….

Page 24: Using Whidbey Layout Building a non-resizable dialog.

Set AutoSize on the Form and AutoSizeMode to GrowAndShrink. Set AutoSize on the Form and AutoSizeMode to GrowAndShrink.

(When you run the application, the form will shrink down, you can also (When you run the application, the form will shrink down, you can also manually shrink it in the designer).manually shrink it in the designer).

Page 25: Using Whidbey Layout Building a non-resizable dialog.

At this point, you can add space from the edge of the form by adjusting At this point, you can add space from the edge of the form by adjusting the Form’s Padding property.the Form’s Padding property.

RightLeft

Top

Bottom

Control the spacing Control the spacing from the frame of the from the frame of the form by changing form by changing Form.PaddingForm.Padding

Page 26: Using Whidbey Layout Building a non-resizable dialog.

We want the Labels to be glued to the left edge, but vertically centered We want the Labels to be glued to the left edge, but vertically centered within their cells. In order to do this, we can set the anchor to be Left.within their cells. In order to do this, we can set the anchor to be Left.

Page 27: Using Whidbey Layout Building a non-resizable dialog.

We can stretch the textboxes by setting their Anchors to Right | Left.We can stretch the textboxes by setting their Anchors to Right | Left.

Set UseSystemPasswordChar=true on the password text box.Set UseSystemPasswordChar=true on the password text box.

Page 28: Using Whidbey Layout Building a non-resizable dialog.

Testing automatic resize behaviorTesting automatic resize behavior

We can change the label’s text to “Network Password:” and watch the We can change the label’s text to “Network Password:” and watch the first column grow and second column shrink.first column grow and second column shrink.

Notice how the first Notice how the first column grew?column grew?

Previous column width

Previous column width

Page 29: Using Whidbey Layout Building a non-resizable dialog.

Resetting the text to “Password:” shrinks back up the first column.Resetting the text to “Password:” shrinks back up the first column.

Notice how the first Notice how the first column shrinks back column shrinks back when the original text when the original text is restored.is restored.

Page 30: Using Whidbey Layout Building a non-resizable dialog.

Set the Form’s title to Login by changing the Text property and….Set the Form’s title to Login by changing the Text property and….

Page 31: Using Whidbey Layout Building a non-resizable dialog.

We’re done!We’re done!….ish. Now its time add an OK and Cancel button…….ish. Now its time add an OK and Cancel button…