Thread: New to this forum and C# - Need some help

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    Kent, U.K
    Posts
    5

    Smile New to this forum and C# - Need some help

    Hi.

    I got reffered here by one of your members.

    I've done Delphi in the past so I know the basic prinicples of programming, but I am now trying to change over to C# as it holds a lot more potential.

    I'm using Microsoft Visual C# 2005 Express edition so I have all the software I need.

    What I was wondering is, could someone around here please share some existing C# project files with me. I do have a book on C# but find it quite hard to learn from, I find it easier to just suss things out and learn from experience.

    All I need is a basic, windows form application project, that I can disect and learn the syntax.

    For instance, in Delphi to open up another form I would have written 'form2.visible := true'.

    Obviously, that will not work in C#, but I want to learn the equivalent.

    So if someone could perhaps send me some project files that really would be great.

    Thanks.
    Daniel.

  2. #2
    ♥Sexy Coding Hunk♥ CartoonLarry's Avatar
    Join Date
    Dec 2003
    Location
    Michigan
    Posts
    50
    For instance, in Delphi to open up another form I would have written 'form2.visible := true'.

    Obviously, that will not work in C#, but I want to learn the equivalent.
    Code:
                Form2 form2 = new Form2();
                form2.Show();

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    Kent, U.K
    Posts
    5
    Quote Originally Posted by CartoonLarry
    Code:
                Form2 form2 = new Form2();
                form2.Show();
    Ok thanks, but what does the:

    Code:
    Form2 form2 = new Form2();
    bit mean?


    Obviously, form2.Show(); makes sense, split into Form2, and then show, it's logical.

    But,
    Code:
    Form2 form2 = new Form2();
    ?

    I just don't get the logic of it.


    Also, could you please explain how to create an if statement that basically does the following:

    Code:
    If
    
    textbox1.text = "asd"
    
    Then
    
    MessageBox.Show("Password Correct!");
    
    Form2 form2 = new Form2();
    form2.Show();
    
    Else
    
    MessageBox.Show("Password incorrect");

    Sorry for the basic questions, but this C# is a totally different world to Delphi.

    Thanks again.

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by dannysmith
    Ok thanks, but what does the:
    Code:
    Form2 form2 = new Form2();
    bit mean?
    You need an instance of your form before you can do anything with it. So, you create an instance of it with that line.
    Quote Originally Posted by dannysmith
    Also, could you please explain how to create an if statement that basically does the following:
    Code:
    If
    
    textbox1.text = "asd"
    
    Then
    
    MessageBox.Show("Password Correct!");
    
    Form2 form2 = new Form2();
    form2.Show();
    
    Else
    
    MessageBox.Show("Password incorrect");
    Code:
    if (textbox1.text == "asd")
    {
       MessageBox.Show("Password Correct!");
    
       Form2 form2 = new Form2();
       form2.Show();
    }
    else
    {
       MessageBox.Show("Password incorrect");
    }
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    1
    Quote Originally Posted by dannysmith
    Ok thanks, but what does the:

    Code:
    Form2 form2 = new Form2();
    bit mean?
    This is a basic part of an object-orientated language, and you need to understand the use of objects before you continue in C#. I'll break this line down for you quickly, and refer you to material that discusses this subject more in depth, but you should probably progress through a C# tutorial, or book if you have the resources to purchase one (or loan from a library).

    Form2 is the name of a class, in this case a class that is a sub-class of a Windows Form. form2, however, is an object. Form2 form2 is a declaration and could exist simply as:

    Code:
    Form2 form2;
    Which, perhaps you know from previous programming experience, is the standard way to declare a variable.

    The other part of the code, = new Form2();, is the constructor. This is basically taking the declared object, and using the Form2 blueprint to give it the attributes and methods contained within the Form2 class.

    Another way to illustrate this would be through the following two bits of code, both of which do the same as each other, just in different ways:

    Code:
    Class object = new Class();
    or

    Code:
    Class object;
    
    object = new Class();
    The following article will give more detail, and probably clearer understanding, of the use of objects in C#. But I strongly advise you to do as much reading into the preliminaries of C#, and if possible get your hands on a book, if you wish to understand more.

    http://www.devarticles.com/c/a/C-Sha...es-in-C-sharp/

  6. #6
    Registered User
    Join Date
    Oct 2006
    Location
    Kent, U.K
    Posts
    5

    Question

    Thanks. Just another quick one,

    OnKeyPress event.

    I want to be able to do the following: (pseudocode)


    Code:
    Form1 OnKeyPress;
    
        If Keypress = Return Key
    
        Then
    
          Begin
    
               If textBox1 = 'asd'
    
               Then
    
               Form2.Show;
    
               This.Hide();
    
               Else
    
               MessageBox.Show("Password incorrect");
    I know how to do an if statement and change the object properties, but it's just that-

    1. I have never added in my own event, only used the default events with the objects (onclick for button e.t.c.)

    and 2. Haven't a clue what Delphi's "ord(key)=13" equivalent in C# is.


    Thanks.

    (p.s. I do look this stuff up on the net before asking, I just have no luck in finding anything usefull)

  7. #7
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59
    perhaps a starting point ...

    Code:
            private void inputTextBox_KeyDown(object sender, KeyEventArgs e)
            {
                if(e.KeyCode == Keys.Enter)
                {
                         // code
                }
            
            }

Popular pages Recent additions subscribe to a feed