Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts

    Arrow Merry X-max + please help me w/ C#

    Hello all, merry christmas, and happy holidays

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

  • #2
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    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.
    Last edited by melloorr; 12-25-2011 at 06:38 PM.

  • #3
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by melloorr View Post
    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?
    Last edited by crank01; 12-26-2011 at 04:26 AM.

  • #4
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by crank01 View Post
    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
    Last edited by melloorr; 12-26-2011 at 10:46 AM.

  • #5
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by melloorr View Post
    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

  • #6
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    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.

  • #7
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts
    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.

  • #8
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by crank01 View Post
    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

  • #9
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by melloorr View Post
    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

  • #10
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by crank01 View Post
    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
    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).

  • #11
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by melloorr View Post
    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

  • #12
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    No problem, glad to help

  • #13
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,821
    Thanks
    42
    Thanked 199 Times in 198 Posts
    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?

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #14
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by alykins View Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •