Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   Problem with a drawing program in visual basic 2008 (c sharp)(gui) (https://www.askmehelpdesk.com/showthread.php?t=478555)

  • Jun 11, 2010, 03:01 AM
    Teutn
    Problem with a drawing program in visual basic 2008 (c sharp)(gui)
    Hello all,

    I am learning myself c sharp and for that I have been working on a drawing program where the user is capable of drawing lines in 3 different strokes and 4 different colors,

    My first problem is how to let the user make a line by 2 mouseclicks on the panel.

    This is the code I have so far:
    Namespace WindowsFormsApplication1
    Code:

    namespace WindowsFormsApplication1{
    public partial class Form1 : Form
        {
            Graphics e;
            Pen p;
            Point punt1, punt2;
            int nPunt = 0;

           
            public Form1()
            {
                InitializeComponent();
               
                p = new Pen(Color.Black);
            }

            public void tekenpaneel_MouseClick(object sender, MouseEventArgs e)
            {
                if (nPunt == 0)
                {
                    punt1 = new Point(e.X, e.Y);
                    nPunt++;
                }
                else if (nPunt == 1)
                {
                    punt2 = new Point(e.X, e.Y);
                    nPunt = 0;
                }
            }

    public void tekenpaneel_Paint(object sender, PaintEventArgs e)
            {
                e.Graphics.DrawLine( p, punt1, punt2);
            }

        }
    }




    I don't got any errors but the program isn't doing anything when I click on the panel, I would be verry gratefull if someone could help me out :)
  • Jun 11, 2010, 08:10 AM
    Teutn
    OK now a quick update of how my code is now so its easier to help me :)
    Already a big thanks, getting to really understand csharp now :D

    Code:

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public int A, B, X, Y;
            public Color m_Color;
            public Point punt1;
            public Point punt2;
            public int nPunt;

            public Form1()
            {
                InitializeComponent();
            }
            public void tekenpaneel_MouseClick(object sender, MouseEventArgs e)
            {
                if (nPunt == 0)
                {
                    punt1 = new Point(e.X, e.Y);
                    nPunt++;
                }
                else if (nPunt == 1)
                {
                    punt2 = new Point(e.X, e.Y);
                    nPunt = 0;
                }
            }

            private void zwartBtn2_CheckedChanged(object sender, EventArgs e)
            {
                m_Color = Color.Black;
            }

            private void roodBtn2_CheckedChanged(object sender, EventArgs e)
            {
                m_Color = Color.Red;
            }

            private void geelBtn2_CheckedChanged(object sender, EventArgs e)
            {
                m_Color = Color.Yellow;
            }

            private void blauwBtn2_CheckedChanged(object sender, EventArgs e)
            {
                m_Color = Color.Blue;
            }
           
            public void tekenpaneel_Paint(object sender, PaintEventArgs e)
            {
                e.Graphics.DrawLine(new Pen(m_Color, 2), punt1, punt2);
            }
         
        }
    }

    I get no errors but no lines either... any help would be welcome :) THANKS!

  • All times are GMT -7. The time now is 07:20 AM.