6. WinForms: GUI Programming in .


50 views
Uploaded on:
Description
Goals.
Transcripts
Slide 1

6. WinForms: GUI Programming in .NET

Slide 2

Objectives ".NET backings two sorts of shape based applications, WinForms and WebForms . WinForms are the conventional, desktop GUI applications. The colossal news is that Visual Studio .NET empowers fast, intuitive development of shape based applications… " Event-driven, code-behind programming Visual Studio .NET WinForms Controls

Slide 3

Part 1 Event-driven, code-behind programming…

Slide 4

Event-driven applications Idea is extremely straightforward: singular client activities are converted into "occasions" occasions are passed, 1 by 1, to application for preparing this is the way most GUIs are customized… GUI App

Slide 5

GUI-based occasions Mouse move Mouse click Mouse double tap Key press Button click Menu determination Change in center Window enactment and so forth

Slide 6

Code-behind Events are taken care of by strategies that live behind visual interface known as "code-behind" our employment is to program these techniques…

Slide 7

Call-backs Events are a get back to from question us… How is association made? setup by code auto-created by Visual Studio

Slide 8

Part 2 Visual Studio .NET…

Slide 9

Visual Studio .NET (VS.NET) A solitary IDE for all types of .NET improvement from class libraries to shape based applications to web administrations and utilizing C#, VB, C++, J#, and so on

Slide 10

outline run break Basic operation Visual Studio works in one of 3 modes: plan run soften When up uncertainty, check the title bar of VS…

Slide 11

Example: a windowing application GUI applications depend on the idea of structures and controls … a frame speaks to a window a frame contains at least 0 controls a control interfaces with the client Let\'s make a GUI application in a progression of steps…

Slide 12

Step 1 Create another venture of sort "Windows Application" a frame will be made for you consequently…

Slide 13

Step 2 — GUI configuration Select craved controls from tool kit… float mouse over tool kit to uncover simplified onto frame position and resize control

Slide 14

GUI configuration cont\'d… A basic adding machine: Position and arrange controls snap to choose set properties by means of Properties window

Slide 15

Step 3 — code configuration "Code behind" the frame… Double-tap the control you need to program uncovers coding window

Slide 16

Step 4 — run mode Run!

Slide 17

Break mode? Effortlessly activated in this application through invalid information…

Slide 18

Working with Visual Studio In Visual Studio, you work as far as source documents, ventures & arrangements Source records contain code end in .cs, .vb, and so forth. Extend documents speak to 1 get together utilized by VS to monitor source records all source documents must be in a similar dialect end in .csproj, .vbproj, and so on. Arrangement (*.sln) documents monitor extends so you can chip away at various activities

Slide 19

Part 3 WinForms…

Slide 20

WinForms Another name for customary, Windows-like GUI applications versus WebForms, which are electronic Implemented utilizing FCL subsequently versatile to any .NET stage

Slide 21

question Abstraction FCL goes about as a layer of reflection isolates WinForm application from fundamental stage occurrence of FCL class System.Windows.Forms.Form CLR Windows OS

Slide 22

Form properties Form properties normally control visual appearance: AutoScroll BackgroundImage ControlBox FormBorderStyle (sizable?) Icon Location Size StartPosition Text (i.e. window\'s inscription) WindowState (minimized, amplified, ordinary) Form1 frame; shape = new Form1(); form.WindowState = FormWindowState.Maximized; form.Show();

Slide 23

Form strategies form.Hide(); . . . form.Show(); Actions you can perform on a shape: Activate : give this frame the concentration Close : close & discharge related assets Hide : hide, however hold assets to show shape later Refresh : redraw Show : make frame obvious on the screen, & enact ShowDialog : show modularly

Slide 24

Form occasions Events you can react to: raise properties window double tap on occasion name Load : occurs just before frame is appeared for first time Closing : occurs as shape is being shut (capacity to wipe out) Closed : occurs as shape is certainly being shut Resize : occurs after client resizes shape Click : occurs when client taps on shape\'s experience KeyPress : occurs when shape has center & client squeezes key

Slide 25

Example Ask client before shutting structure: private void Form1_Closing (question sender, System.ComponentModel.CancelEventArgs e) { DialogResult r; r = MessageBox.Show("Do you truly need to close?", "MyApp", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (r == DialogResult.No) e.Cancel = genuine; }

Slide 26

Part 4 Controls…

Slide 27

Controls User-interface protests on the frame: marks catches content boxes menus list & combo boxes alternative catches check boxes and so forth

Slide 28

protest question protest question Abstraction Like structures, controls depend on classes in the FCL: System.Windows.Forms.Label System.Windows.Forms.TextBox System.Windows.Forms.Button and so on. Controls are examples of these classes

Slide 29

Who makes all these objects? Who is in charge of making control occasions? code is auto-produced by Visual Studio when shape protest is made, controls are then made…

Slide 30

Naming traditions Set control\'s name by means of Name property A typical naming plan depends on prefixes: cmdOK alludes to a summon catch control lstNames alludes to a rundown box control txtFirstName alludes to a content box control

Slide 31

Labels For static show of content used to name different things on the frame used to show read-just outcomes Interesting properties: Text : what client sees Font : how he/she sees it

Slide 32

Command catches For the client to click & play out an errand Interesting properties: Text : what client sees Font : how he/she sees it Enabled : can it be clicked Interesting occasions: Click : occurs when catch is "pressed" private void cmdAdd_Click (...) { int i, j, k; i = System.Convert.ToInt32( this.txtNum1.Text ); j = System.Convert.ToInt32( this.txtNum2.Text ); k = i + j; MessageBox.Show( "Sum = " + k.ToString() ); }

Slide 33

Text boxes Most ordinarily utilized control! for showing content for information passage Lots of intriguing elements…

Slide 34

Text box properties Basic properties: Text : denotes the whole substance of content box (a string) Modified : has content been adjusted by client? (Genuine/False) ReadOnly : set on the off chance that you need client to view content, however not alter Do you need multi-line content boxes? MultiLine : True permits different lines of content Lines : array of strings, one for every line in content box ScrollBars : none, flat, vertical, or both

Slide 35

Text box occasions Interesting occasions: Enter , Leave : occurs on change in center KeyPress : occurs on ascii keypress KeyDown , KeyUp : occurs on any key mix TextChanged : occurs at whatever point content is adjusted Validating and Validated Validating allows you to wipe out on invalid info

Slide 36

List Boxes Great for showing/keeping up rundown of information rundown of strings rundown of items (rundown box calls ToString() to show) Customer[] clients; . . /make & fill cluster with items... . /show clients in rundown box foreach (Customer c in clients) this.listBox1.Items.Add(c);/show name of chose client (assuming any) Customer c; c = (Customer) this.listBox1.SelectedItem; if (c == invalid) return; else MessageBox.Show(c.Name);

Slide 37

Just the tip of the ice shelf… Menus, exchanges, toolbars, and so forth. A large number of extra controls .NET and ActiveX right-tap on Toolbox "Customize Toolbox"

Slide 38

Summary Event-driven writing computer programs is extremely natural for GUI applications Forms are the initial phase in GUI outline every shape speaks to a window on the screen frame creator empowers simplified GUI development Users cooperate basically with shape\'s controls marks, content boxes, catches, and so forth suggests that GUI writing computer programs is control programming

Slide 39

References Books: R. Grimes, "Developing Applications with Visual Studio .NET" Best books on building GUIs are VB-based: J. Savage, "The VB.NET Coach" (starting) F. Balena, "Programming Microsoft VB .NET (Core Reference)" (wide scope, moderate level)

Slide 40

Lab? Take a shot at lab #3, "WinForms"…

Recommended
View more...