Results 1 to 8 of 8

Thread: Need help with my first C# program please

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2010
    Posts
    762

    Need help with my first C# program please

    I installed the community edition of Microsoft Visual studio in November 2021, and tried to use it at that time, but I left it because I didn't have time then.

    Now, I am trying to use it, but I have trouble figuring out how to begin.
    For example, I go to File -> New -> Project
    This screen shows up:

    I didn't choose that first item from the list. It chose it for me.
    It is a Console project which is not what I need.

    What I am trying to do is to write my first program in C#
    I want to write a GUI type of program: A form with some controls on it, etc.

    In other words a "Hello world" program in the GUI style.
    I don't know how to navigate this screen, what to choose and where to go.

    Can you please help?

    Also, can you please give me the link to a very good online tutorial for this?
    I googled and there are a lot of tutorials, but which one is the best for somebody like me who comes from VB6 background and wants to write a GUI program similar to VB6?

    Please advise.
    Thanks a lot.
    Last edited by dday9; May 27th, 2022 at 08:48 AM.

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Need help with my first C# program please

    I asked the mods to move this to the C# forum.

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Need help with my first C# program please

    With regards to creating a traditional desktop application using C#, follow these steps:
    1. Under the All Languages dropdown, select C#
    2. Under the All Platforms dropdown, select Windows
    3. Under the All Project Types dropdown, select Desktop
    4. In the list below, click on Windows Form App (.NET Framework)
    5. Click on the Next button
    6. Fill out the configuration options
    7. Click on the Create button


    With regards to tutorials for coming from a VB6 background, my suggestion is to completely forget VB6 if you are going to code using C#. You will still have the drag and drop editor, but you will no longer have those funky control arrays. I would suggest playing around with the editor and if you run into a specific problem, bring it up here.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Need help with my first C# program please

    If you do a google search of archive.org looking for books related to C#, you will likely find freely available PDF versions of C# programming textbooks. If it were me, that's where I would start.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2010
    Posts
    762

    Re: Need help with my first C# program please

    Hi
    Thanks for your help.

    I google searched and found a good tutorial:
    https://docs.microsoft.com/en-us/vis...f?view=vs-2022

    As per the above tutorial, I am trying to develop a Hello world app.
    Actually I did develop that, and placed all the controls (a textbox, two radio buttons and a command button (or a Button as they call it)) on the designer.
    And also I placed the code that is instructed in there under the Button_Click event:
    Code:
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                if (HelloButton.Checked == True)
                {
                    MessageBox.Show("Hello!");
                }
                else if (GoodbyeButton.Checked ==true)
                {
                    MessageBox.Show("Good bye!");
                }
            }
    Then in the Solution explorer, I renamed MainWindow.xaml to Greetings.xaml (as instructed in the tutorial).

    As soon as I did that rename, the Design screen disappeared.
    Anywhere on the screen that I click, the design environment (the environment where I had placed the textbox, radio buttons and the command button) doesn't appear:
    https://i.imgur.com/SK725uP.jpeg

    Looks like the Designer has vanished into thin air.
    How can I see the Designer again please?

    Second problem:
    When I press F5, I expect to get this error:
    https://i.imgur.com/UQQ4Uuf.jpeg
    Instead, I get this:
    https://i.imgur.com/HIMhDag.jpeg

    I press "No", then these strange errors:
    https://i.imgur.com/FZlpQ0F.jpg


    Third problem:
    How come the main form has so few properties:
    https://i.imgur.com/yFnbs1A.jpg

    Fourth:
    The event list is strange:
    https://i.imgur.com/X8ln2XP.jpg


    Additional notes:
    1- I installed Visual Studio in November 2021. At that time the latest version was 2019. That is what I have installed.
    Could this be the cause of my problems?

    2- In the beginning of this Hello World project, I chose different stuff than instructed by this tutorial:
    https://i.imgur.com/CrfhNIw.jpg
    Could this be the cause of my problems?


    Please help.
    Thanks.
    Ilia

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Need help with my first C# program please

    Quote Originally Posted by IliaPreston View Post
    Then in the Solution explorer, I renamed MainWindow.xaml to Greetings.xaml (as instructed in the tutorial).

    As soon as I did that rename, the Design screen disappeared.
    Anywhere on the screen that I click, the design environment (the environment where I had placed the textbox, radio buttons and the command button) doesn't appear:
    https://i.imgur.com/SK725uP.jpeg
    I just tested and the same thing happened to me. I closed the designer window that was already open and then double-clicked the item in the Solution Explorer and it opened as expected. Probably best to not have an item open when renaming it. VS should handle it but the WPF designer has been reimplemented for .NET Core and it still has a few bugs.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Need help with my first C# program please

    Quote Originally Posted by IliaPreston View Post
    Second problem:
    When I press F5, I expect to get this error:
    https://i.imgur.com/UQQ4Uuf.jpeg
    Instead, I get this:
    https://i.imgur.com/HIMhDag.jpeg

    I press "No", then these strange errors:
    https://i.imgur.com/FZlpQ0F.jpg
    You can't run a project if it won't compile. You need to address the compilation errors. If you double-click an error in the Error List it should take you to the place in the code that is causing it.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Need help with my first C# program please

    Quote Originally Posted by IliaPreston View Post
    Additional notes:
    1- I installed Visual Studio in November 2021. At that time the latest version was 2019. That is what I have installed.
    Could this be the cause of my problems?
    Maybe. Most things will be the same but Windows Desktop app support has improved. You might want to install VS 2022. You can keep VS 2019 or uninstall it.
    Quote Originally Posted by IliaPreston View Post
    2- In the beginning of this Hello World project, I chose different stuff than instructed by this tutorial:
    https://i.imgur.com/CrfhNIw.jpg
    Could this be the cause of my problems?
    That won't make any difference.

Posting Permissions

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



Click Here to Expand Forum to Full Width