Download presentation
Presentation is loading. Please wait.
Published byAlison Richard Modified over 9 years ago
1
Intro to More Controls in C#
2
C# Demonstration We already touched on labels and buttons Ad-hoc demo of controls – Textboxes Multiline – Checkbox – Radiobutton – Picturebox – Group box Tab order Tooltips
3
Events GUI applications are generally event-driven. – The application waits until some event occurs, and then executes some code to handle the event. – Typical user-initiated events Pressing a key Clicking the mouse – C# handle events by creating a method. A method is a grouping of code that performs a common task – We’ll start by creating button click events
4
Creating an Event Handler Double-click the control in the design view to bring up the most common event for that control Select the control in the design view, then click on the lightning bolt in the properties window to find the event you’re interested in for the selected control
5
Event Example For example, creating a button and then double- clicking it results in the following event handler: For now, don’t worry about the object sender, EventArgs e part. For now all you really need to know is that any code you enter between the curly braces will be executed when the button is clicked.
6
Event handler experimentation Try adding some code to change the properties of other controls on the form There are assignment statements that copy the value on the right into the object on the left (not the same as mathematical equality) Every statement ends in a semicolon
7
Methods In our code we can also invoke methods associated with some object – Methods have ()’s at the end; later we will put things inside the parenthesis textBox1.Clear(); textBox1.Text = ""; Method to clear the textbox Manually set the textbox to a blank Both do the same thing
8
String concatenation Text enclosed in "" are called strings We can concatenate (or glue together) two strings with the + symbol What will this do? textBox1.Text = textBox1.Text + " HELLO "; textBox2.Text = txtName.Text + " is your name ";
9
Comments Commenting helps explain how your code works Commenting can be used to disable code without deleting it if you want it back later // – Everything from // to the end of the line is ignored /* */ – Everything in between the /* and */ is ignored Can use these buttons on selected text // textBox1.Text = " HELLO "; /* textBox1.Text = " HELLO "; */
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.