CFanatic

Go Back   CFanatic > Programming > C# Programming

Join CFanatic Forum Now

help MyPaint topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-04-2010, 05:50 AM
Junior Member
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
emc22 is on a distinguished road
| More
help MyPaint

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();
        }


    }
}

Last edited by shabbir; 09-04-2010 at 08:10 AM. Reason: Code Blocks
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 04:12 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board