1 / 23

Language basics and first controls

Language basics and first controls. Learning Outcomes Part I. We will learn about : Data types Naming convention Assignments and comments Converting data types Math functions Operators and comparisons. Naming convention. C# is case sensitive Naming convention

yoshi
Download Presentation

Language basics and first controls

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

E N D

Presentation Transcript


  1. Language basics and first controls

  2. Learning OutcomesPart I We will learn about : • Data types • Naming convention • Assignments and comments • Converting data types • Math functions • Operators and comparisons

  3. Naming convention • C# is case sensitive Naming convention • Variables start with lowercase letter. • Methods and Classes start with Capital letter • Separate words with Uppercase letter : upperCase’ would be a variable. • Controls should start with three letters indicating the control: lblTitle, btnStop, txtName

  4. Data types Basic data types: Integer : byte, int, long Floating point: float, double Characters: char, string Logical: bool Declaration: Datatype name ( = initValue);

  5. Declarations Examples: const double PI =3.14159; const int MAXSIZE = 10, MINSIZE = 1; int Number; double Numberf = 34.5; char c1, c2; bool test = true; string Message = “Cancel”;

  6. Assignment and Comments Assignments: ‘=‘ var= expression; sum = one + two; Comments: /* Slash-star is a multi-line comment- end with a star-slash */ // a double slash which ignores the rest of the line

  7. Operators Operators: Usual operators and order of operation (precedence): +, -, *, /, % ==, !=, >, <, <=, >= Relational Logic operators: AND a = a & b; OR a= a | b; NOT a= !b; XOR a= a ^ b;

  8. Shortcuts Shortcuts X = X + 3; X+=3; div = div / 4; div /= 4; mult = mult * 5; mult *= 5; sub = sub - 2; sub -= 2; rem = rem%4; rem %= 4; Increment i++; ++i : decrement --i ; i--;

  9. Math functions Some Math functions: Sin, Cos, Tan, Exp Log - Returns the logarithm of a specified number. Log10 - Returns the base 10 logarithm. Pow - Returns a number raised to a specified power. Round - Rounds to the nearest integer or decimal places. Sqrt - Returns the square root of a specified number. Truncate - Calculates the integral part of a number. ‘

  10. Comparison == equal to != not equal to < less than <= less than or equal to > greater than >= greater than or equal to && AND || OR

  11. Summary Covered: • Variables constants and data types • Naming convention • Assignments and comments • Operators • Math functions • Logic Operations • Comparison

  12. Learning Outcomes Part II • You will learn about : • GUI • Controls • Button, TextBox, ListBox • Properties and Events • Dialog boxes

  13. GUI and Controls • GUI - Graphical User Interface • How your user interfaces with your program • You can make it really easy (or difficult) for the user! • Lots of controls • e.g. buttons, textboxes, labels, menus • You place them on the form • IDE groups similar controls together • You write code for them

  14. Common controls • Common Controls – in Toolbox • Button • TextBox • ListBox • Label • Checkbox • Radio buttons • Picture box • Menu • ..... • All have properties and events

  15. Button control • Main properties: • Appearance – Color, Image, Text • Behavior – Enabled, Visible • Design – Name • Layout – Location, Size • ........ • Main events: • Click • Double-click

  16. Text Box Control • Properties – Similar to button, but also text entry • Text (single line) • Lines (multiline) • MultiLine is a property • ReadOnly • Events • Keyboard events • TextChanged • Focus – Enter

  17. Text Box control • Reading text • Text property – all text • Individual lines: • textBox1.Lines[0]; • Add text using AppendText • textBox1.AppendText("new text"); • To add on new line: • textBox1.AppendText("\r\nnew last line"); • Backslash indicates non-printing characters • Number of Lines? • textBox1.Lines.Length

  18. TextBox Control • Conversion • String to int • int N; • N = Convert.ToInt(textBox1.Text); • or • N = int.Parse(textBox1.Text); • int to string: • int i = 20; • textBox1.AppendText(i.ToString())

  19. ListBox Control List of selectable items Properties: Items (collection) ScrollBars (Horizontal & Vertical) MultiColumn Events Click SelectedIndexChanged

  20. TextBox and ListBox TextBox and ListBox text properties Text – all the text in the text or list box. Lines[0] – first line of text or list box – read only AppendText(“new text”); – adds text to textbox Lines.Length – number of lines in textbox ListBox Items.Add(“new list item”); Items.Insert(lineNo, “inserted text”); Clear(); SelectedItem Data is a string – need to convert for numbers.

  21. Dialog Boxes Easy way to display text information. A dialog box is not a control it is displayed when program runs MessageBox.Show(Message);

  22. Dialog Boxes You Can add Caption, buttons and icon: MessageBox.Show("This will format your disk!", "Format caption", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); Check response with DialogResult.OK DialogResult.Cancel DialogResult.Yes …..

  23. Summary Covered • GUI • Controls • Button, Textbox etc • Properties and Events • Dialog boxes

More Related