C# - Lesson 5b - Visual C# overview + our first real programme

View previous topic View next topic Go down

C# - Lesson 5b - Visual C# overview + our first real programme

Post  Guest on Tue Dec 22, 2009 6:21 am

Ok, this lesson continues on lesson 5a. There we got our project set and we dragged a button onto our form.
This is what you should have now:



Now we are going to make the form and the button look a bit better before we start the programming.
When you look on the right side at the bottom of the UI you see a 'properties' panel. Now when you select the forum itself, you will see that in that properties panel by the '(Name)' property 'Form1' is written. This is the Name you give to this form object. This means that when you are programming this "Form1" string is meant for the form object.

Note:
You can actually make it any name you want, but watch out... To prevent from misunderstandings, never write spaces in the name, and neither use underscores _ or points . ,neither any other symbol because those symbols have other programming functions and we don't want the environment to mix them up. And again, it's tradition to write you names and strings like this: myName or myStringIsThis, so always a small letter for the first word and the others you can make capitals.


Ok, you can actually leave the form's name, you don't need to change that for now. Now, when you scroll down in the form's properties list, you can see the "Text" property. That property has nothing to do with any programming. This Text is the text that will show up on the upper bar of your form. So, click it and you can change it to "Hello World" for this tutorial. You will see your form upper bar changes to "Hello World".

Now to let our form look a bit nicer we gonna change its size. Go to the size property, and change it to 250 x 100. (First make sure your button is still visible in the field after you resized the form.)
Now, we gonna change the button's size so that it fits the form. You will need to make it look huge but that doesn't matter.
You now should have something like this:



As you can see when you drag the button around, the button snaps to the corners and the edges of the form to make your UI look a bit nicer.
Now we go to the button's properties and change the Text property to 'Click Here'. So where stood 'button1' before, should now stand 'Click Here'.
Our UI is done now.

Let's start programming.
When you double click your button, the real programming code page shows up.
Your code should look like this if you haven't typed anything yet:


Code:
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;

namespace HelloWorld
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}

Your cursor will be automaticly set to the void of the object you double clicked. In this case the button.
This void will process when the button1 is clicked. (remember the name is still button1, you only changed it's Text property)
So, we want a MessageBox to show up with the words "Hello World" when we push the button.
For that we first need to call the MessageBox function.
Below is the private void of the button shown with the MessageBox function typed inside it:

Code:
private void button1_Click(object sender, EventArgs e)
        {
            MessageBox
        }

Note:
In the coding window will be drawn a red line under the "MessageBox" because it has nothing to show yet. There will always show up a red line if the code is not debuggable. That means that's it's not gonna work.
You will also see the box under your word when you are typing "MessageBox", this box is the auto helper for finding your functions. This very handy to program in a fast way.


So, to continue we need to type a point behind the MessageBox function, that means "in the function MessageBox, we are looking for the subfunction ...". When you are typing the point you will see that box under it again and it gives you 3 subfunctions. (Equals, ReferenceEquals and Show) For now we are going to take the Show subfunction. That means the MessageBox will Show up. (when the button is clicked)
Now you should have this:

Code:
private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show
        }

Now we have set enough functions. The actually content of the MessageBox comes now.
Behind the Show subfunction you gonna type this: ("Hello World")
This means the MessageBox will show you those words.

Note:
Don't forget the ; behind your MessageBox line of code. This is almost always needed in C#!


Your code should look like this now:

Code:
private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello World");
        }

Now the code for your programme is set.
It's time to test it.
In the toolbar, somewhere under the button 'Data' you see this little green arrow ()
Push that, and it will debug your code and will show your programme.
This is what is should look like when the button is pushed:



In the image the code and programme is shown.

I hope you brought this to work smoothly, and enjoyed your first programme.
You now have achieved the n00b-programmer achievement. Good job. Wink Razz

Guest
Guest


Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Beazt on Thu Apr 15, 2010 9:51 am

okey, this teached me to make my first programme, but how do I save to to .exe file type?
edit: nvm I found were it got compiled
avatar
UF Beazt
UF Member
UF Member

Posts : 968
Join date : 2009-09-11
Age : 22
Location : Helsinki

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  Guest on Fri Apr 16, 2010 2:31 am

in the bin map of your project ^^

Guest
Guest


Back to top Go down

coo;

Post  ComitteD on Mon Jun 06, 2011 9:57 pm

cool, I am happy to see that this clan is doing stuff like that. Thats the reason I joined i4Ni before this to be with my designer friends. I wished I would have joined UF instead of i4Ni before. At least I am here now:)

ComitteD
Guest
Guest

Posts : 19
Join date : 2011-06-02

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Vishna on Tue Jun 07, 2011 4:34 am

And your welcome to stay here. . . Wink
Btw are you doing web design?
avatar
UF Vishna
UF Member
UF Member

Posts : 560
Join date : 2010-04-30
Age : 23
Location : Estonia

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Beazt on Tue Jun 07, 2011 4:42 am

UF ComitteD wrote:cool, I am happy to see that this clan is doing stuff like that. Thats the reason I joined i4Ni before this to be with my designer friends. I wished I would have joined UF instead of i4Ni before. At least I am here now:)
Not sure is anyone doing really this stuff. Xorax wrote this tutorial several months ago. I tried to learn at start but didnt understood much. Maybe will give it another try since im studying pascal in school and understand some basic things now.
avatar
UF Beazt
UF Member
UF Member

Posts : 968
Join date : 2009-09-11
Age : 22
Location : Helsinki

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Vishna on Tue Jun 07, 2011 4:49 am

Well if anyone needs somekind help with programming or just wants to talk about that, then you can contact me, since im on programming atm. You can ask about HTML, CSS, Javascript, C++, cause i have learned those. Im not saying that im expert on those, but somehwere in middle. Very Happy
avatar
UF Vishna
UF Member
UF Member

Posts : 560
Join date : 2010-04-30
Age : 23
Location : Estonia

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Beazt on Tue Jun 07, 2011 5:33 am

did you learned them by yourself or had a course or something?
avatar
UF Beazt
UF Member
UF Member

Posts : 968
Join date : 2009-09-11
Age : 22
Location : Helsinki

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Vishna on Tue Jun 07, 2011 5:35 am

Mostly myself, but C++ learned in school in Mechatronics and Robotics class
avatar
UF Vishna
UF Member
UF Member

Posts : 560
Join date : 2010-04-30
Age : 23
Location : Estonia

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Spartan19423 on Tue Jun 07, 2011 12:42 pm

UF Beazt wrote:
UF ComitteD wrote:cool, I am happy to see that this clan is doing stuff like that. Thats the reason I joined i4Ni before this to be with my designer friends. I wished I would have joined UF instead of i4Ni before. At least I am here now:)
Not sure is anyone doing really this stuff. Xorax wrote this tutorial several months ago. I tried to learn at start but didnt understood much. Maybe will give it another try since im studying pascal in school and understand some basic things now.

Just to say, it is way more harder to study this, when you dont have an actual person right there to explain the differances to you, because it can be quite confusing at times. If you are considering of doing something, then Vishna will be probably a lot of help to you. That is if you are consider doing something in C++ .

_________________
avatar
UF Spartan19423
UF Admin
UF Admin

Posts : 1635
Join date : 2009-01-28
Age : 23
Location : Estonia

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Beazt on Tue Jun 07, 2011 1:33 pm

I would imagine different programming languages are similar, I mean they have different commands and functions but logical thinking and basics are still pretty much the same.
But im not really considering learning c++ now. Im busy learning proper modeling in max so its enough of new information for me. especially in summer
avatar
UF Beazt
UF Member
UF Member

Posts : 968
Join date : 2009-09-11
Age : 22
Location : Helsinki

Back to top Go down

Learn More on C#

Post  Shawnm1700 on Thu Nov 03, 2011 5:17 pm

I have been learning from this "Book" for a while i found it "Somewhere" and i think you guys will like it

Download Its a .Pdf

