+ All Categories
Home > Documents > Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of...

Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of...

Date post: 18-Jan-2018
Category:
Upload: edgar-flynn
View: 221 times
Download: 0 times
Share this document with a friend
Description:
3 Size Size is a simple built-in struct that stores dimensions (width, height pair) in pixels. Declare a Size: Size rectSize = new Size(); Assign values: rectSize.Width = 100; rectSize.Height = 200; Or do it all at one time: Size boxSize = new Size(300, 100); Size uses integer values; SizeF uses float values for the dimensions.
30
Compound Data Types Part13dbg
Transcript
Page 1: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

Compound Data Types

Part13dbg

Page 2: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

2

Point• A Point is a simple built-in struct that stores a

pair of screen coordinates.• Instantiate a Point:

Point aPoint = new Point();• Assign values:

aPoint.X = 100;aPoint.Y = 200;

• Or do it all at one time:Point x1 = new Point(200, 175);

• Point uses integer values.• Another type of Point structure is PointF; it uses

float values for the x and y coordinates.

Good things come to those who read the textbook! See page 451 of textbook.

Page 3: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

3

Size• Size is a simple built-in struct that stores

dimensions (width, height pair) in pixels.• Declare a Size:

Size rectSize = new Size();• Assign values:

rectSize.Width = 100;rectSize.Height = 200;

• Or do it all at one time:Size boxSize = new Size(300, 100);

• Size uses integer values; SizeF uses float values for the dimensions.

Page 4: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

4

Rectangle

• A Rectangle is another simple built-in struct that stores the coordinates and sizes necessary to create a rectangle.

• You can initialize a Rectangle one of 2 ways:– Assign 4 integer coordinates

(x-coord, y-coord, width, height) – Point and a Size (yet another struct)

(startPoint, rectSize)

Page 5: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

5

Using Points and Rectangles

• Draw and Fill methods that call for coordinate pairs also accept values stored in Points.

• If dimensions of Rectangles are involved, as in DrawRectangle and DrawEllipse, – the Rectangle may be used (instead of x-coord, y-

coord, width, height)– Size can be used (instead of Width, Height pairs)

UsingPoints

Page 6: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

6

Arrays of Points

• Both the DrawLines() and DrawPolygon() methods of the Graphics object require an array of points to define the vertices of their output.

PointArray

Page 7: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

7

Alternative Way to Force Paint Event

• Instead of calling the Paint event manually (and the necesssary preparation of the PaintEventArgs pea), you may mark a control or form as invalidated, which will call the Paint event.

• this.Invalidate(); in the Resize or Load or Click handler of a button will cause any code in the Paint event to be executed (and thus execute any drawing code you have placed there).

Page 8: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

8

DateTime

• DateTime is a built-in struct type that has a number of methods and properties used for storing and converting time and date values.

• The Now property of the DateTime object delivers the present time and date to the struct from the system clock.

Page 9: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

9

Create a Struct of Type DateTime

• Declare new struct:DateTime myDT = new DateTime();

• Get present time and date:myDT = DateTime.Now;

• Extract time or date value:lblDay.Text =

myDT.DayOfWeek.ToString();

DateTimeStruct

Page 10: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

10

Generate DateTime Values with DateTimePicker Control• The DateTimePicker control furnishes a visible

interface for selecting DateTime values.• Dates are selected with a perpetual calendar

display.• Times and dates may be displayed in several

formats.• Use the TimeSpan class to manipulate and

compare times and dates.

DatePicker

Page 11: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

11

Regions in Code

• We have seen before that the region, Windows Form Designer Generated Code, is a collapsible region.

• When we want to view the contents, we click the in front of region.

• To collapse the region, we click the in front of region.

Page 12: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

12

Making Your Own Collapsible Regions in Code• You can make your own collapsible region in

code, for example, a region for the class-level variables.

• Type #region regionDescription above the class-level variable declarations.

• Type #endregion after the last line of class-level variable declarations.

• You will now have a user-defined region.

Page 13: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

Multiple Form Applications

Single Document Interface

Page 14: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

14

Launching a Second Form• Although it is possible to

design a form totally manually, adding and designing a new form to a project with the IDE is much easier.

• Use the Add Windows Form… selection from the Project menu.

• A new form class is added to the project.

Page 15: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

15

Launching a Second Form

• An instance of the second form must be created within the original application form.

• Once the form object is created, it may be displayed by running its Show() method.

• Multiple instances of the second form can be created and displayed.

SecondSDI

Page 16: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

16

Startup Form as “Parent”

• Launching a second form in this way causes the second form to depend upon the first for survival.

• Closing the first form causes the second form to close as well.

Page 17: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

17

Hiding a Form

• Run the Hide() method of the original form to remove it from view prior to showing the second form.

• Now the second form commands the application and can not lose focus unless it is closed.

• Closing the second form leaves the original form running, but not visible.

HideParent

Page 18: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

18

Showing a Hidden Form

• We could run the Show() method of the original form from the second form—but only if the second form is aware of the first form

• If we created a new instance of the first form within the second form it would be different from the original.

• One way to solve the problem is to pass the identity of the original form to the second form as a constructor argument.

Page 19: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

19

Identifying the Parent Form

• If the second form has a class scope variable of type Form, the constructor can use its argument to assign the identity of the “parent” form.

• This then allows the second form to run the Show() method of the “parent”.

FormConstructor

Page 20: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

Multiple Form Applications

Owned Forms

Page 21: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

21

Owned Forms

• Subsequent SDI forms can be launched from a startup form as Owned Forms.

• Although these forms can transfer focus back to the startup form they remain on top of the startup form at all times.

• Add a new form to the Owned Forms collection of the startup form by setting its Owner property to the startup form.

OwnedForms

Page 22: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

22

Owned Forms

• Potential uses for owned forms are as specialized help forms, customized “toolboxes” or overview maps.

• Use an owned form when you don’t want to lose sight of a form in a multiple SDI application, even if it loses focus.

Page 23: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

Multiple Form Applications

Multiple Document Interface

Page 24: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

24

MDI Forms

• Standard Windows forms may exist as either MDI parents or MDI children.

• MDI children may only be displayed within the client area of their parent and may not be dragged outside that client area.

• Like owned forms, MDI children always remain on top of their parent form.

Page 25: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

25

MDI Parent Forms

• Any standard Windows form can be converted to an MDI parent by setting its IsMdiContainer property to True.

• By convention, MDI parent forms have a dark gray client area.

• Because MDI parents are intended solely as containers for other forms, they should not include controls.

Page 26: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

26

MDI Parent Forms

• Use menu items in the MenuStrip control of the MDI parent to control activities associated with displaying MDI child forms.

MDIParent

Page 27: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

27

MDI Child Forms

• Forms destined to become children of an MDI parent should be instantiated within the MDI parent class.

• Any standard Windows form can become an MDI child.

• Set the MdiParent property of the child instance to the parent.

• Show the child form.

MDIChildren

Page 28: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

28

MDI Child Form Menus

• When an MDI Child has focus within an MDI parent form, the menustrips of the Parent and Child are merged and menuitems from both are displayed.

• The merging of the menus to present a sensible display is coordinated by adjusting the MergeAction and MergeIndex properties of each menuitem.

• The Visible property of the child menustrip must be set to false if you do not wish to see both parent and child menustrips.

Page 29: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

29

The Windows Menu

• By design convention the Menustrip of an MDI parent form has a Window menu item that lists the displayed child forms and indicates which has focus.

• The contents of this menuitem (mnuWindow) are automatically generated by simply setting the MdiWindowListItem property of the parent menustrip to the appropriate menuitem (mnuWindow).

Page 30: Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.

30

The Window Menu

• Three different modes of display are available for child forms: cascade, horizontal tile, and vertical tile.

• These modes can be set with the LayoutMdi() method of the parent form.

• Use the foreach loop to close all forms in the child collection of the parent at once.

MDIWindows


Recommended