Gaming Community
Forum
 
Go Back   D3scene > Software/Hardware > Development
Register Blogs Live view Downloads Marketplace FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

[TuT] (C#) Introduction to C# Programming Part 2

This is a discussion on [TuT] (C#) Introduction to C# Programming Part 2 within the Development forum part of the Software/Hardware category; Welcome to Wynthar's C# Tutorial Series Tutorial 2: More Windows Forms Features Introduction So in the Last Tutorial we downloaded ...


Welcome on D3scene.com! Make sure to register - it's free and very quick! You have to register before you can post and participate in our discussions with 70000 other registered members. Downloads, user profiles and some forums can only be seen by registered members. After you create your free account you will be able to customize many options, you will have the full access to new hacks, latest cheats and last but not least will see no advertisements at all. We would love to see you around in our community!
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 04-14-2009, 05:21 AM
Wynthar's Avatar
Advanced Hacker

 
Join Date: Feb 2009
Location: So Cal, USA
Posts: 264
Thanks: 30
Thanked 39 Times in 15 Posts
Reputation: 235
Rep Power: 2
Wynthar has a spectacular aura aboutWynthar has a spectacular aura aboutWynthar has a spectacular aura about
[TuT] (C#) Introduction to C# Programming Part 2

Welcome to Wynthar's C# Tutorial Series
Tutorial 2: More Windows Forms Features

Introduction
So in the Last Tutorial we downloaded Microsoft Visual C# Express Edition and created our first windows forms application. I hope you have at least tried to play around with the code we used. Experiment, change the string. See the results. If you have not managed to make enough changes that the program does not compile, you are not experimenting enough.

Let's Begin
When creating forms, I usually find that it's easiest to develop the user interface the way I want it to work first, then program in the functionality for all of the forms objects. So, let's add a pair of buttons, a check box, a text box and see what we can do with these. So, let's create our Tutorial 2 project.

Go to File->New Project... Select Windows Forms Application. Set the Name to Tutorial2 and click OK.



Next
In the tool box, click on the [+] Common Controls to expand that menu. And click on Button.

Now go over to your form, and click in the middle of your form. It should create a button for you.

Repeat this process once more to create two buttons.



Next
Now, scroll down in the tool box and select TextBox. Click somewhere to the right of your first button.



Next
I had to scroll up a little to find CheckBox. Click on CheckBox and click on our form to the right of the second button.



Next
Let's add one more item to our form. Click on Label and add a label someplace below the other objects we already have.



Next
Excellent. Our user interface for this tutorial is now complete.

Now, let's add some functionality to the program.

First, let's add some functionality to button1. So, double click on button1.

Enter the following into the function where the cursor is.

Code:
private void button1_Click(object sender, EventArgs e)
{
	//This takes the value out of the textBox1
	//And changes the form's title to the value
	//Of the text box.
	string newWindowTitle = "Title: " + textBox1.Text;
	this.Text = newWindowTitle;
}
Code Explaination

So. I'll explain this code a bit. The forward slashes are comments. Comments are not read by the compiler. They are useful for making your code easier to read. It can also be helpful to add in reminders to yourself about what is happening in your code.

I created a new variable of type "string" with a variable name of "newWindowTitle" and I set it equal to the string "Title: " then I attached the text from textBox1 to the end of the string.

For example, if someone types "Hello" into the text box, then our string newWindowTitle will equal "Title: " + "Hello", which is added together and results in a single string, "Title: Hello"

The final line of our function sets the current form's title to our string variable newWindowTitle. The keyword "this" refers to whichever object we are currently in. Since, our code currently resides in Form1, "this" refers to Form1.

I have found out that the Form1.Text refers to the form's title. Therefore, when we set this.Text = newWindowTitle; we will be changing the form's title to "Title: Whatever Is In The Text Box"



Next
Okay, so now go back to the tab Form1.cs [Design] then double click on button2 to create a method stub for button2. Enter the following code.

Code:
private void button2_Click(object sender, EventArgs e)
{
    //This button changes the text on the label
    //based on check box value.
    if (checkBox1.Checked == true)
    {
        label1.Text = "Check box is checked!";
    }
    else
    {
        label1.Text = "You didn't check the checkbox.";
    }
}
Code Explaination

Okay. Another fun feature of programming. The If/Else statement. It should be pretty logical. We check here if our checkBox1 is checked by accessing the checkBox1.Checked variable and seeing if it equals (==) true.

If it does equal true, that means it is checked. Then we go execute the code between the braces. This code for the true case reads label1.Text = "Check box is checked!" Similar to setting the text of the form title, this will set the text for the label to our string.



Next
So, now press the green arrow again to compile and run. (Or hotkey F5)



Finally
If everything is correct you should be able to test out your form and the buttons. Here is a sample result that I came up with by playing with the form.




[Next Time]
  • We will go over Form Object Properties and how to set them.
  • Once again we will explore and practice more coding examples.

[Later]
  • If I get good feedback, I will continue these tutorials all the way up to making a simple map hack using some common offsets.
  • Please feel free to post your feedback, comments, questions, and other things you might like to see.
  • Thanks for reading guys!

[C# Tutorials]

Last edited by Wynthar; 04-15-2009 at 06:55 PM.
Reply With Quote
The Following 4 Users Say Thank You to Wynthar For This Useful Post:
D3scene
Welcome to D3scene - probably the best location for all Gamers.

To participate in our friendly environment you have to register. After completing registration you will have full access to all threads and features. We care about members and try to make your stay as pleasant as possible. We are unique with the following feature for members - you will not see a single Advertisement!


The best: registration is completely free. It will not cost you a single penny or harm you in any way. You will lose nothing except 1 minute of your time. So why not register? We would be happy to see you around!
  #2  
Old 04-14-2009, 07:28 AM
Morphex's Avatar
Mentor

 
Join Date: Dec 2008
Location: Norway, Ski
Posts: 132
Thanks: 2
Thanked 1 Time in 1 Post
Reputation: 39
Rep Power: 1
Morphex is on a distinguished road
Really nice tut for beginners ^^
Reply With Quote
  #3  
Old 04-14-2009, 01:06 PM
Newbie

 
Join Date: Apr 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Reputation: 0
Rep Power: 1
jWindz is an unknown quantity at this point
Very helpful.
So detaild tutorial, and with images. Good job!
Reply With Quote
  #4  
Old 04-14-2009, 01:17 PM
wtfdudes's Avatar
Hacker

 
Join Date: Dec 2008
Location: Austria
Posts: 185
Thanks: 16
Thanked 10 Times in 10 Posts
Reputation: 82
Rep Power: 1
wtfdudes will become famous soon enough
Send a message via ICQ to wtfdudes
Yeah, very helpful indeed.

Just skimmed over your tuto and as far as I can see it's plain and correct.
Definitely worth a .
Reply With Quote
  #5  
Old 04-14-2009, 01:37 PM
dog_keeper's Avatar
Teh Sexy One.


 
Join Date: Dec 2007
Location: The one and only person who lives far far away from all the people here on d3scene!
Posts: 2,297
Thanks: 144
Thanked 79 Times in 55 Posts
Reputation: 1129
Rep Power: 8
dog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud ofdog_keeper has much to be proud of
thanks. Really nice =]
Reply With Quote
  #6  
Old 04-27-2009, 06:57 AM
Banned User

 
Join Date: Oct 2008
Location: Australia
Posts: 2,862
Thanks: 29
Thanked 46 Times in 29 Posts
Reputation: 671
Rep Power: 0
risker is a splendid one to beholdrisker is a splendid one to beholdrisker is a splendid one to beholdrisker is a splendid one to beholdrisker is a splendid one to beholdrisker is a splendid one to behold
Send a message via MSN to risker
;D
Finished 2#
Going for 3#

+Rep
Reply With Quote
D3scene
Welcome to D3scene - probably the best location for all Gamers.

To participate in our friendly environment you have to register. After completing registration you will have full access to all threads and features. We care about members and try to make your stay as pleasant as possible. We are unique with the following feature for members - you will not see a single Advertisement!


The best: registration is completely free. It will not cost you a single penny or harm you in any way. You will lose nothing except 1 minute of your time. So why not register? We would be happy to see you around!
Reply

Tags
c#, programming, tutorial

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[TuT] (C#) Introduction to C# Programming Part 1 Wynthar Development 6 05-06-2009 05:41 PM
Evolution of Viruses risker Internet Guides 13 12-29-2008 07:51 AM


All times are GMT +1. The time now is 09:40 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0 ©2009, Crawlability, Inc.
vBulletin style developed by Transverse Styles