Learn C# (C sharp) in FREE step-by-step lessons.
Module 03: Writing Code in C#
We have learned to change properties at design time.
In this lesson we will learn to write code.
In C# we will write code to execute when an event occurs:
- when the form loads,
- when the user clicks a button,
- or makes a choice,
- or one of the other events that occur.
Sometimes we will use the code to change properties of the form or the controls.
For instance we want to change the backcolor of the form when the user clicks BtnRed.
We may want to hide a control under certain circumstances.
The possibilities are endless! Let's get started!
Goals:
- Write code in C#, to change Properties and create a console app
Objectives:
- Be familiar with coding standards;
- write code to change properties of a form;
- Understand why comments are important and add them to the code;
- Add code to respond to events for controls;
- Understand the arguments in Mouse Move Event;
- Use the text box control;
- Understand and be able to use the debugging tools;
- Be able to create a console app.
Please study the material at each of the links below.
Microsoft Reference: C# Coding Standards
Writing Code to change properties of the form: Instead of changing properties in the design view, it can be done with code.- Comments: Comments are notes a programmer makes about the code
Code created: An explanation of each line of code
Adding events for controls: Some events can be added by double clicking on the control
Adding items to listbox at runtime: Clicking a button adds the conents of a text box to a list box.
Changing the location of a control: The location is a Point with x and y values
Mouse Move Event, Arguments: The mousemove event has argument e that has the location
Using the TextBox Control: After user types their name and presses a button,
a greeting is displayed
Using the Scroll Bar Control: A scrollbar is used to select inches
Debugging Tools: A few tools for debugging are shown
Creating a Console App: A console app runs in the system window instead of a form
Glossary for code lesson
Full Glossary