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