locked
What to Put Where? RRS feed

  • Question

  • Hi, it is the first Time I use a Forum,

    Here is my problem.


    WHERE TO PUT WHAT ?

    I am trying to write a WINDOWS-program in C#, using
    Microsoft Visual C# 2008 Express Edition.

    Although writing some small applications with various
    languages many years as amateur, I am certainly not
    an experienced programmer.

    Right now I cannot find out where to put the pieces of code.
    I bought the book "Beginning Visual C# 2008"
    by Karli Watson and partners and spent already a few days
    on internet with no success.

    My idea for the program is as follows:

    There is only one screen on which many things are moving
    using simple drawing tools of the GDI+.

    I put a menu bar with only two buttons: "Start" to
    invoke the proces the program involves and "Help"
    to show some text using a RichTextBox.

    On the screen there are also many controls to change
    varibles in order to change the flow of the process
    and how things on the screen behave.

    To avoid flickering I use double-buffering.

    I did not yet create classes, objects and so on, because
    I think I do not need them.

     

    So I have:

    1. A lot of global variables with among them the
       bool started = false.

    2. Maybe one or two simple functions returning values.

    3. Many event handlers of which the basics are
       automatically coded by VC.
       The one for the Start Button in the menu bar sets
       the bool started = true and disables that button.

    4. To avoid flickering I use double-buffering with
       following method:

     protected override void OnPaint(PaintEventArgs e)
     {
        Graphics displayGraphics = e.Graphics;
        Image i = new Bitmap(ClientRectangle.Width,
                                      ClientRectangle.Height);
        Graphics g = Graphics.FromImage(i);

      // here all the drawing activities

               displayGraphics,DrawImage(i,ClientRectangle);

               i.Dispose();
     }

    5. A main loop containing two other loops.
       Something as follows:

     
     while (true)
     {
               while(started == false)
        {
           // Here an Welcome Screen etc
           // and inviting to press the
                  // Start button in the menu bar
        }
     
        while (started == true)
        {
           // Here all the mathematics for
                  // the planned proces and providing
                  // varibles with screen coördinates for 
           // drawing activities.

                  // while this routine is running user
                  // may change varibles with the
                  // various controls

                  Refresh();// do all drawing at once

                  if ( targed is reached) //end of te session
           { 
         StartToolStripMenuItem.Enabled = true;
                       started = false;// back to Welcome Screen
           }

                }

     } // this loop can ( I think ) be ended with the
              // standard Windows form control which closes
              // the program

     


    After creating a new Windows application and putting some
    controls on Form1 VC provides following coding:

    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;
    using System.Drawing.Drawing2D; // this one I added

    namespace myProgram
    {
        // place a

        public partial class Form1 : Form
        {
            // place b
           
            public Form1()
            {
                // place c

                InitializeComponent();

                // place d
            }

            // place e

            private void startToolStripMenuItem_Click
                                    (object sender, EventArgs e)
            {
                started = true;                       
                startToolStripMenuItem.Enabled = false;
                // as described above
            }

            private void helpToolStripMenuItem_Click
                                    (object sender, EventArgs e)
            {
                // code to show help text
            }

            private void button1_Click(object sender, EventArgs e)
            {
                // code to change variables
            }

            private void button2_Click(object sender, EventArgs e)
            {
                // code to change variables
            }
     
     // and more such event handlers


            // place f

        }

        // place g

    }

    Now I have two questions:

     1. In which places and how should I put the numbered
        pieces of code I am going to write?

     2. What code do I have to write in the event handlers
        to direct the flow of the program back to the place
        where it was when the event occurs?
        I tried "return" with no success. 

     

    Tuesday, March 31, 2009 11:46 PM

Answers

  • You should begin with something a little bit more modest. "Global Variables" in an object oriented programming model are not usually considered good practice as such. In C#, we refer to "functions" as Methods. "Subroutines" are methods.

    Before jumping the gun to graphics, you should get primed on the tenets of Object Oriented programming. Don't be discouraged, for we were all there once too. If this is an example from a "beginner's" C# book, I would reconsider getting a new book, for things such as GDI+ are usually a bit of a handful for beginners.

    Let me make some recommendations:

    1.) Get a membership at www.learnvisualstudio.net
    2.) Illustrated C# by Daniel Solis.
    3.) The Object Oriented Thought Process by Matt Weisfeld

    There are tons of free stuff on the Internet

    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    • Marked as answer by liurong luo Tuesday, April 7, 2009 3:35 AM
    Wednesday, April 1, 2009 1:48 AM

All replies

  • You should begin with something a little bit more modest. "Global Variables" in an object oriented programming model are not usually considered good practice as such. In C#, we refer to "functions" as Methods. "Subroutines" are methods.

    Before jumping the gun to graphics, you should get primed on the tenets of Object Oriented programming. Don't be discouraged, for we were all there once too. If this is an example from a "beginner's" C# book, I would reconsider getting a new book, for things such as GDI+ are usually a bit of a handful for beginners.

    Let me make some recommendations:

    1.) Get a membership at www.learnvisualstudio.net
    2.) Illustrated C# by Daniel Solis.
    3.) The Object Oriented Thought Process by Matt Weisfeld

    There are tons of free stuff on the Internet

    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    • Marked as answer by liurong luo Tuesday, April 7, 2009 3:35 AM
    Wednesday, April 1, 2009 1:48 AM
  • Thank you for answering so soon.

    I see it is not wise to try things in C# without OOP.
    So, as you recommended I am going to orientate myself in that a bit more.

    Willem.J

    Wednesday, April 1, 2009 8:21 AM