i know the post is old but if you see it you will like it i think
avatar
Shawnm1700
Guest
Guest

Posts : 2
Join date : 2011-06-08
Age : 22
Location : In your moms bed ^_^

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Garanas on Thu Nov 03, 2011 11:13 pm

After a long time of trying, I realized that programming and stuff maybe me not my thing.
It is just, quite complicated Razz

Maybe I might try to use the book Wink

_________________
[quote="UF Beazt"] ... is a good idea! [quote="UF Spartan19423"]
YOU HAVE DONE OUTSTANDING WORK!
[/quote][/quote]
avatar
UF Garanas
UF Member
UF Member

Posts : 998
Join date : 2011-01-10
Age : 22
Location : Netherlands

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Vishna on Fri Nov 04, 2011 7:39 am

Hmm seems thorough, maybe I will try it to someday, when I go back to C langeuage. Atm I'm learning Java.
avatar
UF Vishna
UF Member
UF Member

Posts : 560
Join date : 2010-04-30
Age : 23
Location : Estonia

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Garanas on Fri Nov 04, 2011 10:31 am

Java seems to be the future Wink, But it is quite hard if you're asking me.
I guess languages aren't my thing Razz

_________________
[quote="UF Beazt"] ... is a good idea! [quote="UF Spartan19423"]
YOU HAVE DONE OUTSTANDING WORK!
[/quote][/quote]
avatar
UF Garanas
UF Member
UF Member

Posts : 998
Join date : 2011-01-10
Age : 22
Location : Netherlands

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF WiredUp4Fun on Fri Nov 04, 2011 12:06 pm

UF Garanas wrote:Java seems to be the future Wink, But it is quite hard if you're asking me.
I guess languages aren't my thing Razz
Yeah, English is one if them Razz haha
avatar
UF WiredUp4Fun
UF Admin
UF Admin

Posts : 1265
Join date : 2009-08-18
Age : 28
Location : Australia

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Vishna on Sun Nov 06, 2011 2:01 pm

UF Garanas wrote:Java seems to be the future Wink, But it is quite hard if you're asking me.
I guess languages aren't my thing Razz

Yeah its hardest what I have learned, but if you have learned atleast C/C#/C++ then its easier to understand. But I agree, that you need teacher. Atleast for couple of first lesson, to get the logic behind java. Hardest thing is IMO debugging. It can give so complex errors what I can only solve with teachers help.

Maybe, maybe I can put up some tutorials in future, but not atm, need to learn more.
avatar
UF Vishna
UF Member
UF Member

Posts : 560
Join date : 2010-04-30
Age : 23
Location : Estonia

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Garanas on Mon Nov 07, 2011 12:37 am

UF WiredUp4Fun wrote:
UF Garanas wrote:Java seems to be the future Wink, But it is quite hard if you're asking me.
I guess languages aren't my thing Razz
Yeah, English is one if them Razz haha

When you're asking me.
That should do it. :p

Debugging isn't the hardest thing, the hardest thing is preventing bugs before you make them!
And a teacher would be lovely, but these things are (mostly, as far I can see) only given at universities / the other type of high school.

_________________
[quote="UF Beazt"] ... is a good idea! [quote="UF Spartan19423"]
YOU HAVE DONE OUTSTANDING WORK!
[/quote][/quote]
avatar
UF Garanas
UF Member
UF Member

Posts : 998
Join date : 2011-01-10
Age : 22
Location : Netherlands

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  UF Vishna on Mon Nov 07, 2011 7:52 am

If you want to be so specific, then yes. And other type high school? Well it just depends I guess. I'm learning in normal school, wich dont have only one specification. There are selection curses and well, our school has decided to make different kind of selection courses every year. So yeah maybe I'm lucky. Previous year robotics and this year programming. Very Happy
avatar
UF Vishna
UF Member
UF Member

Posts : 560
Join date : 2010-04-30
Age : 23
Location : Estonia

Back to top Go down

Re: C# - Lesson 5b - Visual C# overview + our first real programme

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum