//filename.cs using System; using System.Windows.Forms; [STAThread] public static void Main() { Application.Run(new Form1()); } }
|
|
- Dustin Mills
- 6 years ago
- Views:
Transcription
1 Lecture #10 Introduction Hand-Coding Windows Forms Applications The.NET Framework provide tools and components, such as dialog boxes, menus, buttons, and many other controls, that make up a standard Windows application user interface (UI). Fundamentally, these controls are just classes from the.net Framework class library for C# to reference with. When building a Windows Forms application, programmers start with creating the form, continue with adding components and controls, register events, and write custom codes to implement them. In one of previous lecture, you had learned to hand-code a generic Windows form using the following template code. //filename.cs public class Form1 : Form public Form1() To compile the code, use csc.exe /t:winexe filename.cs in the Visual Studio (Developer) Command Prompt. This template code will produce a blank windows form that looks: The above code starts with a using directive to eliminate the need of specifying fully qualified domain name (FQDN). Although the using directive does not give access to any namespaces that are nested in the namespace it specifies, it permit the use of types in a namespace so programmers do not have to write the long FQDN when referencing any member of the namespaces. The three most frequently used namespaces are: As in any generic C# code, there must be a default class. The following declares a class named Form1 that inherits the System.Windows.Forms.Form class through C# inheritance. Such inheritance enables programmers to create new classes that reuse, extend, and modify the behavior that is defined in the System.Windows.Forms.Form class. The Form class can be used to create standard, tool, borderless, and floating windows. You can also use the Form class to create modal windows such as a dialog box. Visual C# - Dr. Penn P. Wu 268
2 public class Form1 : Form Inside the Form1 class, define a default constructor that must have exactly the same name as the class. The default constructor is a no-argument constructor that will be automatically called, unless the programmer detour this routine, when a class instance is instantiated. The default constructor is often used to set the default values of the form, if any. public Form1() The Main() method is optionally (but preferably) defined in the section. When the STAThread Attribute is used, it changes the apartment state of the current thread to be single threaded. The single thread mode ensures the Main() method is the only one on the communication with the current thread. It blocks other threads that may want to communicate with the Main() via Component Object Model (COM). If this attribute is not present, the application uses the multithreaded apartment model, which is not supported for Windows Forms. The Run method of the Application class actually creates an instance of the form. The Application class provides static methods and properties to manage an application, such as methods to start and stop an application, to process Windows messages, and properties to get information about an application. The Main() method calls Run() to start the application, which creates the form. The above code provides the core mechanism to build a Windows form. In this lecture, the instructor will focus the discussion on the instantiation of form controls to enhance the functionality of the form. Controls Controls are objects of user interfaces within a windows form. Each type of control has its own set of properties, methods, and events that make it suitable for a particular purpose. Programmers can manipulate controls by writing code to add controls dynamically at run time. The following are commonly used controls. There controls are components on a Windows form for displaying information or accepting user inputs. Control Sample UI Descriptions Checkbox Allows multiple option Radio button Allow only one option Button Clickable button Textbox A single line text entry area ComboBox A drop down menu ListBox An area of list of options Most controls in.net derive from the System.Windows.Forms.Control class which defines the basic functionality of the controls including properties, methods, and events of the controls. Interestingly, most controls have individual classes under the System.Windows.Forms namespace. For example, you can eliminate the need to use fully Visual C# - Dr. Penn P. Wu 269
3 qualified name of the CheckBox class with the using directive of System.Windows.Forms namespace. The following is the syntax to create an instance of the CheckBox named checkbox1 in C#. CheckBox checkbox1; Use the new operator to actually create the checkbox1 object by invoking the CheckBox() constructor of the CheckBox class. checkbox1 = new CheckBox(); It is very common to declare and initialize the object in one single statement. CheckBox checkbox1 = new CheckBox(); The generic format of syntax is thus: controlname objectname = new controlname(); The implementation of Controls objects are centered on four aspects: property, method, event, and event handler. The.NET Framework provides properties, methods, and events. Programmers use them by learning the usage specified by the.net Framework. As to the event handler, the programmer create the code by studying the syntax. The following depicts these terms: Properties: All controls have a number of properties that are used to manipulate the behavior of the control. Methods: Methods are individually functional code blocks with unique identifier to perform a special task. They are defined in the Control classes to be inherited by other control classes. Events: The term event refers to user s activities such as clicking a button, moving the cursor, or dragging an object. The Control class defines a number of events and related supportive tools to help the programmers detect and respond to these events. Event handler: An event handler is a user-defined function, strictly using the syntax defined by the.net Framework, to respond to the raised event. A Label control is typically used to provide descriptive text that can be changed at the runtime programmatically. For example, you can use a Label to add descriptive text for a TextBox control to inform the user about the type of data expected in the control. The following statements declare and initialize the label1 object as a Label control. specifies the class, is the identifier, is the constructor that actually creates the control. Label label1 = new Label(); Similarly, the following declare and initialize a TextBox object named textbox1. With a text box, users can display, enter, or edit a text or numeric value. TextBox textbox1 = new TextBox(); After instantiation, the label1 object can use all members (properties, methods, and events) of the Label class. For example, the content of a Label is set through the Text property. The following statement sets the content of the label1 object to the string Welcome to CIS218!. label1.text = "Welcome to CIS218!"; Frequently, values of properties are initialized with the new operator following by a constructor of some class. For example, a Label control has a Size property that takes an Visual C# - Dr. Penn P. Wu 270
4 object initialized by the Size() structure. The following sets the size of label1 is set to 267 pixels wide by 40 pixels high. label1.size = new Size(267, 40); The Label class also provides a Location property, keeping track of where the Label is placed on the screen. The Location property accepts a Point() constructor (similar to a method), which is a member of the System.Drawing namespace. This Point() constructor is used frequently in Windows Forms applications to specify X and Y screen coordinates. In the example, the Location of the label1 is 12 pixels from the left and 56 pixels from the top of the main form. Here is how the Location property of the label1 label is set: label1.location = new Point(12, 56); The Hide() method conceals the control from the user. lable1.hide(); Additionally, a form s Controls object holds a collection of all of its controls. A controls must be added to a container, such as panel or a form, by the Add() method of the Controls object; otherwise, the control will not be present in the form or panel. In the following example, this is a keyword that typically represents the form. this.controls.add(label1); If the Windows application contains only one single form, then the this keyword may be omitted. The following statement adds label1 to the Form1 Controls collection object. Controls.Add(label1); The event model (which will be discussed in details in one of the later lecture) in the.net Framework is based on having an event delegate that connects an event with its handler. To raise an event, two elements are needed: a delegate and an optional class that holds the event data. Each control has its default events according to Visual.NET framework. Control Button TextBox Label CheckBox GroupBox RadioButton PictureBox DateTimePicker DataGrid Default event Click TextChanged Click CheckedChanged Enter CheckedChanged Click ValueChanged Navigate The.NET Framework provides a list of event specific to every kind of controls. For example, the TextChanged event occurs when the Text property value changes. However, the event must be registered to the Windows form before they can take effect. The syntax to register an event is: objectname.eventname += new EventHandler(this.functionName); The this keyword refers to the form. The EventHandler delegate represents a method that will handle an event which has no event data. A delegate is a class that can hold a reference to a method that match its signature; therefore, the programmers must rigorously abide by the format: new EventHandler(functionName), where functionname is the identifier of the Visual C# - Dr. Penn P. Wu 271
5 function that will be called when the event occurs. This function is known as event handler. The following demonstrates how to register a TextChanged event of the textbox1 control. textbox1.textchanged += new EventHandler(this.textBox1_TextChanged); The.NET Framework has a rigid syntax for event handler. The object that raises the event is called the event sender. The object that captures the event and responds to it is called the event receiver. Since the event sender class does not know which object or method will receive (handle) the events it raises, the event handler in the.net Framework have two parameters: the source that raised the event and the event argument data for the event. Because the object can be of any possible type, it is optimal to declare it as System.object type (a universal data type). The event arguments must be implemented by the EventArgs class or a class of similar kind. Microsoft also recommend to name the object sender and the EventArg e. private void functionname(object sender, EventArgs e) The following is a sample event handler that match with the above registration. The identifier (name) of the event handler is textbox1_textchanged. private void textbox1_textchanged(object sender, EventArgs e) label1.text = textbox1.text; It is necessary to note that some events, such as Paint, require a special delegate (PaintEventHandler) to handle event data. The following illustrates how to create an event handler for a button. The button, once being clicked, will write a message to the label1 control of the form. public class myform : Form private Label label1; private Button button1; public myform() // properties of the form this.size = new Size (250, 150); // define a Label control label1 = new Label (); label1.location = new Point (10, 10); label1.text = ""; label1.autosize = true; // add the control to the form Controls.Add (label1); button1 = new Button(); button1.text="click Me"; button1.location = new Point(10,80); button1.click += new EventHandler(this.button1_Click); Controls.Add(button1); Visual C# - Dr. Penn P. Wu 272
6 private void button1_click(object sender, EventArgs e) label1.text="you create a Form1_Click event handler!"; Application.Run(new myform()); A sample output looks: The following is a comple code that takes user input through a textbox. Depending on the button being clicked, either button1 or button2 will process the user input, and then display the final result in textbox1. public class Form1 : Form TextBox textbox1; public Form1() this.size = new Size (300, 150); textbox1 = new TextBox(); textbox1.location = new Point(10, 10); textbox1.size = new Size(265, 50); Controls.Add(textBox1); Button button1 = new Button(); button1.location = new Point(10, 60); button1.size = new Size(120, 30); button1.text = "Celsius to Fahrenheit"; button1.click += new EventHandler(this.button1_Click); Controls.Add(button1); Button button2 = new Button(); button2.location = new Point(150, 60); button2.size = new Size(120, 30); button2.text = "Fahrenheit to Celsius"; button2.click += new EventHandler(this.button2_Click); Controls.Add(button2); private void button1_click(object sender, EventArgs e) Visual C# - Dr. Penn P. Wu 273
7 // Celsius to Fahrenheit: double C = Convert.ToDouble(textBox1.Text); double F = ((C * 9) / 5) + 32; textbox1.text = F + ""; private void button2_click(object sender, EventArgs e) // Fahrenheit to Celsius: double F = Convert.ToDouble(textBox1.Text); double C = (F - 32) * 5 / 9; textbox1.text = C + ""; A sample output looks: and The following is a complete sample code that demonstrates how the above discussions work. public class Form1 : Form private TextBox textbox1; private Label label1; public Form1() textbox1 = new TextBox(); textbox1.size = new Size(260, 25); textbox1.location = new Point(10, 10); textbox1.multiline = true; textbox1.textchanged += new EventHandler(this.textBox1_TextChanged); Controls.Add(textBox1); label1 = new Label(); label1.size = new Size(260, 250); label1.location = new Point(10, 50); Controls.Add(label1); Visual C# - Dr. Penn P. Wu 274
8 private void textbox1_textchanged(object sender, EventArgs e) label1.text = textbox1.text; A sample output looks. In practice, programmers can always develop user-defined function in C# to deliver a special feature. For example, the instructor creates a new regular C# function named UpIt() which converts the all letters in a string to uppercase. By modifying the textbox1_textchanged() event handler, every letter typed into the textbox will be forced to displayed in uppercase. private void textbox1_textchanged(object sender, EventArgs e) label1.text = UpIt(textBox1.Text); private string UpIt(string s) s = s.toupper(); return s; Coding preferences Unlike the IDE, you have more flexibilities in a hand-coded project. You can choose to develop your coding preferences and totally ignore any parts that are deemed unnecessary in your project. For example, in the following code, you can choose to adopt the IDE ways to create an InitializeComponent() method which defines and creates the form components. You can also declare the Container object. Containers are objects that encapsulate and track zero or more components. In this context, containment refers to logical containment, not visual containment. You can use components and containers in a variety of scenarios, including scenarios that are both visual and not visual. The components in a container are tracked in a first-in, first-out list, which also defines the order of the components within the container. Added components are appended to the end of the list. //test.cs using System.ComponentModel; public class Form1 : Form Visual C# - Dr. Penn P. Wu 275
9 private Container components; private Label label1; public Form1() InitializeComponent(); private void InitializeComponent() // properties of the form Text = "My Sample Form"; Size = new Size (400, 200); // add a new component to the form components = new Container (); // define the new component as a Label control label1 = new Label (); // define properties of the label label1.location = new Point(12, 56); label1.text = "Welcome to CIS218!"; label1.size = new Size(267, 40); label1.autosize = true; label1.font = new Font("Arial", 24, FontStyle.Bold); label1.tabindex = 0; label1.anchor = AnchorStyles.None; label1.textalign = ContentAlignment.MiddleCenter; // add the control to the form Controls.Add (label1); Compile and test this code, the output looks: The AutoSize property accepts a Boolean value, which tells whether a Label can automatically resize itself to accommodate its contents. For instance, in this program the actual size of the label1 contents exceeds its set size from the previous statement, so the label must grow to fully show the entirety of its text. Here s how the AutoSize property of the label1 label is set. label1.autosize = true; A Label control can change its typeface through the Font property. It accepts a Font object. The constructor for the Font object in the following statement accepts three parameters: the font name, the font size, and a font style. The font style is from the FontStyle enum in the Visual C# - Dr. Penn P. Wu 276
10 System.Drawing namespace. By the way, the System.Drawing namespace provides access to the operating system graphics functionality. label1.font = new Font("Arial", 24, FontStyle.Bold); When there are multiple controls on a form, each control that can accept input can have its TabIndex property set. This permits the user to press the Tab key to move to the next control on the form, based on TabIndex. In this example, the TabIndex of label1 is set to 0. This is for illustrative reasons only. The fact is that a Label can never be a tab stop because it doesn't normally accept user input. Furthermore, for this program, this is the only control on the form. There isn't any other control to tab to. Here s how the TabIndex property of the label1 label is set: label1.tabindex = 0; Window layout in Windows Forms is done with the techniques of anchoring and docking. Docking specifies the location of the form that a control will reside in. Anchoring tells which side of a control will be attached to another control. These two techniques permit any type of layout a window design would need. The following code line states that label1 will not be anchored. It uses the AnchorStyles enumeration to set the Anchor property. label1.anchor = AnchorStyles.None; The horizontal alignment of a Label may be set with the TextAlign property, which accepts a ContentAlignment enumeration. The following statement sets the horizontal alignment of label1 to be centered between its left and right margins. label1.textalign = ContentAlignment.MiddleCenter; In the above code, the Form1 constructor calls the InitializeComponent() method, which creates and instantiates the Windows Forms Controls and Forms that make up the graphical interface of this program. public Form1() InitializeComponent(); The following segment instantiate the components and label1 fields as objects. private void InitializeComponent()... You can also create the form components in the Form1() constructor. In this case, you do not need the optional InitializeComponent() method. For example, in the Form1 constructor, create the button and set its Size, Location and Text properties. public Form1() button1 = new Button(); button1.size = new Size(25, 100); button1.location = new Point(10, 10); button1.text = "Click me"; this.controls.add(button1); The following is a simple but complete code that is enough to create a Windows form. In this class, you can consider using the following as template. Visual C# - Dr. Penn P. Wu 277
11 public class Form1 : Form public Form1() Since Form1 is a Form object (because the new Form1() statement), it is considered the main form. // properties of the form this.text = "My Sample Form"; this.size = new Size(400, 200); All forms and controls have Text properties. A Form object sets its title bar with the value of the Text property. This example sets the form s title to My Sample Form. The Size property set the width and height of this form. Another handcoding method Forms can also be created by creating a new class that derives from the Form class. There are two kinds of forms, modal and modeless forms. Modal forms are those forms to which the user must respond before being allowed to work on any other form. Modeless forms are those forms that do not need a response immediately. The user can ignore the form and continue to work on same application or another form. The user can respond to this form whenever it is convenient. Forms are used to display different kinds of windows, message box, and dialog box. The following demonstrates the general syntax for creating a form. Note that Form1 is the name of the class and myform is the identifier of the form. public class Form1 : Form Form1 myform = new Form1(); Application.Run(myForm); A more flexible way, which the instructor recommends is: using System.ComponentModel; public class Form1 : Form public Form1() Visual C# - Dr. Penn P. Wu 278
12 The outputs of the above two sample codes are exactly the same which looks: Similar to the first method, this second method (class-based) use the following code segment to handle the formation of forms and their components. However, the class-based method required an object as delegate. You do so by using the following line: Form1 f = new Form1(); The object, f, then represents the form, so all the attributes the forms has must be associated to it with a dot. For example, the following specifies the title of the form. f.text = "My Sample Form"; All the components, such as labels, buttons, checkbox, must be declared. For example, Label label1 = new Label(); The control of the form also needs to be associated to the object f. For example, f. Controls.Add (label1); The first example can then be re-written as: public class Form1:Form Form1 f = new Form1(); f.text = "My Sample Form"; f.size = new Size (400, 200); Visual C# - Dr. Penn P. Wu 279
13 // define the new component as a Label control Label label1 = new Label(); // define properties of the label label1.location = new Point (12, 56); label1.text = "Welcome to CIS218!"; label1.size = new Size (267, 40); label1.autosize = true; label1.font = new Font ("Arial", 24, FontStyle.Bold); label1.tabindex = 0; label1.anchor = AnchorStyles.None; label1.textalign = ContentAlignment.MiddleCenter; // add the control to the form f. Controls.Add (label1); Application.Run(f); As the output still is: The following code demonstrates how to create a second form with a button clicking on the primary form. The button1 is a component of Form1 class. Its event handler, button1_click() method, is responsible for creating the secondary form (named form2 ) only when button1 is clicked. public class Form1 : Form public Form1() this.size = new Size (250, 250); Button button1 = new Button(); button1.location = new Point(10, 10); button1.size = new Size(120, 50); button1.text = "Click Me"; button1.click += new EventHandler(this.button1_Click); Controls.Add(button1); private void button1_click(object sender, EventArgs e) Form form2 = new Form(); // create another form instance form2.text = "The second form"; this.size = new Size(200, 50); form2.show(); Visual C# - Dr. Penn P. Wu 280
14 Test the executable file. A sample output looks: to For those who are accustomed to the Visual Studio IDE may find the above code very different from those automatically generated by the IDE. This is because Microsoft uses a different logic to create the form. Compare the following two codes, they both create the same form (they generate the same result). Visual C# creates a constructor called Form1(), and later uses the following code to call the constructor. The class-based method, alternatively, instantiate an object using: Form1 form1 = new Form1(); and then call the following. Application.Run(form1); The Form1() constructor, in turn, calls another constructor InitialieComponent() to define all the components of the form. private void InitializeComponent() As an efficient programmer, you can let the Main() function takes the lead to create the form and all the components of the form. // Method 1 visual c# using System.ComponentModel; public class Form1 : Form private Container components; private Label label1; public Form1() InitializeComponent(); private void InitializeComponent() //Method 2 hand coded using System.ComponentModel; public class MyWin : Form MyWin Form1 = new MyWin(); // properties of the form Form1.Size = new Size (150, 75); // define a Label control Label label1 = new Label(); label1.location = new Point(10, 10); Visual C# - Dr. Penn P. Wu 281
15 // properties of the form Size = new Size (150, 75); // add a new component to the form components = new Container (); // define a Label control label1 = new Label (); label1.location = new Point(10, 10); label1.text = "Welcome to CIS218!"; label1.autosize = true; label1.text = "Welcome to CIS218!"; label1.autosize = true; // add the control to the form Form1.Controls.Add(label1); Application.Run(Form1); // add the control to the form Controls.Add (label1); Both codes produce the same output similar to the following. In this class, you have the option to either go with Microsoft s way, or take the efficient way, although the instructor chooses the latter (class-based). Textbox To define a textbox in a form use the syntax of: TextBox textboxname = new TextBox(); textboxname.propertyname = "Values "; FormName.Controls.Add(textboxName); FormName can be either the name of the form (e.g. Form1 ) or the this keyword if the control is created inside the form s class. See the following code for illustration. Another code example in a later section will demonstrate how to use the form name to identify a specific form. public class Form1 : Form public Form1() // properties of the form this.size=new Size(200, 150); // define the first textbox TextBox textbox1=new TextBox(); textbox1.text = "Your first name here!"; textbox1.size = new Size(120,40); textbox1.location = new Point(10,10); this.controls.add(textbox1); // with this keyword Visual C# - Dr. Penn P. Wu 282
16 The result is: // define the second textbox TextBox textbox2 = new TextBox(); textbox2.location = new Point(10,40); textbox2.size=new Size(120,240); Controls.Add(textBox2); // without this keyword Notice that each textbox must have an individual set of definition. For details about Visual C# TextBox control s properties, visit (available as of Feb 2011). You can skip the FormName part if you declare the control inside the form s class. For example, public class Form1 : Form public Form1() // properties of the form TextBox textbox1 = new TextBox(); textbox1.location = new Point(10,10); Controls.Add(textBox1); // FormName is skipped Checkbox To define a checkbox in a form use the syntax of: CheckBox checkboxname = new CheckBox(); checkboxname.propertyname = "Values "; FormName.Controls.Add(checkboxName); Visual C# - Dr. Penn P. Wu 283
17 FormName can be either the name of the form (e.g. Form1 ) or the this keyword if the control is created inside the form s class. Notice that each checkbox must have an individual set of definition. For details about Visual C# TextBox control s. Visit for a list of properties. The following example, unlike, the one for TextBox, demonstrates the use of form name as identification to specify which form the Controls object should add the control to. The result is: using System.ComponentModel; public class Form1 : Form Form1 myform = new Form1(); // properties of the form myform.size = new Size (210, 150); // define a label Label lbl1=new Label(); lbl1.text="check the city you visited recently:"; lbl1.location = new Point (10, 10); lbl1.autosize = true; myform.controls.add(lbl1); // define the first checkbox CheckBox chk1=new CheckBox(); chk1.text="tokyo"; chk1.location = new Point(10, 30); myform.controls.add(chk1); // define the 2nd checkbox CheckBox chk2=new CheckBox(); chk2.text="hong Kong"; chk2.location = new Point(10, 50); myform.controls.add(chk2); // define the 3rd checkbox CheckBox chk3=new CheckBox(); chk3.text="taipei"; chk3.location = new Point(10, 70); myform.controls.add(chk3); Application.Run(myForm); Visual C# - Dr. Penn P. Wu 284
18 Radio Button To define a radio button in a form use the syntax of: RadioButton RadioButtonName = new RadioButton(); RadioButtonName.PropertyName = "Values "; FormName.Controls.Add(RadioButtonName); FormName can be either the name of the form (e.g. Form1 ) or the this keyword if the control is created inside the form s class. Notice that each radio button must have an individual set of definition. For details about Visual C# TextBox control s. Visit for a list of properties. In the following example, rdb1, rdb2, and rdb3 are three radio buttons and each represents a special option: Chemistry, Biology, and Physics. However, they share the same event handler radiobutton_checkchanged which is an individual method that will respond to the CheckChanged event, if triggered. public class Form1 : Form private Label lbl2; public Form1() // properties of the form Size=new Size(200, 200); Label lbl1=new Label(); lbl1.text="what is your favorite subject?"; lbl1.location=new Point(10, 10); lbl1.autosize = true; Controls.Add(lbl1); lbl2=new Label(); // to display outputs lbl2.location=new Point(10, 100); lbl2.autosize = true; Controls.Add(lbl2); RadioButton rdb1=new RadioButton(); rdb1.text="chemistry"; rdb1.location=new Point(10, 30); rdb1.checkedchanged += new EventHandler(radioButton_CheckedChanged); Controls.Add(rdb1); RadioButton rdb2=new RadioButton(); rdb2.text="biology"; rdb2.location=new Point(10, 50); rdb2.checkedchanged += new EventHandler(radioButton_CheckedChanged); Controls.Add(rdb2); RadioButton rdb3=new RadioButton(); rdb3.text="physics"; rdb3.location=new Point(10, 70); Visual C# - Dr. Penn P. Wu 285
19 rdb3.checkedchanged += new EventHandler(radioButton_CheckedChanged); Controls.Add(rdb3); private void radiobutton_checkedchanged(object sender, EventArgs e) lbl2.text = "You picked " + ((RadioButton) sender).text; A sample output looks: and ListBox and ComboBox Both ListBox and ComboBox do much the same thing, but there are a few nuiances. More than one item in a ListBox is visible, unlike the ComboBox, which has only the selected item visible unless the IsDropDownOpen property is true. The SelectionMode property determines whether more than one item in the ListBox is selectable at a time. In ListBox you can make multiple selections and listbox is multilined. Generally you use ComboBox when you expect the user to give a single answer and use ListBox when you expect the user to (possibly) select more than one answer. To define a listbox in a form use the syntax of: ListBox ListBoxName = new ListBox(); ListBoxName.PropertyName = "Values "; FormName.Controls.Add(ListBoxName); Notice that each ListBox must have an individual set of definition. For details about Visual C# TextBox control s. Visit for a list of properties. To define a combobox in a form use the syntax of: ComboBox ComboBoxName = new ComboBox(); ComboBoxName.PropertyName = "Values "; FormName.Controls.Add(ComboBoxName); Notice that each ComboBox must have an individual set of definition. For details about Visual C# TextBox control s. Visit for a list of properties. Visual C# - Dr. Penn P. Wu 286
20 ListBox and ComboBox has the following methods: The Items.Add() method adds options to the list. The Items.Insert() method inserts new option(s) to the list. The Items.Remove() method removes option(s) from the list. ListBox and ComboBox uses the following event handlers: SelectedIndexChanged() The following examples demonstrate how ListBox and ComboBox works. // Listbox public class Form1 : Form public Form1() Size=new Size(150,150); ListBox lsb1 = new ListBox(); lsb1.location=new Point(10,10); lsb1.items.add("apple"); lsb1.items.add("orange"); lsb1.items.add("banana"); lsb1.selecteditem="banana"; lsb1.width=100; lsb1.height=25; Controls.Add(lsb1); ListBox lsb2 = new ListBox(); lsb2.location=new Point(10,40); lsb2.items.add("hbo"); lsb2.items.add("cnn"); lsb2.items.add("pbs"); lsb2.items.add("fox"); lsb2.items.add("abc"); lsb2.width=100; lsb2.height=50; Controls.Add(lsb2); //ComboBox public class Form1 : Form public Form1() Size=new Size(150,150); ComboBox cbo1 = new ComboBox(); cbo1.location=new Point(10,10); cbo1.items.add("apple"); cbo1.items.add("orange"); cbo1.items.add("banana"); cbo1.selecteditem="banana"; cbo1.width=100; cbo1.height=25; Controls.Add(cbo1); ComboBox cbo2 = new ComboBox(); cbo2.location=new Point(10,40); cbo2.items.add("hbo"); cbo2.items.add("cnn"); cbo2.items.add("pbs"); cbo2.items.add("fox"); cbo2.items.add("abc"); cbo2.selecteditem="pbs"; cbo2.width=100; cbo2.height=50; Controls.Add(cbo2); You can use the the SelectedItem property to specify the default selection. Visual C# - Dr. Penn P. Wu 287
21 Menus (MenuItem) Menus are one of the primary means of selecting a program's available options. They're similar to controls, but their function is specialized to invoking selected features of a program. The following table shows how to create and use Windows Forms Menus. Menu Control ContextMenu MainMenu MenuItem What It Does Menus that are invoked by right-clicking a control. Resides at the top of a form, below its title bar. It is the root menu of an entire menu hierarchy. Sub-menus of a MainMenu and other MenuItems. They form the branches and nodes of the menu hierarchy. MenuItems are used to invoke some capability of a program. For example, public class Form1 : Form MainMenu mainmenu1; public Form1() // properties of the form // define form properties Text = "My Sample Menu"; Size = new Size (200, 200); // add main to form mainmenu1 = new MainMenu(); MenuItem File = mainmenu1.menuitems.add("&file"); File.MenuItems.Add(new MenuItem("&New")); File.MenuItems.Add(new MenuItem("&Open")); File.MenuItems.Add(new MenuItem("&Exit")); MenuItem About = mainmenu1.menuitems.add("&about"); About.MenuItems.Add(new MenuItem("&About")); this.menu=mainmenu1; Test the code, and the output looks: Visual C# - Dr. Penn P. Wu 288
22 Each MenuItem has a Text and Index property. The Text property sets the text that appears on screen. The & character in front of a letter in the text makes the following character a shortcut for the menu item. In the case of the File menu, the user can press the Alt+F keys to open the menu. The Index property is a zero-based position identifier for the menu. In this case, the first menu item in the File menu is the New menu item at index 0. The last is the Exit menu item at index 2. Menu items are tied to actions the same as Button controls. A menu hierarchy is built from the bottom up. The example shows the New, Open, and Exit submenu items being added to the File menu s MenuItems collection. The File menu is added to the MainMenu -- mainmenu1. Then the form s Menu property is set with the mainmenu1. Just add an EventHandler delegate with an event handler method parameter to the menu item Click event. Each of the New, Open, and Exit menu items has an event handler that invokes a Windows Forms MessageBox. DateTimePicker The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format. The DateTimePicker control makes it easy to work with dates and times because it handles a lot of the data validation automatically. When used to represent a date, the DateTimePicker control appears in two parts: a drop-down list with a date represented in text, and a calendar that appears when you click the down-arrow next to the list. The calendar looks like the MonthCalendar control, which can be used for selecting multiple dates. The following is a sample output of the code below it. The following code starts with creating an new instance of a DateTimePicker control and initializes it. The MinDate property gets or sets the minimum date and time that can be selected in the control. The MaxDate property gets or sets the maximum date and time that can be selected in the control. public class Form1 : Form DateTimePicker datetimepicker1; public Form1() datetimepicker1 = new DateTimePicker(); datetimepicker1.location = new Point(10, 10); // Set the MinDate and MaxDate. datetimepicker1.mindate = new DateTime(2000, 1, 1); datetimepicker1.maxdate = DateTime.Today; Visual C# - Dr. Penn P. Wu 289
23 datetimepicker1.valuechanged += new EventHandler(this.DateTimePicker1_ValueChanged); Controls.Add(dateTimePicker1); private void DateTimePicker1_ValueChanged(Object sender, EventArgs e) this.text = datetimepicker1.value + ""; The DateTimePicker can work with the ValueChanged event which occurs when the Value property of the DateTimePicker changes. However, this event is not raised when the entered date is earlier than MinDateTime or later than MaxDateTime. The above example use the following event handler to report on the occurrence of the ValueChanged event. This report helps you to learn when the event occurs and can assist you in debugging. private void DateTimePicker1_ValueChanged(Object sender, EventArgs e) The control s CustomFormat property is set to be display the date values in the format of MMMM dd, yyyy dddd. The ShowCheckBox property is set to true so that the control displays a CheckBox, and the ShowUpDown property is set to true so that the control is displayed as a spin button control. The following are sample code snippets that demonstrate how to customize the DateTimePicker object. // Set the CustomFormat string. datetimepicker1.customformat = "MMMM dd, yyyy - dddd"; datetimepicker1.format = DateTimePickerFormat.Custom; // Show the CheckBox and up-down control. datetimepicker1.showcheckbox = true; datetimepicker1.showupdown = true; You can change the look of the calendar portion of the control by setting the CalendarForeColor, CalendarFont, CalendarTitleBackColor, CalendarTitleForeColor, CalendarTrailingForeColor, and CalendarMonthBackground properties. Details are available at With the use of Globalization namespace, you can convert the date value from Western calendar to a foreign calendar, such as Chinese lunar calendar. using System.Globalization; The ChineseLunisolarCalendar class can represent time in divisions, such as months, days, and years. Years are calculated using the Chinese calendar, while days and months are calculated using the lunisolar calendar. In the following code snippets, dt is a DateTime instance that will get the date and time value from the DateTimePicker. The ChineseLunisolarCalendar class then converts the date values to the equivalent ones in Visual C# - Dr. Penn P. Wu 290
24 Chinese calendar and stores them in three int variables: d, m, y. The value of dt is reassigned to new DateTime(y, m, d). DateTime dt = datetimepicker1.value; ChineseLunisolarCalendar ch = new ChineseLunisolarCalendar(); int d = ch.getdayofmonth(dt); // convert to Chinese value int m = ch.getmonth(dt); // convert to Chinese month int y = ch.getyear(dt); // convert to Chinese year dt = new DateTime(y, m, d); The MessageBox A MessageBox is a GUI object that can contain text, buttons, and symbols that inform and instruct a user. You cannot create a new instance of the MessageBox class because its constructor is not public. Instead, you use the static class method Show() to display a MessageBox. The MessageBox class contains 12 overloaded versions of the Show() method. You have learned to use the MessageBox class without creating Windows form. For example, public class Form1 MessageBox.Show("Hi!"); In this lecture, you should learn to incorporate message box with Windows forms. Consider the following code, which has four parameters. public class mymsg MessageBox.Show("How are you?", "F201", MessageBoxButtons.YesNo, MessageBoxIcon.Question ); The output looks: The three parameters are: The first is the text to be displayed in the MessageBox. The second is the title of the form that goes into the MessageBox title bar. The third is the button type of the MessageBox. The forth specifies the type of icon. Visual C# - Dr. Penn P. Wu 291
25 In fact, the syntax is: MessageBox.Show(String1, String2, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions); String1 is always the text to be display in the MessageBox, while String2 is option and is the title of the MessageBox A MessageBox has an OK button by default. However, you can use the following options: Member Name Description AbortRetryIgnore Create Abort, Retry, and Ignore buttons OK Create OK button OKCancel Create OK and Cancel buttons RetryCancel Create Retry and Cancel buttons YesNo Create Yes and No buttons YesNoCancel Create Yes, No, and Cancel buttons A MessageBox can have the following icons: Asterik Error Exclamation Hand Information None Question Stop Warning You can also specify what button to be the default if a MessageBox has more than one buttons. For example, MessageBoxDefaultButton.Button3 You can specify other MessageBox options using MessageBoxOptions. They are: Member Name Description DefaultDesktopOnly The message box appears on the active desktop RightAlign The message box text is right-aligned RtlReading The message box text is displayed with right-to-left reading order ServiceNotification The message box appears on the active desktop MessageBox are frequently used with the DialogResult property. The dialog result of a form is the value that is returned from the form when it is displayed as a modal dialog. If the form is displayed as a dialog box, setting this property with a value from the DialogResult enumeration sets the value of the dialog result for the form, hides the modal dialog, and returns control to the calling form. The DialogResult property is typically set by the DialogResult property of a Button control on the form. When the user clicks the Button control, the value assigned to the DialogResult Visual C# - Dr. Penn P. Wu 292
26 property of the Button is assigned to the DialogResult property of the form. The following code demonstrates how to use the DialogResult property to determine the option picked by a user in order to respond. class MyMsg // create an object to keep dialog result DialogResult dr = MessageBox.Show("Are you a student?", "My Question", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == DialogResult.Yes) MessageBox.Show("You click Yes."); else if (dr == DialogResult.No) MessageBox.Show("You are not!"); else MessageBox.Show("Why did you cancel it?"); The output looks: When a form is displayed as a modal dialog box, clicking the Close button (the button with an X in the top-right corner of the form) causes the form to be hidden and the DialogResult property to be set to DialogResult.Cancel. The Close method is not automatically called when the user clicks the Close button of a dialog box or sets the value of the DialogResult property. Instead, the form is hidden and can be shown again without creating a new instance of the dialog box. Because of this behavior, you must call the Dispose method of the form when the form is no longer needed by your application. The following example simply use an environment variable to retrieve values from the operationg system and then display the result in a message box. class MyMsg MessageBox.Show( Environment.GetFolderPath(Environment.SpecialFolder.Personal), "My Documents Folder"); Visual C# - Dr. Penn P. Wu 293
27 The output looks: The following is a complete code that takes user input from a textbox control and then passes the output to a message box. public class Form1 : Form TextBox textbox1; public Form1() this.width=240; this.height=150; Label label1 = new Label(); label1.text = "What is your name?"; label1.location = new Point(10, 10); label1.size = new Size(200, 30); textbox1 = new TextBox(); textbox1.location = new Point(10, 40); textbox1.size = new Size(200, 60); Button button1 = new Button(); button1.text = " OK "; button1.size = new Size(80, 25); button1.location = new Point(this.Width-110, this.height-70); button1.click += new EventHandler(this.button1_Click); this.controls.add(label1); this.controls.add(textbox1); this.controls.add(button1); public void button1_click(object sender,eventargs e) MessageBox.Show("Welcome " + textbox1.text); Compile and test the program. A sample output looks: Visual C# - Dr. Penn P. Wu 294
28 and Common Event Handler for windows forms A keyboard is a hardware object attached to the computer. By default, it is used to enter recognizable symbols, letters, and other characters on a control. Each key on the keyboard displays a symbol, a letter, or a combination of those, to give an indication of what the key could be used for. The user typically presses a key, which sends a signal to a program. The signal is analyzed to find its meaning. If the program or control that has focus is equipped to deal with the signal, it may produce the expected result. If the program or control cannot figure out what to do, it ignores the action. Each key has a code that the operating system can recognize. Message KeyDown Usage When a keyboard key is pressed, a message called KeyDown is sent. KeyDown is a KeyEventArgs type interpreted through the KeyEventHandler class. This event is defined as follows: private void Control_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) This event is carried by the KeyEventArgs class defined in the System.Windows.Forms namespace. When you initiate this event, its KeyEventArgs argument provides as much information as possible to implement an appropriate behavior. KeyUp The KeyUp message is sent when the user releases the key. The event is initiated as follows: private void Control_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) Like KeyDown, KeyUp is a KeyEventArgs type. KeyPress When the user presses a key, the KeyPress message is sent. Unlike the other two keyboard messages, the key pressed for this event should (must) be a character key. The event is initiated as follows: private void Control_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) The KeyPress event is carried by a KeyPressEventArgs type. The Handled property identifies whether this event was handled. Visual C# - Dr. Penn P. Wu 295
29 The KeyChar property identifies the key that was pressed. It must be a letter or a recognizable symbol. Lowercase alphabetic characters, digits, and the lower base characters such as ;, [ ] - = / are recognized as they are. For an uppercase letter or an upper base symbol, the user must press Shift + the key. The character would be identified as one entity. This means that the symbol % typed with Shift + 5 is considered as one character. For example, public class Form1 : Form public Form1() Size=new Size(150,150); this.keydown += new KeyEventHandler(this.Form1_OnKeyDown); private void Form1_OnKeyDown(object sender, KeyEventArgs e) MessageBox.Show("Hi"); Press any key, and watch the form changes to Another example, public class Form1 : Form public Form1() this.keyup += new KeyEventHandler(OnKeyPress); public void OnKeyPress(object sender, KeyEventArgs e) this.size=new Size(150, 150); Visual C# - Dr. Penn P. Wu 296
30 Press any key, the size of form shrinks from the default (300, 300) to (150, 150). The mouse is another object that is attached to the computer allowing the user to interact with the machine. The mouse and the keyboard can each accomplish some tasks that are not normally available on the other or both can accomplish some tasks the same way. The mouse is equipped with two, three, or more buttons. When a mouse has two buttons, one is usually located on the left and the other is located on the right. When a mouse has three buttons, one usually is in the middle of the other two. A mouse can also have a round object referred to as a wheel. The mouse is used to select a point or position on the screen. Once the user has located an item, which could also be an empty space, a letter or a word, he or she would position the mouse pointer on it. To actually use the mouse, the user would press either the left, the middle (if any), or the right button. If the user presses the left button once, this action is called Click. If the user presses the right mouse button, the action is referred to as Right-Click. If the user presses the left button twice and very fast, the action is called Double-Click. If the mouse is equipped with a wheel, the user can position the mouse pointer somewhere on the screen and roll the wheel. This usually causes the document or page to scroll up or down, slow or fast, depending on how it was configured. Message MouseEnter Usage Before using a control using the mouse, the user must first position the mouse on it. When this happens, the control fires a MouseEnter event. This event is initiated as follows: private void Control_MouseEnter(object sender, System.EventArgs e) This event is carried by an EventArgs argument but doesn't provide much information, only to let you know that the mouse was positioned on a control. MouseMove Whenever the mouse is being moved on top of a control, a mouse event is sent. This event is called MouseMove and is of type MouseEventArgs. It is initiated as follows: private void Control_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) Visual C# - Dr. Penn P. Wu 297
31 To implement this event, a MouseEventArgs argument is passed to the MouseEventHandler event implementer. The MouseEventArgs argument provides the necessary information about the event such as what button was clicked, how many times the button was clicked, and the location of the mouse. MouseHover If the user positions the mouse on a control and hovers over it, a MouseHover event is fired. This event is initiated as follows: private void Control_MouseHover(object sender, System.EventArgs e) This event is carried by an EventArgs argument that doesn't provide further information than the mouse is hovering over the control. MouseDown Imagine the user has located a position or an item on a document and presses one of the mouse buttons. While the button is pressed and is down, a button-down message is sent. This event is called MouseDown and is of type MouseEventArgs and it is initiated as follows: private void Control_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) Like the other above mouse move event, the MouseDown event is carried by a MouseEventArgs argument. MouseUp After pressing a mouse button, the user usually releases it. While the button is being released, a button-up message is sent and it depends on the button, left or right, that was down. The event produced is MouseUp and it is initiated as follows: private void Control_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) Like the MouseDown message, the MouseUp event is of type MouseEventArgs which is passed to the MouseEventHandler for processing. For example, public class Form1 : Form public Form1() this.mouseup += new MouseEventHandler(OnMouseup); Visual C# - Dr. Penn P. Wu 298
32 public void OnMouseup(object sender, MouseEventArgs e) this.size=new Size(100, 100); MouseLeave When the user moves the mouse pointer away from a control, the control fires a MouseLeave event. This event is initiated as follows: private void Form1_MouseLeave(object sender, System.EventArgs e) For example, public class Form1 : Form public Form1() this.backcolor = Color.Yellow; this.mouseup += new MouseEventHandler(this.Form1_OnMouseup); public void Form1_OnMouseup(object sender, MouseEventArgs e) this.backcolor = Color.White; Move the mouse cursor and watch the form changes its background color from yellow to white. In the following example, the MouseEventArgs e represent the mouse event. Its X and Y properties holds the x- and y-coordinate of the current mouse location. When the mouse cursor moves inside the form, the x and y values is displayed in the titlebar of the form. public class Form1 : Form public Form1() this.mousemove += new MouseEventHandler(this.Form1_OnMouseMove); public void Form1_OnMouseMove(object sender, MouseEventArgs e) Visual C# - Dr. Penn P. Wu 299
33 this.text = "Current Position (" + e.x + ", " + e.y +")"; Click on the form, move the mouse and then click again. Another example is to make a text (e.g. CIS218) move with the mouse cursor. public class Form1 : Form Label label1; public Form1() label1 = new Label(); label1.text = "CIS218!"; Controls.Add(label1); this.mousemove += new MouseEventHandler(this.Form1_OnMouseMove); ~Form1() // destructor public void Form1_OnMouseMove(object sender, MouseEventArgs e) Cursor = Cursors.Hand; // set different cursor type label1.location = new Point(e.X, e.y); The trick is the label1.location = new Point(e.X, e.y); statement which sets the x- and y- values of the label1 object to those of the mouse cursor. Move the mouse cursor around inside the form. A sample output looks: Visual C# - Dr. Penn P. Wu 300
34 Review Questions 1. Given the following code segment, which is the correct way to create an instance of the Form1 class? public class Form1 : Form A. Application.Run(new Form1); B. Application.Run(Form1()); C. D. Application.Run(new Form1(Form)); 2. Given the following code segment, which is the constructor that actually creates a Label control? A. Label B. label1 C. new D. Label() Label label1 = new Label(); 3. Which is the correct to specify the size of a form? A. this.size = new Size (150, 75); B. this,size = 150, 75; C. Form.Width=150; Form.Height=75; D. Form Size = new Size (150, 75); 4. Which is the correct way to register a TextChanged event to a TextBox object named "textbox1" and will call an event handler named "textbox1_textchanged)? A. textbox1.textchanged += new EventHandler(this.textBox1_TextChanged); B. textbox1.textchanged = new EventHandler(this.textBox1_TextChanged); C. textbox1.textchanged = new EventHandler(this(textBox1_TextChanged)); D. textbox1.textchanged += new EventHandler(this.textBox1_TextChanged()); 5. Given the following code segment, which is the statement you need to add in order to display the Label control on the Windows form? public class Form1 : Form public Form1() Label label1 = new Label(); label1.text = "Show me"; label1.location = new Point(10, 10); label1.autosize = true; A. label1.enabled = true; B. label1.show(); C. label1.visible = true; Visual C# - Dr. Penn P. Wu 301
35 D. Controls.Add(label1); 6. Given the following code, the field is a Windows Forms Label Control. public class Form1 : Form private Container components;... A. Container B. Form1 C. components D. label1 private Label 7. Given the following code,. label1; A. Main() runs the program by calling the static Run()method B. The Run() method's parameter is a new instance of the Form1 class C. Run() is a static method D. All of the above 8. Given the following code segment, which statement best explain why the declaration and instantiation of the Label controls are placed at two different lines? public class Form1 : Form Label label1; public Form1() label1 = new Label(); public changeit() label1.text = "Changed"; A. "label1" is declared as an empty object, so it can be instantiated on demand to save some memory space. B. "label1" is declared as a member of the "Form1" class, so the changeit() function of the "Form1" class can access it. C. "label1" is declared as a subclass, so it can inherit the "Form1" class. D. It does not have any effect and will not make any difference in this case. 9. Given the following code segment, which can add an option "New" to the "menuitem1" menu? mainmenu1 = new MainMenu(); MenuItem menuitem1 = mainmenu1.menuitems.add("&file"); A. menuitem1.menuitems.add(new MenuItem("&New")); B. menuitem1.menuitems.add("&new"); Visual C# - Dr. Penn P. Wu 302
36 C. menuitem1.menuitems.add(menuitem("&new")); D. menuitem1.menuitems.add(menuitem(new ("&New"))); 10. Given the following code segment, which statement is correct? MessageBox.Show("CIS218", "How are you?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); A. "How are you?" is the text to be displayed in the message Box B. "CIS218" is the title of the message box C. The message box has only one button that displays "YesNo". D. The MessageBoxIcon.Question part specifies that the message box must include a question mark icon. Visual C# - Dr. Penn P. Wu 303
37 Lab #10 Hand-Coding Windows Forms Applications Learning Activity #1: 1. Create a new directory called C:\CIS218 if it does not exist. 2. Launch the Developer Command Prompt. 3. In the prompt, type cd c:\cis218 and press [Enter] to change to the C:\CIS218 directory. 4. In the prompt, type notepad lab10_1.cs and press [Enter] to use Notepad to create a new source file called lab10_1.cs with the following contents: public class Form1 : Form private TextBox textbox1; private Label label1; public Form1() textbox1 = new TextBox(); textbox1.size = new Size(260, 25); textbox1.location = new Point(10, 10); textbox1.multiline = true; textbox1.textchanged += new EventHandler(this.textBox1_TextChanged); Controls.Add(textBox1); label1 = new Label(); label1.size = new Size(260, 250); label1.location = new Point(10, 50); Controls.Add(label1); private void textbox1_textchanged(object sender, EventArgs e) label1.text = UpIt(textBox1.Text); private string UpIt(string s) s = s.toupper(); return s; 5. Compile and test the program. A sample output looks: Visual C# - Dr. Penn P. Wu 304
38 6. Download the assignment template, and rename it to lab1.doc if necessary. Capture a screen shot similar to the above and paste it to the Word document named lab10.doc (or.docx). Learning Activity #2: 1. Under the C:\cis218 directory, use Notepad to create a new source file called lab10_2.cs with the following contents: public class Form1 : Form private Label lbl2; public Form1() // default constructor // properties of the form this.size = new Size(300, 200); this.text = "A hand-coded form"; this.cursor = Cursors.Hand; this.backcolor = Color.Pink; // background color Label lbl1=new Label(); lbl1.text="what is your favorite subject?"; lbl1.location=new Point(10, 10); lbl1.autosize = true; Controls.Add(lbl1); lbl2=new Label(); lbl2.location=new Point(10, 100); lbl2.autosize = true; Controls.Add(lbl2); RadioButton rdb1=new RadioButton(); rdb1.text="chemistry"; rdb1.location=new Point(10, 30); rdb1.checkedchanged += new EventHandler(radioButton_CheckedChanged); Controls.Add(rdb1); RadioButton rdb2=new RadioButton(); rdb2.text="biology"; rdb2.location=new Point(10, 50); rdb2.checkedchanged += new EventHandler(radioButton_CheckedChanged); Controls.Add(rdb2); RadioButton rdb3=new RadioButton(); Visual C# - Dr. Penn P. Wu 305
39 rdb3.text="physics"; rdb3.location=new Point(10, 70); rdb3.checkedchanged += new EventHandler(radioButton_CheckedChanged); Controls.Add(rdb3); private void radiobutton_checkedchanged(object sender, EventArgs e) lbl2.text = "You picked " + ((RadioButton) sender).text; 2. Compile and test the program. A sample output looks: 3. Capture a screen shot similar to the above and paste it to the Word document named lab10.doc (or.docx). Learning Activity #3: 1. Under the C:\cis218 directory, use Notepad to create a new source file called lab10_3.cs with the following contents: public class Form1 : Form private ComboBox combobox1; public Form1() // properties of the form // define the size of the form this.size = new Size(200, 200); Label label1 = new Label(); label1.text = "Select the campus:"; label1.location = new Point(10, 10); Controls.Add(label1); combobox1 = new ComboBox(); combobox1.location=new Point(10,35); combobox1.items.add("sherman Oaks"); combobox1.items.add("long Beach"); combobox1.items.add("pomona"); combobox1.items.add("irvine"); combobox1.selecteditem="sherman Oaks"; Visual C# - Dr. Penn P. Wu 306
40 combobox1.width = 100; combobox1.height = 25; combobox1.selectedvaluechanged += new EventHandler(comboBox1_SelectedValueChanged); Controls.Add(comboBox1); private void combobox1_selectedvaluechanged(object sender, EventArgs e) MessageBox.Show("You picked " + combobox1.selecteditem.tostring()); 2. Compile and test the program. A sample output looks: 3. Capture a screen shot similar to the above and paste it to the Word document named lab10.doc (or.docx). Learning Activity #4: 1. Under the C:\cis218 directory, use Notepad to create a new source file called lab10_4.cs with the following contents: public class Form1 : Form MainMenu mainmenu1; public Form1() // properties of the form // define form properties Text = "My Sample Menu"; Size = new Size (200, 200); // add main to form mainmenu1 = new MainMenu(); and MenuItem File = mainmenu1.menuitems.add("&file"); File.MenuItems.Add(new MenuItem("&New")); File.MenuItems.Add(new MenuItem("&Open")); File.MenuItems.Add(new MenuItem("&Exit")); Visual C# - Dr. Penn P. Wu 307
41 MenuItem About = mainmenu1.menuitems.add("&about"); About.MenuItems.Add(new MenuItem("&About")); this.menu=mainmenu1; 2. Compile and test the program. A sample output looks: 3. Capture a screen shot similar to the above and paste it to the Word document named lab10.doc (or.docx). Learning Activity #5: Convert a data to Chinese lunar calendar 1. Under the C:\cis218 directory, use Notepad to create a new source file called lab10_5.cs with the following contents: using System.Globalization; public class Form1 : Form DateTimePicker datetimepicker1; Label label1; public Form1() datetimepicker1 = new DateTimePicker(); datetimepicker1.location = new Point(10, 10); datetimepicker1.valuechanged += new EventHandler(this.DateTimePicker1_ValueChanged); Controls.Add(dateTimePicker1); label1 = new Label(); label1.location = new Point(10, 50); label1.autosize = true; Controls.Add(label1); private void DateTimePicker1_ValueChanged(Object sender, EventArgs e) DateTime dt = datetimepicker1.value; ChineseLunisolarCalendar ch = new ChineseLunisolarCalendar(); int d = ch.getdayofmonth(dt); // convert to Chinese value int m = ch.getmonth(dt); // convert to Chinese month Visual C# - Dr. Penn P. Wu 308
42 int y = ch.getyear(dt); // convert to Chinese year dt = new DateTime(y, m, d); label1.text = "It is " + dt.toshortdatestring() + " (M/D/Y) in Chinese lunar calendar!"; 2. Compile and test the program. A sample output looks: 3. Capture a screen shot similar to the above and paste it to the Word document named lab10.doc (or.docx). Programming Exercise: 1. Use Notepad to create a new file named ex10.cs with the following heading lines (be sure to replace YourFullNameHere with the correct one): //File Name: ex10.cs //Programmer: YourFullNameHere 1. Under the above two heading lines, write C# codes to create a generic Windows form (not message box) with a Button control in it. Set its size to (300, 300). 2. Write codes to add event handlers to the Button control, so it will change the size of the form to (150, 150) when the button is clicked, as shown below. and Change from to 2. Download the programming exercise template, and rename it to ex10.doc. Capture a screen shot similar to the above figure and then paste it to the Word document named ex10.doc (or.docx). Visual C# - Dr. Penn P. Wu 309
Overview Describe the structure of a Windows Forms application Introduce deployment over networks
Windows Forms Overview Describe the structure of a Windows Forms application application entry point forms components and controls Introduce deployment over networks 2 Windows Forms Windows Forms are classes
More informationCST242 Windows Forms with C# Page 1
CST242 Windows Forms with C# Page 1 1 2 4 5 6 7 9 10 Windows Forms with C# CST242 Visual C# Windows Forms Applications A user interface that is designed for running Windows-based Desktop applications A
More informationEvents. Event Handler Arguments 12/12/2017. EEE-425 Programming Languages (2016) 1
Events Events Single Event Handlers Click Event Mouse Events Key Board Events Create and handle controls in runtime An event is something that happens. Your birthday is an event. An event in programming
More informationProgramming. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies
9 Programming Based on Events C# Programming: From Problem Analysis to Program Design 2nd Edition David McDonald, Ph.D. Director of Emerging Technologies Chapter Objectives Create applications that use
More informationChapter 13: Handling Events
Chapter 13: Handling Events Event Handling Event Occurs when something interesting happens to an object Used to notify a client program when something happens to a class object the program is using Event
More informationEEE-425 Programming Languages (2013) 1
2 System.Drawing Namespace System.Windows.Forms Namespace Creating forms applications by hand Creating forms applications using Visual Studio designer Windows applications also look different from console
More informationPhiladelphia University Faculty of Information Technology. Visual Programming
Philadelphia University Faculty of Information Technology Visual Programming Using C# -Work Sheets- Prepared by: Dareen Hamoudeh Eman Al Naji Work Sheet 1 Form, Buttons and labels Properties Changing properties
More informationUsing Visual Basic Studio 2008
Using Visual Basic Studio 2008 Recall that object-oriented programming language is a programming language that allows the programmer to use objects to accomplish a program s goal. An object is anything
More informationEEE-425 Programming Languages (2013) 1
2 System.Drawing Namespace System.Windows.Forms Namespace Creating forms applications by hand Creating forms applications using Visual Studio designer Windows applications also look different from console
More informationHow to Use MessageBox
How to Use MessageBox Contents MessageBox Class... 1 Use MessageBox without checking result... 4 Check MessageBox Return Value... 8 Use a property to save MessageBox return... 9 Check MessageBox return
More informationYour First Windows Form
Your First Windows Form From now on, we re going to be creating Windows Forms Applications, rather than Console Applications. Windows Forms Applications make use of something called a Form. The Form is
More informationDateTimePicker Control
Controls Part 2 DateTimePicker Control Used for representing Date/Time information and take it as input from user. Date information is automatically created. Prevents wrong date and time input. Fundamental
More informationCSC 211 Intermediate Programming
Introduction CSC 211 Intermediate Programming Graphical User Interface Concepts: Part 1 Graphical user interface Allow interaction with program visually Give program distinct look and feel Built from window
More informationLaboratorio di Ingegneria del Software
Laboratorio di Ingegneria del Software L-A Interfaccia utente System.Windows.Forms The System.Windows.Forms namespace contains classes for creating Windows-based applications The classes can be grouped
More informationLaboratorio di Ingegneria del L-A
Software L-A Interfaccia utente System.Windows.Forms The System.Windows.Forms namespace contains classes for creating Windows-based applications The classes can be grouped into the following categories:
More informationProgram and Graphical User Interface Design
CHAPTER 2 Program and Graphical User Interface Design OBJECTIVES You will have mastered the material in this chapter when you can: Open and close Visual Studio 2010 Create a Visual Basic 2010 Windows Application
More information#using <System.dll> #using <System.Windows.Forms.dll> #using <System.Drawing.dll>
Lecture #9 Introduction Anatomy of Windows Forms application Hand-Coding Windows Form Applications Although Microsoft Visual Studio makes it much easier for developers to create Windows Forms applications,
More informationIngegneria del Software T. Interfaccia utente
Interfaccia utente Creating Windows Applications Typical windows-application design & development 1+ classes derived from System.Windows.Forms.Form Design UI with VisualStudio.NET Possible to do anything
More information1 Dept: CE.NET Programming ( ) Prof. Akash N. Siddhpura. Working with Form: properties, methods and events
Working with Form: properties, methods and events To create a New Window Forms Application, Select File New Project. It will open one dialog box which is shown in Fig 2.1. Fig 2.1 The New Project dialog
More informationVisual Basic.NET. 1. Which language is not a true object-oriented programming language?
Visual Basic.NET Objective Type Questions 1. Which language is not a true object-oriented programming language? a.) VB.NET b.) VB 6 c.) C++ d.) Java Answer: b 2. A GUI: a.) uses buttons, menus, and icons.
More informationUnit-1. Components of.net Framework. 1. Introduction to.net Framework
1 Unit-1 1. Introduction to.net Framework The.NET framework is a collection of all the tools and utilities required to execute the.net managed applications on a particular platform. The MS.NET framework
More information1. Windows Forms 2. Event-Handling Model 3. Basic Event Handling 4. Control Properties and Layout 5. Labels, TextBoxes and Buttons 6.
C# cont d (C-sharp) (many of these slides are extracted and adapted from Deitel s book and slides, How to Program in C#. They are provided for CSE3403 students only. Not to be published or publicly distributed
More informationGetting started 7. Setting properties 23
Contents 1 2 3 Getting started 7 Introducing Visual Basic 8 Installing Visual Studio 10 Exploring the IDE 12 Starting a new project 14 Adding a visual control 16 Adding functional code 18 Saving projects
More informationGetting started 7. Setting properties 23
Contents 1 2 3 Getting started 7 Introduction 8 Installing Visual Basic 10 Exploring the IDE 12 Starting a new project 14 Adding a visual control 16 Adding functional code 18 Saving projects 20 Reopening
More informationChapter 6 Dialogs. Creating a Dialog Style Form
Chapter 6 Dialogs We all know the importance of dialogs in Windows applications. Dialogs using the.net FCL are very easy to implement if you already know how to use basic controls on forms. A dialog is
More informationChapter 12: Using Controls
Chapter 12: Using Controls Examining the IDE s Automatically Generated Code A new Windows Forms project has been started and given the name FormWithALabelAndAButton A Label has been dragged onto Form1
More informationLecture 1 Introduction Phil Smith
2014-2015 Lecture 1 Introduction Phil Smith Learning Outcomes LO1 Understand the principles of object oriented programming LO2 Be able to design object oriented programming solutions LO3 Be able to implement
More informationChapter 2. Creating Applications with Visual Basic Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of
Chapter 2 Creating Applications with Visual Basic Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved. Section 2.1 FOCUS ON PROBLEM SOLVING: BUILDING THE DIRECTIONS APPLICATION
More informationVisual C# Program: Simple Game 3
C h a p t e r 6C Visual C# Program: Simple Game 3 In this chapter, you will learn how to use the following Visual C# Application functions to World Class standards: Opening Visual C# Editor Beginning a
More informationPart I. Integrated Development Environment. Chapter 2: The Solution Explorer, Toolbox, and Properties. Chapter 3: Options and Customizations
Part I Integrated Development Environment Chapter 1: A Quick Tour Chapter 2: The Solution Explorer, Toolbox, and Properties Chapter 3: Options and Customizations Chapter 4: Workspace Control Chapter 5:
More informationType Description Example
Lecture #1 Introducing Visual C# Introduction to the C# Language and the.net Framework According to Microsoft, C# (pronounced C sharp ) is a programming language that is designed for building a variety
More informationLESSON B. The Toolbox Window
The Toolbox Window After studying Lesson B, you should be able to: Add a control to a form Set the properties of a label, picture box, and button control Select multiple controls Center controls on the
More information2 USING VB.NET TO CREATE A FIRST SOLUTION
25 2 USING VB.NET TO CREATE A FIRST SOLUTION LEARNING OBJECTIVES GETTING STARTED WITH VB.NET After reading this chapter, you will be able to: 1. Begin using Visual Studio.NET and then VB.NET. 2. Point
More informationCOPYRIGHTED MATERIAL. Visual Basic: The Language. Part 1
Part 1 Visual Basic: The Language Chapter 1: Getting Started with Visual Basic 2010 Chapter 2: Handling Data Chapter 3: Visual Basic Programming Essentials COPYRIGHTED MATERIAL Chapter 1 Getting Started
More informationGUI Design and Event- Driven Programming
4349Book.fm Page 1 Friday, December 16, 2005 1:33 AM Part 1 GUI Design and Event- Driven Programming This Section: Chapter 1: Getting Started with Visual Basic 2005 Chapter 2: Visual Basic: The Language
More informationWelcome Application. Introducing the Visual Studio.NET IDE. Objectives. Outline
2 T U T O R I A L Objectives In this tutorial, you will learn to: Navigate Visual Studio.NET s Start Page. Create a Visual Basic.NET solution. Use the IDE s menus and toolbars. Manipulate windows in the
More informationMenus and Printing. Menus. A focal point of most Windows applications
Menus and Printing Menus A focal point of most Windows applications Almost all applications have a MainMenu Bar or MenuStrip MainMenu Bar or MenuStrip resides under the title bar MainMenu or MenuStrip
More informationContents. Using Interpreters... 5 Using Compilers... 5 Program Development Life Cycle... 6
Contents ***Introduction*** Introduction to Programming... 1 Introduction... 2 What is a Program?... 2 Role Played by a Program to Perform a Task... 2 What is a Programming Language?... 3 Types of Programming
More informationVisual Studio.NET enables quick, drag-and-drop construction of form-based applications
Visual Studio.NET enables quick, drag-and-drop construction of form-based applications Event-driven, code-behind programming Visual Studio.NET WinForms Controls Part 1 Event-driven, code-behind programming
More informationENGR/CS 101 CS Session Lecture 4
ENGR/CS 101 CS Session Lecture 4 Log into Windows/ACENET (reboot if in Linux) Start Microsoft Visual Studio 2010 Finish exercise from last time Lecture 4 ENGR/CS 101 Computer Science Session 1 Outline
More informationHow to set up a local root folder and site structure
Activity 2.1 guide How to set up a local root folder and site structure The first thing to do when creating a new website with Adobe Dreamweaver CS3 is to define a site and identify a root folder where
More informationWindows Me Navigating
LAB PROCEDURE 11 Windows Me Navigating OBJECTIVES 1. Explore the Start menu. 2. Start an application. 3. Multi-task between applications. 4. Moving folders and files around. 5. Use Control Panel settings.
More informationGraphical User Interface Canvas Frame Event structure Platform-free GUI operations Operator << Operator >> Operator = Operator ~ Operator + Operator
Graphical User Interface Canvas Frame Event structure Platform-free GUI operations Operator > Operator = Operator ~ Operator + Operator - Operator [] Operator size Operator $ Operator? Operator!
More informationPhiladelphia University Faculty of Information Technology. Visual Programming. Using C# -Work Sheets-
Philadelphia University Faculty of Information Technology Visual Programming Using C# -Work Sheets- Prepared by: Dareen Hamoudeh Eman Al Naji 2018 Work Sheet 1 Hello World! 1. Create a New Project, Name
More informationDeveloping for Mobile Devices Lab (Part 1 of 2)
Developing for Mobile Devices Lab (Part 1 of 2) Overview Through these two lab sessions you will learn how to create mobile applications for Windows Mobile phones and PDAs. As developing for Windows Mobile
More informationChapter 2 Exploration of a Visual Basic.Net Application
Chapter 2 Exploration of a Visual Basic.Net Application We will discuss in this chapter the structure of a typical Visual Basic.Net application and provide you with a simple project that describes the
More informationWindows 7 Control Pack for WinForms
ComponentOne Windows 7 Control Pack for WinForms By GrapeCity, Inc. Copyright 1987-2012 GrapeCity, Inc. All rights reserved. Corporate Headquarters ComponentOne, a division of GrapeCity 201 South Highland
More informationMicrosoft Visual Basic 2005: Reloaded
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005 Objectives After studying this chapter, you should be able to: Explain the history of programming languages
More informationHOUR 4 Understanding Events
HOUR 4 Understanding Events It s fairly easy to produce an attractive interface for an application using Visual Basic.NET s integrated design tools. You can create beautiful forms that have buttons to
More informationOCTAVO An Object Oriented GUI Framework
OCTAVO An Object Oriented GUI Framework Federico de Ceballos Universidad de Cantabria federico.ceballos@unican.es November, 2004 Abstract This paper presents a framework for building Window applications
More informationProgramming in C# Project 1:
Programming in C# Project 1: Set the text in the Form s title bar. Change the Form s background color. Place a Label control on the Form. Display text in a Label control. Place a PictureBox control on
More informationDive Into Visual C# 2008 Express
1 2 2 Dive Into Visual C# 2008 Express OBJECTIVES In this chapter you will learn: The basics of the Visual Studio Integrated Development Environment (IDE) that assists you in writing, running and debugging
More informationContents. Launching Word
Using Microsoft Office 2007 Introduction to Word Handout INFORMATION TECHNOLOGY SERVICES California State University, Los Angeles Version 1.0 Winter 2009 Contents Launching Word 2007... 3 Working with
More informationCST272 Getting Started Page 1
CST272 Getting Started Page 1 1 2 3 4 5 6 8 Introduction to ASP.NET, Visual Studio and C# CST272 ASP.NET Static and Dynamic Web Applications Static Web pages Created with HTML controls renders exactly
More informationSKILL AREA 210: USE A WORD PROCESSING SOFTWARE. Lesson 1: Getting Familiar with Microsoft Word 2007 for Windows...5
Contents Microsoft Word 2007...5 Lesson 1: Getting Familiar with Microsoft Word 2007 for Windows...5 The Microsoft Office Button...6 The Quick Access Toolbar...6 The Title Bar...6 The Ribbon...6 The Ruler...6
More informationGetting Familiar with Microsoft Word 2010 for Windows
Lesson 1: Getting Familiar with Microsoft Word 2010 for Windows Microsoft Word is a word processing software package. You can use it to type letters, reports, and other documents. This tutorial teaches
More informationChapter 12: Using Controls
Chapter 12: Using Controls Using a LinkLabel LinkLabel Similar to a Label Provides the additional capability to link the user to other sources Such as Web pages or files Default event The method whose
More informationTo start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer
C# Tutorial Create a Motivational Quotes Viewer Application in Visual Studio In this tutorial we will create a fun little application for Microsoft Windows using Visual Studio. You can use any version
More informationStart Visual Studio and create a new windows form application under C# programming language. Call this project YouTube Alarm Clock.
C# Tutorial - Create a YouTube Alarm Clock in Visual Studio In this tutorial we will create a simple yet elegant YouTube alarm clock in Visual Studio using C# programming language. The main idea for this
More informationRecommended GUI Design Standards
Recommended GUI Design Standards Page 1 Layout and Organization of Your User Interface Organize the user interface so that the information follows either vertically or horizontally, with the most important
More informationOffice 365: . Accessing and Logging In. Mail
Office 365: Email This class will introduce you to Office 365 and cover the email components found in Outlook on the Web. For more information about the Microsoft Outlook desktop client, register for a
More information10Tec igrid for.net 6.0 What's New in the Release
What s New in igrid.net 6.0-1- 2018-Feb-15 10Tec igrid for.net 6.0 What's New in the Release Tags used to classify changes: [New] a totally new feature; [Change] a change in a member functionality or interactive
More informationCIS 3260 Intro. to Programming with C#
Running Your First Program in Visual C# 2008 McGraw-Hill 2010 The McGraw-Hill Companies, Inc. All rights reserved. Run Visual Studio Start a New Project Select File/New/Project Visual C# and Windows must
More informationOpenForms360 Validation User Guide Notable Solutions Inc.
OpenForms360 Validation User Guide 2011 Notable Solutions Inc. 1 T A B L E O F C O N T EN T S Introduction...5 What is OpenForms360 Validation?... 5 Using OpenForms360 Validation... 5 Features at a glance...
More informationEvent-based Programming
Window-based programming Roger Crawfis Most modern desktop systems are window-based. What location do I use to set this pixel? Non-window based environment Window based environment Window-based GUI s are
More informationDive Into Visual C# 2010 Express
Dive Into Visual C# 2010 Express 2 Seeing is believing. Proverb Form ever follows function. Louis Henri Sullivan Intelligence is the faculty of making artificial objects, especially tools to make tools.
More informationResponding to the Mouse
Responding to the Mouse The mouse has two buttons: left and right. Each button can be depressed and can be released. Here, for reference are the definitions of three common terms for actions performed
More informationLesson 1: Getting Familiar with Microsoft Word 2007 for Windows
Lesson 1: Getting Familiar with Microsoft Word 2007 for Windows Microsoft Word is a word processing software package. You can use it to type letters, reports, and other documents. This tutorial teaches
More informationMenuStrip Control. The MenuStrip control represents the container for the menu structure.
MenuStrip Control The MenuStrip control represents the container for the menu structure. The MenuStrip control works as the top-level container for the menu structure. The ToolStripMenuItem class and the
More informationCreating Interactive PDF Forms
Creating Interactive PDF Forms Using Adobe Acrobat X Pro for the Mac University Information Technology Services Training, Outreach, Learning Technologies and Video Production Copyright 2012 KSU Department
More informationChapter 3 Syntax, Errors, and Debugging. Fundamentals of Java
Chapter 3 Syntax, Errors, and Debugging Objectives Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different
More informationMicrosoft Visual Basic 2005 CHAPTER 5. Mobile Applications Using Decision Structures
Microsoft Visual Basic 2005 CHAPTER 5 Mobile Applications Using Decision Structures Objectives Write programs for devices other than a personal computer Understand the use of handheld technology Write
More informationINFORMATICS LABORATORY WORK #4
KHARKIV NATIONAL UNIVERSITY OF RADIO ELECTRONICS INFORMATICS LABORATORY WORK #4 MAZE GAME CREATION Associate Professor A.S. Eremenko, Associate Professor A.V. Persikov Maze In this lab, you build a maze
More informationThe first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear.
4 Programming with C#.NET 1 Camera The first program we write will display a picture on a Windows screen, with buttons to make the picture appear and disappear. Begin by loading Microsoft Visual Studio
More informationMicrosoft Excel 2010 Part 2: Intermediate Excel
CALIFORNIA STATE UNIVERSITY, LOS ANGELES INFORMATION TECHNOLOGY SERVICES Microsoft Excel 2010 Part 2: Intermediate Excel Spring 2014, Version 1.0 Table of Contents Introduction...3 Working with Rows and
More informationAutoCAD 2009 User InterfaceChapter1:
AutoCAD 2009 User InterfaceChapter1: Chapter 1 The AutoCAD 2009 interface has been enhanced to make AutoCAD even easier to use, while making as much screen space available as possible. In this chapter,
More informationWinView. Getting Started Guide
WinView Getting Started Guide Version 4.3.12 June 2006 Copyright 2006 Mincom Limited All rights reserved. No part of this document may be reproduced, transferred, sold or otherwise disposed of without
More informationYou will have mastered the material in this chapter when you can:
CHAPTER 6 Loop Structures OBJECTIVES You will have mastered the material in this chapter when you can: Add a MenuStrip object Use the InputBox function Display data using the ListBox object Understand
More informationThe original of this document was developed by the Microsoft special interest group. We made some addons.
Naming Conventions for.net / C# Projects Martin Zahn, Akadia AG, 20.03.2003 The original of this document was developed by the Microsoft special interest group. We made some addons. This document explains
More informationHere is a step-by-step guide to creating a custom toolbar with text
How to Create a Vertical Toolbar with Text Buttons to Access Your Favorite Folders, Templates and Files 2007-2017 by Barry MacDonnell. All Rights Reserved. Visit http://wptoolbox.com. The following is
More informationNiceForm User Guide. English Edition. Rev Euro Plus d.o.o. & Niceware International LLC All rights reserved.
www.nicelabel.com, info@nicelabel.com English Edition Rev-0910 2009 Euro Plus d.o.o. & Niceware International LLC All rights reserved. www.nicelabel.com Head Office Euro Plus d.o.o. Ulica Lojzeta Hrovata
More informationExperiment 5 : Creating a Windows application to interface with 7-Segment LED display
Experiment 5 : Creating a Windows application to interface with 7-Segment LED display Objectives : 1) To understand the how Windows Forms in the Windows-based applications. 2) To create a Window Application
More informationThe Mathcad Workspace 7
For information on system requirements and how to install Mathcad on your computer, refer to Chapter 1, Welcome to Mathcad. When you start Mathcad, you ll see a window like that shown in Figure 2-1. By
More informationTutorial 3 - Welcome Application
1 Tutorial 3 - Welcome Application Introduction to Visual Programming Outline 3.1 Test-Driving the Welcome Application 3.2 Constructing the Welcome Application 3.3 Objects used in the Welcome Application
More informationTABLE OF CONTENTS TABLE OF CONTENTS... 1 INTRODUCTION... 2 USING WORD S MENUS... 3 USING WORD S TOOLBARS... 5 TASK PANE... 9
TABLE OF CONTENTS TABLE OF CONTENTS... 1 INTRODUCTION... 2 USING WORD S MENUS... 3 DEFINITIONS... 3 WHY WOULD YOU USE THIS?... 3 STEP BY STEP... 3 USING WORD S TOOLBARS... 5 DEFINITIONS... 5 WHY WOULD
More informationAbstract. 1. Conformance. 2. Introduction. 3. Abstract User Interface
MARIA (Model-based language for Interactive Applications) W3C Working Group Submission 3 February 2012 Editors: Fabio Paternò, ISTI-CNR Carmen Santoro, ISTI-CNR Lucio Davide Spano, ISTI-CNR Copyright 2012
More informationVisual Programming (761220) First Exam First Semester of Date: I Time: 60 minutes
Philadelphia University Lecturer : Mrs. Eman Alnaji Coordinator : Miss. Reem AlQaqa Internal Examiner: Dr. Nameer Al Emam Faculty of Information Technology Department of CIS Examination Paper Visual Programming
More informationListBox. Class ListBoxTest. Allows users to add and remove items from ListBox Uses event handlers to add to, remove from, and clear list
C# cont d (C-sharp) (many of these slides are extracted and adapted from Deitel s book and slides, How to Program in C#. They are provided for CSE3403 students only. Not to be published or publicly distributed
More informationStart Visual Studio, start a new Windows Form project under the C# language, name the project BalloonPop MooICT and click OK.
Start Visual Studio, start a new Windows Form project under the C# language, name the project BalloonPop MooICT and click OK. Before you start - download the game assets from above or on MOOICT.COM to
More informationChapter 6 Introduction to Defining Classes
Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of
More informationSkill Area 336 Explain Essential Programming Concept. Programming Language 2 (PL2)
Skill Area 336 Explain Essential Programming Concept Programming Language 2 (PL2) 336.2-Apply Basic Program Development Techniques 336.2.1 Identify language components for program development 336.2.2 Use
More informationCHAPTER 1 COPYRIGHTED MATERIAL. Getting to Know AutoCAD. Opening a new drawing. Getting familiar with the AutoCAD and AutoCAD LT Graphics windows
CHAPTER 1 Getting to Know AutoCAD Opening a new drawing Getting familiar with the AutoCAD and AutoCAD LT Graphics windows Modifying the display Displaying and arranging toolbars COPYRIGHTED MATERIAL 2
More informationText box. Command button. 1. Click the tool for the control you choose to draw in this case, the text box.
Visual Basic Concepts Hello, Visual Basic See Also There are three main steps to creating an application in Visual Basic: 1. Create the interface. 2. Set properties. 3. Write code. To see how this is done,
More informationManaging Content with AutoCAD DesignCenter
Managing Content with AutoCAD DesignCenter In This Chapter 14 This chapter introduces AutoCAD DesignCenter. You can now locate and organize drawing data and insert blocks, layers, external references,
More informationA Quick Tour GETTING STARTED WHAT S IN THIS CHAPTER?
1 A Quick Tour WHAT S IN THIS CHAPTER? Installing and getting started with Visual Studio 2012 Creating and running your fi rst application Debugging and deploying an application Ever since software has
More informationClick on the empty form and apply the following options to the properties Windows.
Start New Project In Visual Studio Choose C# Windows Form Application Name it SpaceInvaders and Click OK. Click on the empty form and apply the following options to the properties Windows. This is the
More informationUsing Microsoft Excel
Using Microsoft Excel Formatting a spreadsheet means changing the way it looks to make it neater and more attractive. Formatting changes can include modifying number styles, text size and colours. Many
More informationThe first time you open Word
Microsoft Word 2010 The first time you open Word When you open Word, you see two things, or main parts: The ribbon, which sits above the document, and includes a set of buttons and commands that you use
More informationLESSON A. The Splash Screen Application
The Splash Screen Application LESSON A LESSON A After studying Lesson A, you should be able to: Start and customize Visual Studio 2010 or Visual Basic 2010 Express Create a Visual Basic 2010 Windows application
More informationCANVASES AND WINDOWS
CHAPTER 8 CANVASES AND WINDOWS CHAPTER OBJECTIVES In this Chapter, you will learn about: Canvas and Window Concepts Page 262 Content Canvases and Windows Page 277 Stacked Canvases Page 287 Toolbar Canvases
More information