1 / 26

COP2360 – C# Programming

COP2360 – C# Programming. Chapter 10ish – Oct 28. Before we Start. Go grab the Chapter 9 Example Zip files, un zip it and put it on your thumb drive and open the solution. Annoucements. Exam 2 is Next Week (November 4) Covers Chapter 4 and Chapters 7 through 10 Similar to Exam 1

mcrutcher
Download Presentation

COP2360 – C# Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP2360 – C# Programming Chapter 10ish – Oct 28

  2. Before we Start • Go grab the Chapter 9 Example Zip files, un zip it and put it on your thumb drive and open the solution.

  3. Annoucements • Exam 2 is Next Week (November 4) • Covers Chapter 4 and Chapters 7 through 10 • Similar to Exam 1 • 70% Short Answer/Essay – You select • Closed Book/Closed Notes • 30% Programming • Windows Form Program • November 11 is a Holiday (Veterans Day) • No Candy For You!! • I’m setting up a Grade Book in Blackboard for the course.

  4. Quick ReviewConsole Apps vs. Windows Apps • Console Apps have a specific start and end with usually minimal “outside” interaction. • Many times used for batch processing • Although there can be different processing paths depending upon input or data, the paths are relatively fixed. • Windows Apps are reliant on the user “doing” something on a form. • Entering data, pushing a button, selecting from a drop-down. • Every execution is potentially different because it all depends upon the interaction of the user. • The program basically sits there and waits for the user to do something. • Each control on the form has many events that it can react to. Each event can have a different set of code to process that event.

  5. Quick Review • Windows Forms applications creates three initial files • Form1.cs:normally this is the only one you edit • Form1.Designer.cs: holds the auto generated code (look but don’t touch!!) • Program.cs:contains the Main( ) method, where execution always begins (Don’t touch this either!!) • Just FYI. The names (Form1 and Program) may be changed based on what you want to call the program • Notice the “Partial Class” designation in the Form1 source files…It takes two to tango. • Notice the extra designation “: Form” on the class definition • public partial class Form1 : Form This indicates that the class is inheriting all of the properties and methods of the general Form class.

  6. Control Properties • Properties of a control describe how that specific control is to look or function on a particular form. • All forms have certain properties that they inherit from their parent classes • Specific controls then have their own set of properties in addition to the inherited ones.

  7. Control Event Handlers • Event Handlers are the links between what a users “does” to a control and what code is executed for that event. • Each control has a default “Event Handler” (many times click) that you can get to by simply double clicking the control. • But, there are many other events that can also be identified and handled. • For a specific control, they are listed under the “lightening bolt” properties for that control.

  8. What Other Controls are Available in Windows Forms? • Text Controls • Labels • A control that cannot take user input but can be manipulated programmatically. Used for titles or messages. • Text Boxes • A control that may or may not allow input (depending upon the way it is set up.) • May be single line or multi-line • Masked Text Box • Allows developer to define the format of the data for entry • Rich Text Boxes • Has the abilities of a regular text box PLUS users can change formats and fonts (like they can do in Word) (but you have to program it be able to do that!!)

  9. What Other Controls are Available in Windows Forms? • Selection Controls • Radio Buttons – Can select exactly one from a group. • To allow for multiple series of Radio Buttons, can be placed inside of other controls. • Panels and Group Boxes. • Check Boxes – Can select none, all or anything in between • Drop-Down Lists/Combo Boxes • Can usually select only one, but does allow for multiple selections. • Requires one to load values to the list.

  10. What Other Controls are Available in Windows Forms? • Data Controls – We’ll get more into this when we get into database access • List Boxes • List Views • Data Grid Views • Combo Boxes

  11. What Other Controls are Available in Windows Forms? • Layout Controls • Grouping • Panels • Group Box • Tabs • Navigation • Scroll Bar • Splitter • Program Flow • Menu (including right click menu) • Tool Strip • Timer • Other • Progress Bar • Picture Box

  12. Message Box Stuff • MessageBox Overloads • MessageBoxButtons • When we use the Buttons, the MessageBox.Show method will return a value • The value return is an “enumeration” type – which basically is an integer that has been given a “name” • The variable to which it is assigned is of type var • (You could also just use it in the if statement directly…why can we do that??) • It is compared to attributes of the DialogResult class

  13. Some Often Used Properties • Visible • Enabled

  14. Let’s Play Some More withOur Course Evaluation • Clicking the Stupendous radio button checks the Fit check box and disables it. Checking any other one undoes the above. • Clicking the Fabulous radio button causes the Fit check box to become invisible. Checking any other one undoes the above. • Clicking the picture will cause a message box asking if the picture should be removed. If yes is answered, remove the picture.

  15. Tooltips • Control needed so that other controls can display ToolTips • Not real sure why they did it this way. • Drag and drop the control on the form…It goes to the bottom. • Let’s add a ToolTip to our Evaluation • Hovering over the command button will pop a message that says “Hurry up and Press the Button!!”

  16. Menu Strip • Let’s add one to our Evaluation: • File -> Clear • Help • & thing – Keyboard Shortcut

  17. Open File Dialog • Pre-packaged process that allows a user to navigate through a Windows directory structure and select a file. • Drag from the Tools. Notice where it goes • Then used with some other event to get the file name of a file.

  18. Text Box • Single Line • Multi-Line

  19. Let’s Put This Together into a Program • Have a Menu with File->Open and File->Write • File->Write will be disabled until a File is opened. • Have a Multi-Line Text Box • Have a File Dialog where the user can select a file to bring into the Text Box to be Edited • Introduce new I/O methods (some of you used in Hangman!!) • StringVar = System.IO.File.ReadAllText (FileName) • System.IO.File.WriteAllText (FileName, StringVar)

  20. Timer • A control that “fires” an event at certain intervals • Let’s add an “auto save” to our Notepad program. • Drag and drop it from the toolbox and give it a name and set some properties. • Set up it’s event. • Start it up in your program. • Best bet is to stop it when the timer fires, do the work and then start it again when the work is done so that by chance it isn’t started twice.

  21. Resizing • Usually when changing the size of a form, you may want to reposition or change the size of the controls on the form. • The Resize Event Handler can be used to do that. • Add a Resize Event Handler to our Mini Text Editor so that as the size of the form changes, so does the editor window.

  22. Dynamically Creating Controls • Controls are just instances of classes • Which means you can create them on the fly within the program • But you really need to know what you are doing!! • Let’s add an Exit button to our Course Evaluation form one step at a time. • Create the button and give it a name (btnNew). • Locate and size it and give it a caption. • Add it to the form • this.Controls.Add(btnNew) • Add an Event Handler for it. • btnNew.Click +=new EventHandler (btnNew_Click);

  23. Event Handler Information • What is this “sender as object” thing? • The event handler has no clue what was done to trigger the event, only that it was called. • What Type of variable is an object • value or reference • So, what is being passed in • And what can we do with it. • What is this “e as EventArgs” thing? • Certain events may return arguments depending upon how they were fired. • We’ll look at one when we get to Web ASP.NET Development

  24. A Word on Event Handlers • Once an Event Handler is Written, it can be called by many different events • You can also have common code created in a separate method with event handlers for each unique event, and the event handlers then call the common code. • I’m for the second way…Why?

  25. Assignment 4 • Brought to you by Google • If you get an error message you don’t understand • If you don’t know how to do something • If you’re in need of information to do a research paper • GOOGLE IT • Literally ask the questions. 99% of the time you’ll get the correct answer back. • One site that I use ALL the time is • StackOverflow.Com

  26. Assignment 4 • Part 1 is due no later than Friday, November 6 by 11:59 PM and is worth 4 points. You can only get these points if you complete the work in Part 1 on time. • Part 2 is due no later than Wednesday, November 18 by 11:59 PM and includes 6 points (plus possibly 2 extra credit points).

More Related