...

View Full Version : Merry X-max + please help me w/ C#



crank01
12-25-2011, 03:25 PM
Hello all, merry christmas, and happy holidays :thumbsup:

I am in need of some help with this C# code that I am learning from a beginners book on C#. The code is for a Windows Form.
using System;
using System.Windows.Forms;

namespace HelloWin
{
public class MyForm : Form
{
private TextBox txtEnter;
private Label lblDisplay;
private Button btnOk;

private MyForm()
{
this.txtEnter = new TextBox();
this.lblDisplay = new Label();
this.btnOK = new Button();
this.Text = "My HelloWin App!";

// txtEnter
this.txtEnter.Location = new System.Drawing.Point(16, 32);
this.txtEnter.Size = new System.Drawing.Size(264, 20);

// lblDisplay
this.lblDisplay.Location = new System.Drawing.Point(16, 72);
this.lvlDisplay.Size = new System.Drawing.Size(264, 128);

// btnOk
this.btnOk.Location = new System.Drawing.Point(88, 224);
this.btnOk.Text = "OK";
this.btnOk.Click +=
new System.EventHandler(this.btnOK_Click);
// MyForm
this.Controls.AddRange(new Control[] {
this.txtEnter, this.lblDisplay, this.btnOk});
}

static Void Main()
{
Application.Run(new MyForm());
}
private void btnOK_Click(object sender, System.EventArgs e)
{
lblDisplay.Text = txtEnter.Text + "\n" + lblDisplay.Text;
}
}
}
Now I copied this windows form code into an empty C# code file but it comes up with sooo many compiling errors! But it looks exactly like how the tutorial's code looks. Please help :( I'm trying to learn C# but I can't even get past the 2nd lesson to get thru the rest of the teachings. Thanks CodingForums

melloorr
12-25-2011, 06:32 PM
Can you post a link to the book you are learning from? Most of the time, tutorials that are a couple of years old, are way out of date and will not work at all.

crank01
12-26-2011, 04:10 AM
Can you post a link to the book you are learning from? Most of the time, tutorials that are a couple of years old, are way out of date and will not work at all.
Its from Sam's Teach Yourself C# language, and sorry about the late response. I had xmas stuff to do lol. And does anyone see anything wrong with the above code? Is it alright if I put the above in a blank C# code file in Microsoft Visual C# even though the code is meant to create a windows form?

melloorr
12-26-2011, 10:17 AM
Its from Sam's Teach Yourself C# language, and sorry about the late response. I had xmas stuff to do lol. And does anyone see anything wrong with the above code? Is it alright if I put the above in a blank C# code file in Microsoft Visual C# even though the code is meant to create a windows form?

I don' think it would work if you put it in a blank file. Could you post a link to the book please? Like a link to Amazon or something, just to see when the book was published

crank01
12-26-2011, 02:14 PM
I don' think it would work if you put it in a blank file. Could you post a link to the book please? Like a link to Amazon or something, just to see when the book was published
I can't find the link to the one I downloaded since I downloaded the 2nd edition a while ago, and now theres a 6th edition! The copy I have is the 2nd edition which says copyrighted 2002. I guess that means its out dated. I just don't get tho, that even with out dated tutorials, shouldn't the code still work since they don't like update C#? Maybe I'm wrong lol. I've been looking at another book on C# which was made in 2010 and called Step by Step C# which I heard good things about. The thing is with Sam's book, it seems as though on the 1st exercise it'll teach you the "hello world" application, then for the next exercise it'll basically teach you how to program the game "snake" lol, atleast thats what it seems to me, and I want to learn slowly and not fast where I won't understand everything. I think I should make the change to another book :)

melloorr
12-26-2011, 02:23 PM
Wow that is seriously outdated. If you wouldn't mind using an ebook, there is a good one here: http://csharpcourse.com/ . (Rob Miles CSharp Yellow Book 2011.pdf) I have used it and found it great, and it is free of course.

crank01
12-26-2011, 02:26 PM
Thanks, I even thanked you for the post =) I don't get why out dated books wouldn't work anymore tho. Does the C# language change over time? Or is the book just flawed when it comes to teaching.

melloorr
12-26-2011, 02:29 PM
Thanks, I even thanked you for the post =) I don't get why out dated books wouldn't work anymore tho. Does the C# language change over time? Or is the book just flawed when it comes to teaching.

All programming languages are updated over time. They all have bugs that need to be fixed, and they all get new functions to improve productivity, while getting rid of functions that are obsolete due to new functions. There have been a few versions of C# since it was released

crank01
12-26-2011, 02:34 PM
All programming languages are updated over time. They all have bugs that need to be fixed, and they all get new functions to improve productivity, while getting rid of functions that are obsolete due to new functions. There have been a few versions of C# since it was released
Oh cool, learn a new thing every day. I wanted to devote today for learning a big chunk of C# and I'll keep in touch with you if I have any more questions via PM if thats alright. Thanks for the ebook and you helped me a great deal :thumbsup:

melloorr
12-26-2011, 02:39 PM
Oh cool, learn a new thing every day. I wanted to devote today for learning a big chunk of C# and I'll keep in touch with you if I have any more questions via PM if thats alright. Thanks for the ebook and you helped me a great deal :thumbsup:

Yeah you could PM me. But It would be best of you posted on the forum, because if someone else has the same problem, they could get help too (and I am not exactly the best person to ask about C#, there are people here with quite a lot more experience than me).

crank01
12-26-2011, 02:42 PM
Yeah you could PM me. But It would be best of you posted on the forum, because if someone else has the same problem, they could get help too (and I am not exactly the best person to ask about C#, there are people here with quite a lot more experience than me).
alright sounds good =) thx for everything

melloorr
12-26-2011, 02:48 PM
No problem, glad to help :)

alykins
12-26-2011, 05:09 PM
i see no reason why it wouldn't work compiling... even on .net 4 the framework uses systems.windows.forms and using system... .net 4 still uses and has textbox buttons and labels etc... what are the compilation errors? and what compiler are you using?

crank01
12-28-2011, 11:29 PM
i see no reason why it wouldn't work compiling... even on .net 4 the framework uses systems.windows.forms and using system... .net 4 still uses and has textbox buttons and labels etc... what are the compilation errors? and what compiler are you using?
Sorry for the late response, I am using Microsoft Visual C# Express, and it just wouldn't compile. I googled the code and I got a response from someone else who said you needed to "add" some missing code to it, in order for it to compile. Now I was completely new to the scene and "adding" code, or even just the lack of support that ebook gave me, made me put it down and start another book. Thanks for your help but I've progressed to another book which has been helping me out so far. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum