Introduction to C - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Introduction to C

Description:

Collections only hold objects (more later) What Visual Controls Can Do ... Dialogs appear below the form in the designer. The ColorDialog. Accessing the Dialog ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 20
Provided by: jonapr
Category:

less

Transcript and Presenter's Notes

Title: Introduction to C


1
Introduction to C
  • Basic GUI Controls

2
Agenda
  • What All Controls Can Do
  • The Label
  • The TextBox
  • The Button
  • The MessageBox
  • Dialogs

3
What All Objects Can Do
  • All objects have properties common to the Object
    class
  • I.e. in OO speak, they inherit from Object
  • All objects
  • Equals(Object) determine (T/F) if the objects
    are equal
  • GetType() determine what type of class this
    object is
  • ToString() represents the object as a
    string/text
  • Ultimately, everything is an object
  • Collections only hold objects (more later)

4
What Visual Controls Can Do
  • A visual control is an object
  • All visual controls have properties common to the
    Control class
  • All controls
  • Font (determines how to display text of the
    control)
  • BackColor, ForeColor (determine colors of
    control)
  • Left, Top, Right, Width, Size, Bottom (determine
    location and size of control)
  • Text (determines what the control shows)
  • Visible (is the control shown to the user or not)
  • Enabled (does the control respond to events)
  • And more

5
Visual Control Examples
Button
TextBox
CheckBox
TreeView
Label
ListBox
6
The Label
  • Can change text
  • Typically does not respond to events
  • Good to annotate other controls (TextBox) and
    provide instructions
  • Important properties
  • Text (what is displayed)
  • Font (how its displayed)
  • AutoSize (set false to allow multi-line text)

7
The TextBox
  • Typically begins blank (or provide default text)
  • Useful for obtaining information from user
  • Contains a string (text)
  • Convert to another type (number) if needed
  • Important Properties
  • Text (what the textbox contains)
  • Multiline (allows multiple lines of text)
  • ScrollBars (shows scroll bars)
  • WordWrap (should the text be wrapped or not)

8
The Button
  • Allows the user to initiate an event
  • User tells program to do something
  • Responds to the Click event
  • Can have text and/or image
  • Important properties
  • Text (the text displayed on the button)
  • Image (shows an optional image)
  • Enabled (does the button respond to events)
  • Click (event handler)

9
The MessageBox
  • Useful for displaying brief information to the
    user
  • Can also provide selections (via buttons)
  • Important properties
  • Text
  • Caption
  • And more

10
The Message Box (cont.)
  • Many different options in creating the MessageBox
  • All use the Show method
  • Examples
  • MessageBox.Show(Hello world!)
  • MessageBox.Show(Hello world!, Hello)
  • MessageBox.Show(Do you want to abort?, Make a
    choice!", MessageBoxButtons.AbortRetryIgnore,
    MessageBoxIcon.Warning, MessageBoxDefaultButton.Bu
    tton1)

11
Dialogs
  • Many common dialogs are built into Windows (and
    consequently C)
  • Common look and feel is a good thing
  • Invoked with the ShowDialog() method
  • Then get dialog result and optionally process
    input from dialog

12
Dialogs
  • Non-visualuntil invoked

Dialogs appear below the form in the designer
13
The ColorDialog
14
Accessing the Dialog
  • private void buttonColorSelect_Click(object
    sender, EventArgs e)
  • DialogResult result
  • result colorDialog1.ShowDialog()
  • if (result DialogResult.OK)
  • this.BackColor colorDialog1.Color

15
The Result
Clicking the button shows the color dialog
Clicking OK change the forms background
color. Clicking Cancel leaves the background
color as is.
16
Putting It All Together
17
Things to Implement
  • Opacity of the form (0.00 1.00)
  • NumericUpDown control
  • Value 1
  • Minimum 0.2 (dont want it invisible! ?)
  • Maximum 1.0
  • DecimalPlaces 2
  • Increment 0.01
  • FileDialog for background image of form

18
Event Handlers for this Example
  • private void buttonBackground_Click(object
    sender, EventArgs e)
  • DialogResult result
  • string filename
  • result openFileDialogChooser.ShowDialog()
  • if (result DialogResult.OK)
  • filename openFileDialogChooser.FileName
  • this.BackgroundImage Image.FromFile(filen
    ame)
  • private void numericUpDownOpacity_ValueChanged(obj
    ect sender, EventArgs e)
  • this.Opacity (double)numericUpDownOpacity.Value

19
Conclusion
  • You should know a little bit about Object
  • Everything is an Object
  • You should know a little bit about Visual
    Controls
  • What can they all do?
  • How are the different from Object?
  • You should know about
  • The Label
  • The TextBox
  • The Button
  • The MessageBox
  • Dialogs
  • You should be able to write a simple C Windows
    application
Write a Comment
User Comments (0)
About PowerShow.com