C# and.net (1) cont d

Size: px
Start display at page:

Download "C# and.net (1) cont d"

Transcription

1 C# and.net (1) cont d Acknowledgements and copyrights: these slides are a result of combination of notes and slides with contributions from: Michael Kiffer, Arthur Bernstein, Philip Lewis, Hanspeter Mφssenbφck, Hanspeter Mφssenbφck, Wolfgang Beer, Dietrich Birngruber, Albrecht Wφss, Mark Sapossnek, Bill Andreopoulos, Divakaran Liginlal, Michael Morrison, Anestis Toptsis, Deitel and Associates, Prentice Hall, Addison Wesley, Microsoft AA. They serve for teaching purposes only and only for the students that are registered in CSE4413 and should not be published as a book or in any form of commercial product, unless written permission is obtained from each of the above listed names and/or organizations. 1

2 C# Namespaces Namespace A group of classes and their methods No two classes in the same namespace may have the same name Classes in different namespaces may have the same name The Framework Class Library (FCL) is composed of namespaces Namespaces are stored in.dll files called assemblies A list of the FCL namespaces are shown next Included in a program with the using keyword 2

3 C# Namespaces Namespace System System.Data System.Drawing System.IO System.Threading System.Windows.Forms System.Xml Description Contains essential classes and data types (such as int, double, char, etc.). Implicitly referenced by all C# programs. Contains classes that form ADO.NET, used for database access and manipulation. Contains classes used for drawing and graphics. Contains classes for the input and output of data, such as with files. Contains classes for multithreading, used to run multiple parts of a program simultaneously. Contains classes used to create graphical user interfaces. Contains classes used to process XML data. Some of the namespaces of the Framework Class Library 3

4 How to create a namespace Create a class library project (in VS.NET) (File -> New -> New Project -> [C# Projects selected in Project types] -> Class Library). Make sure that namespace TimeLibrary is included in the beginning of the generated file. (as shown in next slide). 4

5 Namespaces and Assemblies Simple Class Library. 5

6 How to create a namespace, cont d Type your code for the class (you may rename the class, as you like). Compile the code with the Build Solution option (Build -> Build Solution). This code cannot be executed since it doesn t contain Main(), but it will generate a.dll file, named TimeLibrary.dll, found in the bin\debug directory under your project directory (TimeLibrary). This.dll file is the Assembly and it can then be included in your applications (by typing using TimeLibrary at the beginning of your files. 6

7 1 // AssemblyTest.cs 2 // Using class Time3 from assembly TimeLibrary. 3 4 using System; 5 using TimeLibrary; 6 7 // AssemblyTest class definition 8 class AssemblyTest 9 { 10 // main entry point for application 11 static void Main( string[] args ) 12 { 13 Time3 time = new Time3( 13, 27, 6 ); Console.WriteLine( 16 "Standard time: {0}\nUniversal time: {1}\n", 17 time.tostandardstring(), time.touniversalstring() ); 18 } 19 } AssemblyTest.cs Use Time3 as usual Reference the TimeLibrary namespace Program Output Standard time: 1:27:06 PM Universal time: 13:27:06 7

8 Indexers Allow usage of objects using array notation. Borrowed from C++ ability to overload the [] operator (not possible in C#, or in Java). Allows using objects, like this: obj[0], to mean obj.getx(), if index 0 refers to instance variable x. obj[0] = 7 to mean obj.setx(7). The indexes 0, 1, 2, refer to instance variables of the class of object obj. Index 0 refers to first instance variable, index 1 refers to second instance variable, etc. 8

9 Indexer to refer to instance vars lb and oz (index 0 refers to lb, 1 refers to oz) 9

10 Usage of indexer of Weight this[0] returns the value of lb. ( and, likewise, w[0] would also refer to lb of w, where w is an object of type Weight.) 10

11 Indexer to refer to instance var somearray. (index 0 refers to somearray[0], 1 refers to somearray[1], etc) 11

12 Usage of indexer of Weight and MyArray 12

13 13

14 Exceptions. In C# are pretty much as in Java. 14

15 With no exception handling. (Method2() is in a class ExceptionsDemo) 15

16 Output (crash) 16

17 With exception handling 17

18 Main() to invoke Method1() 18

19 Output (no exception occurred. Finally executed though) 19

20 Output (exception occurred. Finally still executed) 20

21 Passing Arguments to methods: C# supports both Call-By-Value and pass and Call-By-Reference Passing by value (same as Java) Send a method a copy of the object When returned are always returned by value Set by value by default Passing by reference (same as passing a pointer in C, C++) Send a method the actual reference point Causes the variable to be changed throughout the program When returned are always returned by reference The ref keyword specifies by reference The out keyword means a called method will initialize it 21

22 1 // RefOutTest.cs 2 // Demonstrating ref and out parameters. 3 4 using System; 5 using System.Windows.Forms; 6 7 class RefOutTest 8 { 9 // x is passed as a ref int (original value will change) 10 static void SquareRef( ref int x ) 11 { 12 x = x * x; 13 } // original value can be changed and initialized 16 static void SquareOut( out int x ) 17 { 18 x = 6; 19 x = x * x; 20 } // x is passed by value (original value not changed) 23 static void Square( int x ) 24 { 25 x = x * x; 26 } static void Main( string[] args ) 29 { 30 // create a new integer value, set it to 5 31 int y = 5; 32 int z; // declare z, but do not initialize it 33 RefOutTest.cs 22

23 34 // display original values of y and z 35 string output1 = "The value of y begins as " 36 + y + ", z begins uninitialized.\n\n\n"; // values of y and z are passed by by value reference 39 RefOutTest.SquareRef( ref y ); 40 RefOutTest.SquareOut( out z ); // display values of y and z after modified by methods 43 // SquareRef and SquareOut 44 string output2 = "After calling SquareRef with y as an " + 45 "argument and SquareOut with z as an argument,\n" + 46 "the values of y and z are:\n\n" + 47 "y: " + y + "\nz: " + z + "\n\n\n"; // values of y and z are passed by by value 50 RefOutTest.Square( y ); 51 RefOutTest.Square( z ); // values of y and z will be same as before because Square 54 // did not modify variables directly 55 string output3 = "After calling Square on both x and y, " + 56 "the values of y and z are:\n\n" + 57 "y: " + y + "\nz: " + z + "\n\n"; MessageBox.Show( output1 + output2 + output3, 60 "Using ref and out Parameters", MessageBoxButtons.OK, 61 MessageBoxIcon.Information ); } // end method Main } // end class RefOutTest RefOutTest.cs 23

24 RefOutTest.cs Program Output 24

25 const and readonly Members Declare constant members (members whose value will never change) using the keyword const (equivalent to java s final) const members are implicitly static const members must be initialized when they are declared Use keyword readonly to declare members who will be initialized in the constructor but not change after that 25

26 1 // UsingConstAndReadOnly.cs 2 // Demonstrating constant values with const and readonly. 3 4 using System; 5 7 // Constants class definition 8 public class Constants 9 { 10 // PI is constant variable 11 public const double PI = ; // radius is a constant variable 14 // that is uninitialized 15 public readonly int radius; public Constants( int radiusvalue ) 18 { 19 radius = radiusvalue; 20 } 22 } // end class Constants UsingConstAndReadOnly.cs Constant variable PI Readonly variable radius; must be initialized in constructor Initialize readonly member radius 26

27 UsingConstAndReadOnly.cs 1 // UsingConstAndReadOnly.cs 2 // Demonstrating constant values with const and readonly // UsingConstAndReadOnly class definition 25 public class UsingConstAndReadOnly 26 { 27 // method Main creates Constants 28 // object 29 static void Main( string[] args ) 30 { 31 Random random = new Random(); Constants constantvalues = 34 new Constants( random.next( 1, 20 ) ); 35 27

28 UsingConstAndReadOnly.cs 36 MessageBox.Show( "Radius = " + constantvalues.radius + 37 "\ncircumference = " * Constants.PI * constantvalues.radius, 39 "Circumference" ); } // end method Main } // end class UsingConstAndReadOnly Output from two separate runs 28

29 Arrays 29

30 1 // SumArray.cs 2 // Computing the sum of the elements in an array. 3 4 using System; 5 using System.Windows.Forms; 6 7 class SumArray 8 { 9 // main entry point for application 10 static void Main( string[] args ) 11 { 12 int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; 13 int total = 0; for ( int i = 0; i < a.length; i++ ) 16 total += a[ i ]; MessageBox.Show( "Total of array elements: " + total, 19 "Sum the elements of an array", 20 MessageBoxButtons.OK, MessageBoxIcon.Information ); } // end Main } // end class SumArray Declare integer array a and initialize it Total the contents of array a 30

31 Passing Arrays to Methods Pass arrays as arguments to methods by specifying the name of the array (no brackets) Arrays are passed by reference Individual array elements are passed by value 31

32 1 // Fig. 7.8: PassArray.cs 2 // Passing arrays and individual elements to methods. 3 using System; 4 using System.Drawing; 5 using System.Collections; 6 using System.ComponentModel; 7 using System.Windows.Forms; 8 using System.Data; 9 10 public class PassArray : System.Windows.Forms.Form 11 { 12 private System.Windows.Forms.Button showoutputbutton; 13 private System.Windows.Forms.Label outputlabel; // Visual Studio.NET generated code [STAThread] 18 static void Main() 19 { 20 Application.Run( new PassArray() ); 21 } private void showoutputbutton_click( object sender, 24 System.EventArgs e ) 25 { 26 int[] a = { 1, 2, 3, 4, 5 }; outputlabel.text = "Effects of passing entire array " + 29 "call-by-reference:\n\nthe values of the original " + 30 "array are:\n\t"; for ( int i = 0; i < a.length; i++ ) 33 outputlabel.text += " " + a[ i ]; ModifyArray( a ); // array is passed by reference Declare and initialize integer array a PassArray.cs Call method ModifyArray, pass array a as an argument by reference Output contents of array a 32

33 36 37 outputlabel.text += 38 "\n\nthe values of the modified array are:\n\t"; // display elements of array a 41 for ( int i = 0; i < a.length; i++ ) 42 outputlabel.text += " " + a[ i ]; outputlabel.text += "\n\neffects of passing array " + 45 "element call-by-value:\n\na[ 3 ] before " + 46 "ModifyElement: " + a[ 3 ]; // array element passed call-by-value 49 ModifyElement( a[ 3 ] ); outputlabel.text += 52 "\na[ 3 ] after ModifyElement: " + a[ 3 ]; 53 } // method modifies the array it receives, 56 // original will be modified 57 public void ModifyArray( int[] b ) 58 { 59 for ( int j = 0; j < b.length; j++ ) 60 b[ j ] *= 2; 61 } // method modifies the integer passed to it 64 // original will not be modified 65 public void ModifyElement( int e ) 66 { 67 outputlabel.text += 68 "\nvalue received in ModifyElement: " + e; 69 Replace every element in array by twice its value PassArray.cs Output array a after ModifyArray changed the contents Call method ModifyElement, pass element of array a that is at index 3 33

34 PassArray.cs 70 e *= 2; outputlabel.text += 73 "\nvalue calculated Multiply in argument by two ModifyElement: " + e; This does not change value of element in original 74 } array, because the element was passed by value 75 } 34

35 Passing Arrays by Value and by Reference Variables that store object, actually store references to those objects A reference is a location in computer s memory where the object itself is stored Passing value types to methods A copy of the variable is made Any changes to variable in method do not effect the original variable Passing reference types to methods A copy of the reference to the object is made Any changes to the reference in the method do not effect the original variable Any changes to the contents of the object in the method, do effect the object outside the method 35

36 Passing Arrays by Value and by Reference Keyword ref may be used to pass arguments to method by reference Value type variables are not copied modifying the variable in the method will modify the variable outside the method References to objects are not copied modifying the reference in the method will modify the reference outside the method Programmers have to be careful when using ref May lead to references being set to null May lead to methods modifying variable values and references in ways that are not desired 36

37 1 // ArrayReferenceTest.cs 2 // Testing the effects of passing array references 3 // by value and by reference. 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; public class ArrayReferenceTest : System.Windows.Forms.Form 12 { 13 private System.Windows.Forms.Label outputlabel; 14 private System.Windows.Forms.Button showoutputbutton; [STAThread] 17 static void Main() 18 { 19 Application.Run( new ArrayReferenceTest() ); 20 } private void showoutputbutton_click( object sender, 23 System.EventArgs e ) 24 { 25 // create and initialize firstarray 26 int[] firstarray = { 1, 2, 3 }; // copy firstarray reference 29 int[] firstarraycopy = firstarray; outputlabel.text += 32 "Test passing firstarray reference by value"; outputlabel.text += "\n\ncontents of firstarray " + 35 "before calling FirstDouble:\n\t"; ArrayReferenceTest.cs Declare and initialize integer array firstarray Declare integer array firstarraycopy and have it reference firstarray 37

38 36 37 // print contents of firstarray 38 for ( int i = 0; i < firstarray.length; i++ ) 39 outputlabel.text += firstarray[ i ] + " "; // pass reference firstarray by value to FirstDouble 42 FirstDouble( firstarray ); outputlabel.text += "\n\ncontents of firstarray after " + 45 "calling FirstDouble\n\t"; // print contents of firstarray 48 for ( int i = 0; i < firstarray.length; i++ ) 49 outputlabel.text += firstarray[ i ] + " "; // test whether reference was changed by FirstDouble 52 if ( firstarray == firstarraycopy ) 53 outputlabel.text += 54 "\n\nthe references refer to the same array\n"; 55 else 56 outputlabel.text += 57 "\n\nthe references refer to different arrays\n"; // create and initialize secondarray 60 int[] secondarray = { 1, 2, 3 }; // copy secondarray reference 63 int[] secondarraycopy = secondarray; outputlabel.text += "\ntest passing secondarray " + 66 "reference by reference"; outputlabel.text += "\n\ncontents of secondarray " + 69 "before calling SecondDouble:\n\t"; 70 ArrayReferenceTest.cs Test whether firstarray and firstarraycopy reference the same object Declare integer array secondarraycopy and set it to reference Output secondarray contents of firstarray Declare and initialize integer array secondarray Call method FirstDouble on firstarray Output contents of firstarray 38

39 71 // print contents of secondarray before method call 72 for ( int i = 0; i < secondarray.length; i++ ) 73 outputlabel.text += secondarray[ i ] + " "; SecondDouble( ref secondarray ); 76 Test whether secondarray and secondarraycopy reference the same object 77 outputlabel.text += "\n\ncontents of secondarray " + 78 "after calling SecondDouble:\n\t"; // print contents of secondarray after method call 81 for ( int i = 0; i < secondarray.length; i++ ) 82 outputlabel.text += secondarray[ i ] + " "; // test whether reference was changed by SecondDouble 85 if ( secondarray == secondarraycopy ) 86 outputlabel.text += 87 "\n\nthe references refer to the same array\n"; 88 else 89 outputlabel.text += 90 "\n\nthe references refer to different arrays\n"; } // end method showoutputbutton_click // modify elements of array and attempt to modify 95 // reference 96 void FirstDouble( int[] array ) 97 { 98 // double each element's value 99 for ( int i = 0; i < array.length; i++ ) 100 array[ i ] *= 2; // create new reference and assign it to array 103 array = new int[] { 11, 12, 13 }; 104 } 105 ArrayReferenceTest.cs Replace each element in the array Output by twice contents its value of secondarray Set array to reference a new integer array containing the values Call method 11, 12 and SecondDouble 13 and pass secondarray by reference Output contents of secondarray 39

40 ArrayReferenceTest.cs 106 // modify elements of array and change reference array 107 // to refer to a new array 108 void SecondDouble( ref int[] array ) 109 { 110 // double each element's value 111 for ( int i = 0; i < array.length; i++ ) 112 array[ i ] *= 2; // create new reference and assign it to array 115 array = new int[] { 11, 12, 13 }; 116 } 117 } Replace each element in the array Set array by to twice reference its value a new integer array containing the values 11, 12 and 13 Program Output 40

41 foreach Repetition Structure The foreach repetition structure is used to iterate through values in data structures such as arrays No counter A variable is used to represent the value of each element 41

42 1 // ForEach.cs 2 // Demonstrating for/each structure. 3 using System; 4 5 class ForEach 6 { 7 // main entry point for the application 8 static void Main( string[] args ) 9 { 10 int[,] gradearray = { { 77, 68, 86, 73 }, 11 { 98, 87, 89, 81 }, { 70, 90, 86, 81 } }; int lowgrade = 100; foreach ( int grade in gradearray ) 16 { 17 if ( grade < lowgrade ) 18 lowgrade = grade; 19 } Console.WriteLine( "The minimum grade is: " + lowgrade ); 22 } 23 } The minimum grade is: 68 ForEach.cs Use the foreach loop to examine each element in the array If the current array element is smaller than lowgrade, set lowgrade to contain the value of the current element 42

43 Inheritance 43

44 1 // Point3.cs 2 // Point3 class represents an x-y coordinate pair. 4 using System; 6 // Point3 class definition implicitly inherits from Object 7 public class Point3 8 { 9 // point coordinate 10 private int x, y; 12 // default constructor 13 public Point3() 14 { 15 // implicit call to Object constructor occurs here 16 } // constructor 19 public Point3( int xvalue, int yvalue ) 20 { 21 // implicit call to Object constructor occurs here 22 X = xvalue; // use property X 23 Y = yvalue; // use property Y 24 } // property X 27 public int X 28 { 29 get 30 { 31 return x; 32 } 33 Declare coordinates as private Point3.cs 44

45 34 set 35 { 36 x = value; // no need for validation 37 } } // end property X // property Y 42 public int Y 43 { 44 get 45 { 46 return y; 47 } set 50 { 51 y = value; // no need for validation 52 } } // end property Y // return string representation of Point3 57 public override string ToString() 58 { 59 return "[" + X + ", " + Y + "]"; 60 } } // end class Point3 Methods to set x and y coordinates Point3.cs Overridden ToString method 45

46 1 // Circle4.cs 2 // Circle4 class that inherits from class Point3. 4 using System; 6 // Circle4 class definition inherits from Point3 7 public class Circle4 : Point3 8 { 9 private double radius; // default constructor 12 public Circle4() 13 { 14 // implicit call to Point constructor occurs here 15 } 17 // constructor 18 public Circle4( int xvalue, int yvalue, double radiusvalue ) 19 : base( xvalue, yvalue ) 20 { 21 Radius = radiusvalue; 22 } 24 // property Radius 25 public double Radius 26 { 27 get 28 { 29 return radius; 30 } 32 set 33 { 34 if ( value >= 0 ) // validation needed 35 radius = value; Constructor with implicit call to base class constructor Circle4.cs Constructor with explicit call to base class constructor Explicit call to base class constructor 46

47 36 } 38 } // end property Radius // calculate Circle diameter 41 public double Diameter() 42 { 43 return Radius * 2; // use property Radius 44 } // calculate Circle circumference 47 public double Circumference() 48 { 49 return Math.PI * Diameter(); 50 } // calculate Circle area 53 public virtual double Area() 54 { Method area declared virtual so it can be overridden 55 return Math.PI * Math.Pow( Radius, 2 ); // use property 56 } // return string representation of Circle4 59 public override string ToString() 60 { 61 // use base reference to return Point string representation 62 return "Center= " + base.tostring() + 63 "; Radius = " + Radius; // use property Radius 64 } 66 } // end class Circle4 Circle4.cs Circle4 s ToString method overrides Point3 s ToString method Call Point3 s ToString method to display coordinates 47

48 1 // CircleTest4.cs 2 // Testing class Circle4. 4 using System; 5 using System.Windows.Forms; 7 // CircleTest4 class definition 8 class CircleTest4 9 { 10 // main entry point for application 11 static void Main( string[] args ) 12 { 13 // instantiate Circle4 14 Circle4 circle = new Circle4( 37, 43, 2.5 ); // get Circle4's initial x-y coordinates and radius 17 string output = "X coordinate is " + circle.x + "\n" + 18 "Y coordinate is " + circle.y + "\n" + 19 "Radius is " + circle.radius; Change coordinates and radius of Circle4 object 21 // set Circle4's x-y coordinates and radius to new values 22 circle.x = 2; 23 circle.y = 2; 24 circle.radius = 4.25; 26 // display Circle4's string representation 27 output += "\n\n" + 28 "The new location and radius of circle are " + 29 "\n" + circle + "\n"; // display Circle4's Diameter 32 output += "Diameter is " + 33 String.Format( "{0:F}", circle.diameter() ) + "\n"; 34 CircleTest4.cs Create new Circle4 object Implicit call to Circle4 s ToString method 48

49 35 // display Circle4's Circumference 36 output += "Circumference is " + 37 String.Format( "{0:F}", circle.circumference() ) + "\n"; // display Circle4's Area 40 output += "Area is " + 41 String.Format( "{0:F}", circle.area() ); MessageBox.Show( output, "Demonstrating Class Circle4" ); } // end method Main } // end class CircleTest4 CircleTest4.cs Call Circle s Circumference and Area methods for output 49

50 sealed Classes and Methods sealed is a keyword in C# (equivalent to final in Java) sealed methods cannot be overridden in a derived class Methods that are declared static and private, are implicitly sealed sealed classes cannot have any derived-classes Creating sealed classes can allow some runtime optimizations e.g., virtual method calls can be transformed into non-virtual method calls 50

51 Building Graphical User Interfaces Graphical user interface Allow interaction with program visually Give program distinct look and feel Built from window gadgets Is an object, accessed via keyboard or mouse 51

52 Some GUI components Frame TextBox Menu Bar Scrollbar Button 52

53 Using VS.NET to build a windows application (GUI) 53

54 After selecting OK 54

55 Run by selecting Debug Start Without Debugging 55

56 Can choose View Code or View Designer Design view 56

57 Can open the toolbox while in design view. 57

58 Select any component from toolbox The GUI components available in C#. Select and drag into the design Form 58

59 Drag the component inside the Form (or click in the Form after having clicked on the component) A Button has been selected from the Toolbox and placed into the Form 59

60 Inside the Form select the button and right-click get properties menu Use these to adjust the properties of the component (e.g., font used, background color, etc). 60

61 Adding events Select this to add events 61

62 Generating the event code Click is one of the available Events for Button. Double click on Click and VS will generate the event code. 62

63 The generated event related code All this code has been generated by VS.NET Programmer fills in this part 63

64 Introduction Control Label TextBox Button CheckBox ComboBox ListBox Panel ScrollBar Description An area in which icons or uneditable text can be displayed. An area in which the user inputs data from the keyboard. The area also can display information. An area that triggers an event when clicked. A GUI control that is either selected or not selected. A drop-down list of items from which the user can make a selection, by clicking an item in the list or by typing into the box, if permitted. An area in which a list of items is displayed from which the user can make a selection by clicking once on any element. Multiple elements can be selected. A container in which components can be placed. Allows the user to access a range of values that cannot normally fit in its container. Some basic GUI components. 64

65 Windows Forms WinForms Create GUIs for programs Element on the desktop Represented by: Dialog Window MDI window 65

66 Basic Event Handling List of events supported by control Events icon Selected event Current even handler (none) Event description Events section of the Properties window. 66

67 1 // SimpleEventExample.cs 2 // Using Visual Studio.NET to create event handlers. 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; 11 // program that shows a simple event handler 12 public class MyForm : System.Windows.Forms.Form 13 { 14 private System.ComponentModel.Container components = null; // Visual Studio.NET generated code 18 [STAThread] 19 static void Main() 20 { 21 Application.Run( new MyForm() ); 22 } 24 // Visual Studio.NET creates an empty handler, 25 // we write definition: show message box when form clicked 26 private void MyForm_Click( object sender, System.EventArgs e ) 27 { 28 MessageBox.Show( "Form was pressed" ); 29 } } // end class MyForm SimpleEventExample.cs 67

68 Labels, TextBoxes and Buttons Labels Provide text instruction Read only text Defined with class Label Derived from class Control Textbox Class TextBox Area for text input Password textbox Button Control to trigger a specific action Checkboxes or radio buttons Derived from ButtonBase 68

69 Labels TextBoxes and Buttons Label Properties Common Properties Font Text TextAlign Description / Delegate and Event Arguments The font used by the text on the Label. The text to appear on the Label. The alignment of the Label s text on the control. One of three horizontal positions (left, center or right) and one of three vertical positions (top, middle or bottom). Label properties. 69

70 Labels TextBoxes and Buttons TextBox Properties and Events Common Properties Description / Delegate and Event Arguments AcceptsReturn Multiline PasswordChar ReadOnly ScrollBars Text Common Events TextChanged TextBox properties and events. If true, pressing Enter creates a new line if textbox spans multiple lines. If false, pressing Enter clicks the default button of the form. If true, textbox can span multiple lines. Default is false. Single character to display instead of typed text, making the TextBox a password box. If no character is specified, Textbox displays the typed text. If true, TextBox has a gray background and its text cannot be edited. Default is false. For multiline textboxes, indicates which scrollbars appear (none, horizontal, vertical or both). The text to be displayed in the text box. (Delegate EventHandler, event arguments EventArgs) Raised when text changes in TextBox (the user added or deleted characters). Default event when this control is double clicked in the designer. 70

71 Labels TextBoxes and Buttons Button properties and events Common Properties Text Common Events Click Button properties and events. Description / Delegate and Event Arguments Text displayed on the Button face. (Delegate EventHandler, event arguments EventArgs) Raised when user clicks the control. Default event when this control is double clicked in the designer. 71

72 Text area (a Textbox with properties Multiline and AcceptsReturn set to true. 72

73 An example GUI Textbox in which can type password Password displayed upon clicking button 73

74 using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WindowsApplication3_2 { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textbox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); The code Declared components // // TODO: Add any constructor code after InitializeComponent call // } 74

75 private void InitializeComponent() { this.textbox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.suspendlayout(); // // textbox1 // this.textbox1.location = new System.Drawing.Point(32, 48); this.textbox1.name = "textbox1"; this.textbox1.passwordchar = '*'; this.textbox1.size = new System.Drawing.Size(176, 20); this.textbox1.tabindex = 0; this.textbox1.text = ""; this.textbox1.textchanged += new System.EventHandler(this.textBox1_TextChanged); // Event handler for textbox, but never // label1 used. (added automatically by vs.net) // this.label1.backcolor = System.Drawing.SystemColors.Info; this.label1.location = new System.Drawing.Point(32, 96); this.label1.name = "label1"; this.label1.size = new System.Drawing.Size(176, 23); 75 this.label1.tabindex = 1; Construct components Set property so that chars appear as * when typed in textbox1.

76 // // button1 // this.button1.location = new System.Drawing.Point(48, 144); this.button1.name = "button1"; this.button1.size = new System.Drawing.Size(152, 23); this.button1.tabindex = 2; this.button1.text = "Show password"; this.button1.click += new System.EventHandler(this.button1_Click); // Event handler for button. (generated by vs // Form1.net, and implemented by programmer). // this.autoscalebasesize = new System.Drawing.Size(5, 13); this.clientsize = new System.Drawing.Size(292, 273); this.controls.addrange(new System.Windows.Forms.Control[] { this.button1, this.label1, this.textbox1}); this.name = "Form1"; this.text = "Form1"; this.resumelayout(false); } #endregion 76

77 /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components!= null) { components.dispose(); } } base.dispose( disposing ); } private void button1_click(object sender, System.EventArgs e) { label1.text = textbox1.text; } private void textbox1_textchanged(object sender, System.EventArgs e) { This line added by programmer. } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> /// <summary> 77

78 /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } } } 78

79 GroupBoxes and Panels Arrange components on a GUI GroupBoxes can display a caption Text property determines its caption Panels can have scrollbar View additional controls inside the Panel 79

80 GroupBoxes and Panels GroupBox Properties Common Properties Description Controls The controls that the GroupBox contains. Text Text displayed on the top portion of the GroupBox (its caption). GroupBox properties. 80

81 GroupBoxes and Panels Panel Properties Common Properties AutoScroll BorderStyle Controls Panel properties. Description Whether scrollbars appear when the Panel is too small to hold its controls. Default is false. Border of the Panel (default None; other options are Fixed3D and FixedSingle). The controls that the Panel contains. 81

82 Before any click. Example After click of button 1 Panel containing 2 buttons 82

83 using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WindowsApplication3_3 { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.GroupBox groupbox1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button4; private System.Windows.Forms.Label label1; /// <summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); Declared components The code // // TODO: Add any constructor code after InitializeComponent call // } 83

84 //.. private void InitializeComponent() { this.groupbox1 = new System.Windows.Forms.GroupBox(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); Construct this.panel1 = new System.Windows.Forms.Panel(); this.button3 = new System.Windows.Forms.Button(); components this.button4 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.groupbox1.suspendlayout(); this.panel1.suspendlayout(); this.suspendlayout(); Configure // // groupbox1 // components. this.groupbox1.backcolor = System.Drawing.SystemColors.Desktop; this.groupbox1.controls.addrange(new System.Windows.Forms.Control[] { this.button2, this.button1}); this.groupbox1.font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161))); this.groupbox1.location = new System.Drawing.Point(40, 32); this.groupbox1.name = "groupbox1"; this.groupbox1.size = new System.Drawing.Size(240, 96); this.groupbox1.tabindex = 0; this.groupbox1.tabstop = false; this.groupbox1.text = "GroupBox with 2 buttons"; Hookup to // // button1 // events this.button1.backcolor = System.Drawing.Color.Red; this.button1.font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161))); this.button1.location = new System.Drawing.Point(16, 40); this.button1.name = "button1"; this.button1.size = new System.Drawing.Size(80, 32); this.button1.tabindex = 0; this.button1.text = "button1"; this.button1.click += new System.EventHandler(this.button1_Click); 84

85 // // button2 // this.button2.backcolor = System.Drawing.Color.Red; this.button2.font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161))); this.button2.location = new System.Drawing.Point(144, 32); this.button2.name = "button2"; this.button2.size = new System.Drawing.Size(80, 32); this.button2.tabindex = 1; this.button2.text = "exit"; this.button2.click += new System.EventHandler(this.button2_Click); // // panel1 // this.panel1.backcolor = System.Drawing.SystemColors.Desktop; this.panel1.controls.addrange(new System.Windows.Forms.Control[] { this.button4, this.button3}); this.panel1.location = new System.Drawing.Point(40, 184); this.panel1.name = "panel1"; this.panel1.size = new System.Drawing.Size(224, 96); this.panel1.tabindex = 1; this.panel1.paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); // // button3 // this.button3.backcolor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192))); this.button3.font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161))); this.button3.forecolor = System.Drawing.SystemColors.ControlLightLight; this.button3.location = new System.Drawing.Point(16, 48); this.button3.name = "button3"; this.button3.size = new System.Drawing.Size(80, 32); this.button3.tabindex = 0; this.button3.text = "button3"; this.button3.click += new System.EventHandler(this.button3_Click); 85

86 // // button4 // this.button4.backcolor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192))); this.button4.font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161))); this.button4.forecolor = System.Drawing.SystemColors.ControlLightLight; this.button4.location = new System.Drawing.Point(136, 48); this.button4.name = "button4"; this.button4.size = new System.Drawing.Size(80, 32); this.button4.tabindex = 1; this.button4.text = "button4"; this.button4.click += new System.EventHandler(this.button4_Click); // // label1 // this.label1.backcolor = System.Drawing.Color.Yellow; this.label1.font = new System.Drawing.Font("Microsoft Sans Serif", 12F, (System.Drawing.FontStyle.Bold System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, ((System.Byte)(161))); this.label1.location = new System.Drawing.Point(64, 144); this.label1.name = "label1"; this.label1.size = new System.Drawing.Size(168, 23); this.label1.tabindex = 2; this.label1.text = "no button pressed"; this.label1.textalign = System.Drawing.ContentAlignment.MiddleCenter; // // Form1 // this.autoscalebasesize = new System.Drawing.Size(5, 13); this.clientsize = new System.Drawing.Size(296, 317); this.controls.addrange(new System.Windows.Forms.Control[] { this.label1, this.panel1, this.groupbox1}); this.name = "Form1"; this.text = "Form1"; this.groupbox1.resumelayout(false); this.panel1.resumelayout(false); this.resumelayout(false); } #endregion. 86

87 /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void panel1_paint(object sender, System.Windows.Forms.PaintEventArgs e) { }. Event handling for rendering the panel (automatically generated). Event handling code for the four buttons. private void button1_click(object sender, System.EventArgs e) { label1.text = "Button 1 pressed"; } private void button2_click(object sender, System.EventArgs e) { this.close(); } private void button3_click(object sender, System.EventArgs e) { label1.text = "Button 3 pressed"; } private void button4_click(object sender, System.EventArgs e) { label1.text = "Button 4 pressed"; } } } 87

1. Windows Forms 2. Event-Handling Model 3. Basic Event Handling 4. Control Properties and Layout 5. Labels, TextBoxes and Buttons 6.

1. 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 information

User-Defined Controls

User-Defined Controls 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 information

ListBox. Class ListBoxTest. Allows users to add and remove items from ListBox Uses event handlers to add to, remove from, and clear list

ListBox. 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 information

Blank Form. Industrial Programming. Discussion. First Form Code. Lecture 8: C# GUI Development

Blank Form. Industrial Programming. Discussion. First Form Code. Lecture 8: C# GUI Development Blank Form Industrial Programming Lecture 8: C# GUI Development Industrial Programming 1 Industrial Programming 2 First Form Code using System; using System.Drawing; using System.Windows.Forms; public

More information

Arrays. Arrays: Declaration and Instantiation. Array: An Array of Simple Values

Arrays. Arrays: Declaration and Instantiation. Array: An Array of Simple Values What Are Arrays? CSC 0 Object Oriented Programming Arrays An array is a collection variable Holds multiple values instead of a single value An array can hold values of any type Both objects (reference)

More information

Classes in C# namespace classtest { public class myclass { public myclass() { } } }

Classes in C# namespace classtest { public class myclass { public myclass() { } } } Classes in C# A class is of similar function to our previously used Active X components. The difference between the two is the components are registered with windows and can be shared by different applications,

More information

An array can hold values of any type. The entire collection shares a single name

An array can hold values of any type. The entire collection shares a single name CSC 330 Object Oriented Programming Arrays What Are Arrays? An array is a collection variable Holds multiple values instead of a single value An array can hold values of any type Both objects (reference)

More information

Building non-windows applications (programs that only output to the command line and contain no GUI components).

Building non-windows applications (programs that only output to the command line and contain no GUI components). C# and.net (1) Acknowledgements and copyrights: these slides are a result of combination of notes and slides with contributions from: Michael Kiffer, Arthur Bernstein, Philip Lewis, Hanspeter Mφssenbφck,

More information

LISTING PROGRAM. //Find the maximum and minimum values in the array int maxvalue = integers[0]; //start with first element int minvalue = integers[0];

LISTING PROGRAM. //Find the maximum and minimum values in the array int maxvalue = integers[0]; //start with first element int minvalue = integers[0]; 1 LISTING PROGRAM using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace SortingApplication static class Program / / The main entry point for

More information

CSC330 Object Oriented Programming. Inheritance

CSC330 Object Oriented Programming. Inheritance CSC330 Object Oriented Programming Inheritance Software Engineering with Inheritance Can customize derived classes to meet needs by: Creating new member variables Creating new methods Override base-class

More information

CSC 330 Object-Oriented Programming. Encapsulation

CSC 330 Object-Oriented Programming. Encapsulation CSC 330 Object-Oriented Programming Encapsulation Implementing Data Encapsulation using Properties Use C# properties to provide access to data safely data members should be declared private, with public

More information

Tutorial 5 Completing the Inventory Application Introducing Programming

Tutorial 5 Completing the Inventory Application Introducing Programming 1 Tutorial 5 Completing the Inventory Application Introducing Programming Outline 5.1 Test-Driving the Inventory Application 5.2 Introduction to C# Code 5.3 Inserting an Event Handler 5.4 Performing a

More information

Inheritance. Software Engineering with Inheritance. CSC330 Object Oriented Programming. Base Classes and Derived Classes. Class Relationships I

Inheritance. Software Engineering with Inheritance. CSC330 Object Oriented Programming. Base Classes and Derived Classes. Class Relationships I CSC0 Object Oriented Programming Inheritance Software Engineering with Inheritance Can customize derived classes to meet needs by: Creating new member variables Creating new methods Override base-class

More information

Sub To Srt Converter. This is the source code of this program. It is made in C# with.net 2.0.

Sub To Srt Converter. This is the source code of this program. It is made in C# with.net 2.0. Sub To Srt Converter This is the source code of this program. It is made in C# with.net 2.0. form1.css /* * Name: Sub to srt converter * Programmer: Paunoiu Alexandru Dumitru * Date: 5.11.2007 * Description:

More information

Polymorphism. Polymorphism. CSC 330 Object Oriented Programming. What is Polymorphism? Why polymorphism? Class-Object to Base-Class.

Polymorphism. Polymorphism. CSC 330 Object Oriented Programming. What is Polymorphism? Why polymorphism? Class-Object to Base-Class. Polymorphism CSC 0 Object Oriented Programming Polymorphism is considered to be a requirement of any true -oriented programming language (OOPL). Reminder: What are the other two essential elements in OOPL?

More information

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic Outline 6.1 Test-Driving the Enhanced Inventory Application 6.2 Variables 6.3 Handling the TextChanged

More information

Avoiding KeyStrokes in Windows Applications using C#

Avoiding KeyStrokes in Windows Applications using C# Avoiding KeyStrokes in Windows Applications using C# In keeping with the bcrypt.exe example cited elsewhere on this site, we seek a method of avoiding using the keypad to enter pass words and/or phrases.

More information

This is the start of the server code

This is the start of the server code This is the start of the server code using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Net; using System.Net.Sockets;

More information

In order to create your proxy classes, we have provided a WSDL file. This can be located at the following URL:

In order to create your proxy classes, we have provided a WSDL file. This can be located at the following URL: Send SMS via SOAP API Introduction You can seamlessly integrate your applications with aql's outbound SMS messaging service via SOAP using our SOAP API. Sending messages via the SOAP gateway WSDL file

More information

CHAPTER 3. Writing Windows C# Programs. Objects in C#

CHAPTER 3. Writing Windows C# Programs. Objects in C# 90 01 pp. 001-09 r5ah.ps 8/1/0 :5 PM Page 9 CHAPTER 3 Writing Windows C# Programs 5 9 Objects in C# The C# language has its roots in C++, Visual Basic, and Java. Both C# and VB.Net use the same libraries

More information

Flag Quiz Application

Flag Quiz Application T U T O R I A L 17 Objectives In this tutorial, you will learn to: Create and initialize arrays. Store information in an array. Refer to individual elements of an array. Sort arrays. Use ComboBoxes to

More information

Visual Studio Windows Form Application #1 Basic Form Properties

Visual Studio Windows Form Application #1 Basic Form Properties Visual Studio Windows Form Application #1 Basic Form Properties Dr. Thomas E. Hicks Computer Science Department Trinity University Purpose 1] The purpose of this tutorial is to show how to create, and

More information

Introduction to Microsoft.NET

Introduction to Microsoft.NET Introduction to Microsoft.NET.NET initiative Introduced by Microsoft (June 2000) Vision for embracing the Internet in software development Independence from specific language or platform Applications developed

More information

this.openfiledialog = new System.Windows.Forms.OpenFileDialog(); this.label4 = new System.Windows.Forms.Label(); this.

this.openfiledialog = new System.Windows.Forms.OpenFileDialog(); this.label4 = new System.Windows.Forms.Label(); this. form.designer.cs namespace final { partial class Form1 { private System.ComponentModel.IContainer components = null; should be disposed; otherwise, false. protected override void Dispose(bool disposing)

More information

Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects

Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects 1 Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline 19.1 Test-Driving the Microwave Oven Application 19.2 Designing the Microwave Oven Application 19.3 Adding a New

More information

CIS 3260 Sample Final Exam Part II

CIS 3260 Sample Final Exam Part II CIS 3260 Sample Final Exam Part II Name You may now use any text or notes you may have. Computers may NOT be used. Vehicle Class VIN Model Exhibit A Make Year (date property/data type) Color (read-only

More information

Web Services in.net (2)

Web Services in.net (2) Web Services in.net (2) These slides are meant to be for teaching purposes only and only for the students that are registered in CSE4413 and should not be published as a book or in any form of commercial

More information

Inheriting Windows Forms with Visual C#.NET

Inheriting Windows Forms with Visual C#.NET Inheriting Windows Forms with Visual C#.NET Overview In order to understand the power of OOP, consider, for example, form inheritance, a new feature of.net that lets you create a base form that becomes

More information

PS2 Random Walk Simulator

PS2 Random Walk Simulator PS2 Random Walk Simulator Windows Forms Global data using Singletons ArrayList for storing objects Serialization to Files XML Timers Animation This is a fairly extensive Problem Set with several new concepts.

More information

LISTING PROGRAM. // // TODO: Add constructor code after the InitializeComponent()

LISTING PROGRAM. // // TODO: Add constructor code after the InitializeComponent() A-1 LISTING PROGRAM Form Mainform /* * Created by SharpDevelop. * User: Roni Anggara * Date: 5/17/2016 * Time: 8:52 PM * * To change this template use Tools Options Coding Edit Standard Headers. */ using

More information

UNIT III APPLICATION DEVELOPMENT ON.NET

UNIT III APPLICATION DEVELOPMENT ON.NET UNIT III APPLICATION DEVELOPMENT ON.NET Syllabus: Building Windows Applications, Accessing Data with ADO.NET. Creating Skeleton of the Application Select New->Project->Visual C# Projects->Windows Application

More information

Visual 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 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 information

CST242 Windows Forms with C# Page 1

CST242 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 information

Classes and Objects. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

Classes and Objects. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1) Classes and Objects Andrew Cumming, SoC Introduction to.net Bill Buchanan, SoC W.Buchanan (1) Course Outline Introduction to.net Day 1: Morning Introduction to Object-Orientation, Introduction to.net,

More information

namespace Tst_Form { private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components;

namespace Tst_Form { private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components; Exercise 9.3 In Form1.h #pragma once #include "Form2.h" Add to the beginning of Form1.h #include #include For srand() s input parameter namespace Tst_Form using namespace System; using

More information

Arrays (Deitel chapter 7)

Arrays (Deitel chapter 7) Arrays (Deitel chapter 7) Plan Arrays Declaring and Creating Arrays Examples Using Arrays References and Reference Parameters Passing Arrays to Methods Sorting Arrays Searching Arrays: Linear Search and

More information

Operatii pop si push-stiva

Operatii pop si push-stiva Operatii pop si push-stiva Aplicatia realizata in Microsoft Visual Studio C++ 2010 permite simularea operatiilor de introducere si extragere a elementelor dintr-o structura de tip stiva.pentru aceasta

More information

Classes and Objects. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

Classes and Objects. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1) Classes and Objects Andrew Cumming, SoC Bill Buchanan, SoC W.Buchanan (1) Course Outline 11-12am 12-1pm: 1-1:45pm 1:45-2pm:, Overview of.net Framework,.NET Components, C#. C# Language Elements Classes,

More information

C# Forms and Events. Evolution of GUIs. Macintosh VT Datavetenskap, Karlstads universitet 1

C# Forms and Events. Evolution of GUIs. Macintosh VT Datavetenskap, Karlstads universitet 1 C# Forms and Events VT 2009 Evolution of GUIs Until 1984, console-style user interfaces were standard Mostly dumb terminals as VT100 and CICS Windows command prompt is a holdover In 1984, Apple produced

More information

CSC 211 Intermediate Programming

CSC 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 information

Overview Describe the structure of a Windows Forms application Introduce deployment over networks

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 information

The Microsoft.NET Framework

The Microsoft.NET Framework Microsoft Visual Studio 2005/2008 and the.net Framework The Microsoft.NET Framework The Common Language Runtime Common Language Specification Programming Languages C#, Visual Basic, C++, lots of others

More information

Event-based Programming

Event-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 information

CALCULATOR APPLICATION

CALCULATOR APPLICATION CALCULATOR APPLICATION Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;

More information

and event handlers Murach's C# 2012, C6 2013, Mike Murach & Associates, Inc. Slide 1

and event handlers Murach's C# 2012, C6 2013, Mike Murach & Associates, Inc. Slide 1 Chapter 6 How to code methods and event handlers Murach's C# 2012, C6 2013, Mike Murach & Associates, Inc. Slide 1 Objectives Applied 1. Given the specifications for a method, write the method. 2. Give

More information

Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime

Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime Intro C# Intro C# 1 Microsoft's.NET platform and Framework.NET Enterprise Servers Visual Studio.NET.NET Framework.NET Building Block Services Operating system on servers, desktop, and devices Web Services

More information

You can call the project anything you like I will be calling this one project slide show.

You can call the project anything you like I will be calling this one project slide show. C# Tutorial Load all images from a folder Slide Show In this tutorial we will see how to create a C# slide show where you load everything from a single folder and view them through a timer. This exercise

More information

EEE-425 Programming Languages (2013) 1

EEE-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 information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

Lampiran B. Program pengendali

Lampiran B. Program pengendali Lampiran B Program pengendali #pragma once namespace serial using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms;

More information

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

IST311. Advanced Issues in OOP: Inheritance and Polymorphism IST311 Advanced Issues in OOP: Inheritance and Polymorphism IST311/602 Cleveland State University Prof. Victor Matos Adapted from: Introduction to Java Programming: Comprehensive Version, Eighth Edition

More information

Nasosoft Barcode for.net

Nasosoft Barcode for.net Nasosoft Barcode for.net Table of Contents Overview of Nasosoft Barcode for.net 1 Nasosoft Barcode for.net Features... 1 Install Nasosoft Barcode for.net... 4 System Requirements... 4 Install and Uninstall

More information

IBSDK Quick Start Tutorial for C# 2010

IBSDK Quick Start Tutorial for C# 2010 IB-SDK-00003 Ver. 3.0.0 2012-04-04 IBSDK Quick Start Tutorial for C# 2010 Copyright @2012, lntegrated Biometrics LLC. All Rights Reserved 1 QuickStart Project C# 2010 Example Follow these steps to setup

More information

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd El-Shorouk Academy Acad. Year : 2013 / 2014 High Institute of Computer Science & Information Technology Term : 1 st Year : 2 nd Computer Science Department Object Oriented Programming Section (1) Arrays

More information

Welcome Application. Introducing the Visual Studio.NET IDE. Objectives. Outline

Welcome 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 information

Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1) Andrew Cumming, SoC Bill Buchanan, SoC W.Buchanan (1) Course Outline 11-12am 12-1pm: 1-1:45pm 1:45-2pm:, Overview of.net Framework,.NET Components, C#. C# Language Elements Classes, Encapsulation, Object-Orientation,

More information

Experiment 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 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 information

EEE-425 Programming Languages (2013) 1

EEE-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 information

Arrays Data structures Related data items of same type Remain same size once created Fixed-length entries

Arrays Data structures Related data items of same type Remain same size once created Fixed-length entries CBOP3203 Arrays Data structures Related data items of same type Remain same size once created Fixed-length entries A 12 element Array Index Also called subscript Position number in square brackets Must

More information

Visual Basic/C# Programming (330)

Visual Basic/C# Programming (330) Page 1 of 12 Visual Basic/C# Programming (330) REGIONAL 2017 Production Portion: Program 1: Calendar Analysis (400 points) TOTAL POINTS (400 points) Judge/Graders: Please double check and verify all scores

More information

C# Programming: From Problem Analysis to Program Design. Fourth Edition

C# Programming: From Problem Analysis to Program Design. Fourth Edition C# Programming: From Problem Analysis to Program Design Fourth Edition Preface xxi INTRODUCTION TO COMPUTING AND PROGRAMMING 1 History of Computers 2 System and Application Software 4 System Software 4

More information

Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1)

Introduction to.net. Andrew Cumming, SoC. Introduction to.net. Bill Buchanan, SoC. W.Buchanan (1) Andrew Cumming, SoC Bill Buchanan, SoC W.Buchanan (1) Course Outline Day 1: Morning Introduction to Object-Orientation, Introduction to.net, Overview of.net Framework,.NET Components. C#. Day 1: Afternoon

More information

Object oriented lab /second year / review/lecturer: yasmin maki

Object oriented lab /second year / review/lecturer: yasmin maki 1) Examples of method (function): Note: the declaration of any method is : method name ( parameters list ).. Method body.. Access modifier : public,protected, private. Return

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Chapter 12 - Graphical User Interface Concepts: Part 1

Chapter 12 - Graphical User Interface Concepts: Part 1 Chapter 12 - Graphical User Interface Concepts: Part 1 1 12.1 Introduction 12.2 Windows Forms 12.3 Event-Handling Model 12.3.1 Basic Event Handling 12.4 Control Properties and Layout 12.5 Labels, TextBoxes

More information

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at:

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at: This document describes how to create a simple Windows Forms Application using some Open Core Interface functions in C# with Microsoft Visual Studio Express 2013. 1 Preconditions The Open Core Interface

More information

Convertor Binar -> Zecimal Rosu Alin, Calculatoare, An2 Mod de Functionare: Am creat un program, in Windows Form Application, care converteste un

Convertor Binar -> Zecimal Rosu Alin, Calculatoare, An2 Mod de Functionare: Am creat un program, in Windows Form Application, care converteste un Convertor Binar -> Zecimal Rosu Alin, Calculatoare, An2 Mod de Functionare: Am creat un program, in Windows Form Application, care converteste un numar binar, in numar zecimal. Acest program are 4 numericupdown-uri

More information

Chapter 6 Introduction to Defining Classes

Chapter 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 information

Web Services in.net (7)

Web Services in.net (7) Web Services in.net (7) These slides are meant to be for teaching purposes only and only for the students that are registered in CSE4413 and should not be published as a book or in any form of commercial

More information

Chapter 12: Using Controls

Chapter 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 information

BackgroundWorker Component Overview 1 Multithreading with the BackgroundWorker Component 3 Walkthrough Running an Operation in the Background 10 How

BackgroundWorker Component Overview 1 Multithreading with the BackgroundWorker Component 3 Walkthrough Running an Operation in the Background 10 How BackgroundWorker Component Overview 1 Multithreading with the BackgroundWorker Component 3 Walkthrough Running an Operation in the Background 10 How to Download a File in the Background 15 How to Implement

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

Full file at

Full file at T U T O R I A L 3 Objectives In this tutorial, you will learn to: 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.

More information

UNIT-3. Prepared by R.VINODINI 1

UNIT-3. Prepared by R.VINODINI 1 Prepared by R.VINODINI 1 Prepared by R.VINODINI 2 Prepared by R.VINODINI 3 Prepared by R.VINODINI 4 Prepared by R.VINODINI 5 o o o o Prepared by R.VINODINI 6 Prepared by R.VINODINI 7 Prepared by R.VINODINI

More information

DAD Lab. 1 Introduc7on to C#

DAD Lab. 1 Introduc7on to C# DAD 2017-18 Lab. 1 Introduc7on to C# Summary 1..NET Framework Architecture 2. C# Language Syntax C# vs. Java vs C++ 3. IDE: MS Visual Studio Tools Console and WinForm Applica7ons 1..NET Framework Introduc7on

More information

Laboratorio di Ingegneria del Software

Laboratorio 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 information

Laboratorio di Ingegneria del L-A

Laboratorio 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 information

11. Arrays. For example, an array containing 5 integer values of type int called foo could be represented as:

11. Arrays. For example, an array containing 5 integer values of type int called foo could be represented as: 11. Arrays An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier. That means that, for example,

More information

SMITE API Developer Guide TABLE OF CONTENTS

SMITE API Developer Guide TABLE OF CONTENTS SMITE API Developer Guide TABLE OF CONTENTS TABLE OF CONTENTS DOCUMENT CHANGE HISTORY GETTING STARTED Introduction Registration Credentials Sessions API Access Limits API METHODS & PARAMETERS APIs Connectivity

More information

Chapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program)

Chapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program) Chapter - Arrays 1.1 Introduction 2.1 Introduction.2 Arrays.3 Declaring Arrays. Examples Using Arrays.5 Passing Arrays to Functions.6 Sorting Arrays. Case Study: Computing Mean, Median and Mode Using Arrays.8

More information

Introduction. Create a New Project. Create the Main Form. Assignment 1 Lights Out! in C# GUI Programming 10 points

Introduction. Create a New Project. Create the Main Form. Assignment 1 Lights Out! in C# GUI Programming 10 points Assignment 1 Lights Out! in C# GUI Programming 10 points Introduction In this lab you will create a simple C# application with a menu, some buttons, and an About dialog box. You will learn how to create

More information

Chapter 9 - Object-Oriented Programming: Polymorphism

Chapter 9 - Object-Oriented Programming: Polymorphism Chapter 9 - Object-Oriented Programming: Polymorphism Polymorphism Program in the general Introduction Treat objects in same class hierarchy as if all superclass Abstract class Common functionality Makes

More information

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition 11 Features Advanced Object-Oriented Programming C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition Chapter Objectives 2 Chapter

More information

Web Services in.net (6) cont d

Web Services in.net (6) cont d Web Services in.net (6) cont d These slides are meant to be for teaching purposes only and only for the students that are registered in CSE3403 and should not be published as a book or in any form of commercial

More information

Inheritance (Deitel chapter 9)

Inheritance (Deitel chapter 9) Inheritance (Deitel chapter 9) 1 2 Plan Introduction Superclasses and Subclasses protected Members Constructors and Finalizers in Subclasses Software Engineering with Inheritance 3 Introduction Inheritance

More information

CSIS 1624 CLASS TEST 6

CSIS 1624 CLASS TEST 6 CSIS 1624 CLASS TEST 6 Instructions: Use visual studio 2012/2013 Make sure your work is saved correctly Submit your work as instructed by the demmies. This is an open-book test. You may consult the printed

More information

Chapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program) A few types

Chapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program) A few types Chapter 4 - Arrays 1 4.1 Introduction 4.2 Arrays 4.3 Declaring Arrays 4.4 Examples Using Arrays 4.5 Passing Arrays to Functions 4.6 Sorting Arrays 4.7 Case Study: Computing Mean, Median and Mode Using

More information

Conventions in this tutorial

Conventions in this tutorial This document provides an exercise using Digi JumpStart for Windows Embedded CE 6.0. This document shows how to develop, run, and debug a simple application on your target hardware platform. This tutorial

More information

Subject to Change Drawing Application 1 Introducing Computers, the Internet and C#

Subject to Change Drawing Application 1 Introducing Computers, the Internet and C# CO N T E N T S Subject to Change 08-01-2003 Preface Before You Begin Brief Table of Contents i iv vii 1 Drawing Application 1 Introducing Computers, the Internet and C# 1.1 What Is a Computer? 1 1.2 Computer

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;

More information

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout 1 Last update: 2 November 2004 Trusted Components Reuse, Contracts and Patterns Prof. Dr. Bertrand Meyer Dr. Karine Arnout 2 Lecture 26: Component model: The.NET example Agenda for today 3 What is.net?

More information

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32 Contents 1 2 3 Contents Getting started 7 Introducing C# 8 Installing Visual Studio 10 Exploring the IDE 12 Starting a Console project 14 Writing your first program 16 Following the rules 18 Summary 20

More information

Chapter 9 - Object-Oriented Programming: Inheritance

Chapter 9 - Object-Oriented Programming: Inheritance Chapter 9 - Object-Oriented Programming: Inheritance 9.1 Introduction 9.2 Superclasses and Subclasses 9.3 protected Members 9.4 Relationship between Superclasses and Subclasses 9.5 Case Study: Three-Level

More information

Events. Event Handler Arguments 12/12/2017. EEE-425 Programming Languages (2016) 1

Events. 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 information

Framework Fundamentals

Framework Fundamentals Questions Framework Fundamentals 1. Which of the following are value types? (Choose all that apply.) A. Decimal B. String C. System.Drawing.Point D. Integer 2. Which is the correct declaration for a nullable

More information

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class. 1. What is C#? C# (pronounced "C sharp") is a simple, modern, object oriented, and type safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity

More information

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer

To 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 information

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations , 1 C#.Net VT 2009 Course Contents C# 6 hp approx. BizTalk 1,5 hp approx. No exam, but laborations Course contents Architecture Visual Studio Syntax Classes Forms Class Libraries Inheritance Other C# essentials

More information

.NET XML Web Services

.NET XML Web Services .NET XML Web Services Bill Buchanan Course Outline Day 1: Introduction to Object-Orientation, Introduction to.net, Overview of.net Framework,.NET Components. C#. Introduction to Visual Studio Environment..

More information