help MyPaint

Discussion in 'C#' started by emc22, Sep 4, 2010.

  1. emc22

    emc22 New Member

    Joined:
    Sep 4, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,I'm trying to make my own simple paint application but I'm having trouble with the
    "openfiledialog and paint" thing. The code below draws lines when the mouse is down and moving. The problem is whenever I press the button that opens the dialogbox everything I painted on the form disappears except the button. The white rectangle is supposed to be drawn once by the form and written by a mouse like a pen writing on paper. Do you guys have any idea how I can solve this problem??


    Code:
    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;
    
    namespace Doodle
    {
        public partial class Form1 : Form
        {
    
            public Graphics g;
            SolidBrush padBrusher = new SolidBrush(Color.White);
            SolidBrush brusher = new SolidBrush(Color.Red);
            Pen blackPen=new Pen(Color.Black,.1f);
            Rectangle pad=new Rectangle(10,10,200,200);
            public bool mdown=false;
            Point pOne, pTwo;
            bool allowPaint = true;
         
         
            
          
        
    
            public Form1()
            {
                InitializeComponent();
    
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
               
            }
    
            private void mouseDown(object sender, MouseEventArgs e)
            {
                mdown = true;
                pOne =this.PointToClient(new Point(MousePosition.X, MousePosition.Y));
                
            }
    
            private void mouseMove(object sender, MouseEventArgs e)
            {
    
                if (mdown == true)
                {
                    pTwo = pOne;
                    pOne = this.PointToClient(new Point(MousePosition.X, MousePosition.Y));
                    g.DrawLine(blackPen, pOne, pTwo);
    
     
                    
                }
            
            }
    
            private void painter(object sender, PaintEventArgs e)
            {
    
    
                if (allowPaint == true)
                {
                    g = this.CreateGraphics();
                    g.FillRectangle(padBrusher, pad);
                    g.DrawRectangle(blackPen, pad);
                    allowPaint = false;
                }          
            }
    
            private void mouseUp(object sender, MouseEventArgs e)
            {
                mdown = false;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                openFileDialog1.ShowDialog();
            }
    
    
        }
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice