Jump to content

My Paint Program...


DSH
 Share

Recommended Posts

Hi,

im taking some C# courses , and we have to make in order to pass first course a Paintapplication like the one windows uses...

It will be a hard C# project for me.

We got as support only one code that generates a rectangle <black> on a small form... (one of the tolls of my Paint Application), using this code we must think a way of coding the rest of the tools

so...

So i have only 2 weeks to realise something like this, and i already started understanding that rectangle code i got . But i have some questions and problems that i want to solve first(and i will make screens and copy current source codes to see my point when i need help),

so please help me making this program... i know that Paint.Net gives its source code, but i want to make a basic Paint Program that will have:

___________________________

Tools that my Paint Program will have:

1)Pencil

2)Brush

3)Line

4)CurveLine

5)Rectangle

6)Ellipse

si probabil 7)Text

______________________________

i will add a color palette formed of many panels (painted with a color), and when i click one , the color will change...

_____________________________

and ... i would like a lot to have a small panel where i can PREVIEWthe painting ->somewhere to the left or right ,like Paint.Net has. It will be neat to have one :roll: ...

_____________________________

***My Curent Problem:[/b]***

i have a small problem with the Draw Rectangle code i mentioned earlier...

After i draw a rectangle and i wanna start making the second one, the first one DISSAPEARs!

i keep looking at the source code and i cant find a way so that the rectangles will be added to the form (not displaying only one)....

Print Screen here:

drdraw-f9of5zfa.jpg

Here is the Code:

using System;
using System.Drawing;
using System.Windows.Forms;

class BlockOut : Form
{
   bool bBlocking, bValidBox;
   Point ptBeg, ptEnd;
   Rectangle rectBox;

   public static void Main()
   {
       Application.Run(new BlockOut());
   }
   public BlockOut()
   {
       Text = "Dreptunghi Draw by DSH";
       BackColor = SystemColors.Window;
       ForeColor = SystemColors.WindowText;
   }
   protected override void OnMouseDown(MouseEventArgs mea)
   {
       if (mea.Button == MouseButtons.Left)
       {
           ptBeg = ptEnd = new Point(mea.X, mea.Y);
           Graphics grfx = CreateGraphics();
           grfx.DrawRectangle(new Pen(ForeColor), Rect(ptBeg, ptEnd));
           grfx.Dispose();
          bBlocking = true;
       }
   }
   protected override void OnMouseMove(MouseEventArgs mea)
   {
       if (bBlocking)
       {

           Graphics grfx = CreateGraphics();
           grfx.DrawRectangle(new Pen(BackColor), Rect(ptBeg, ptEnd));
           ptEnd = new Point(mea.X, mea.Y);
           grfx.DrawRectangle(new Pen(ForeColor), Rect(ptBeg, ptEnd));
           grfx.Dispose();
           Invalidate();
       }
   }
   protected override void OnMouseUp(MouseEventArgs mea)
   {
       if (bBlocking && mea.Button == MouseButtons.Left)
       {
           Graphics grfx = CreateGraphics();
           rectBox = Rect(ptBeg, new Point(mea.X, mea.Y));
           grfx.DrawRectangle(new Pen(ForeColor), rectBox);
           grfx.Dispose();

           bBlocking = false;
           bValidBox = true;
           Invalidate();
       }
   }
   protected override void OnPaint(PaintEventArgs pea)
   {
       Graphics grfx = pea.Graphics;
       if (bValidBox)
           grfx.FillRectangle(new SolidBrush(ForeColor), rectBox);
       if (bBlocking)
          grfx.DrawRectangle(new Pen(ForeColor), Rect(ptBeg, ptEnd));
   }
   Rectangle Rect(Point ptBeg, Point ptEnd)
   {
       return new Rectangle(Math.Min(ptBeg.X, ptEnd.X), Math.Min(ptBeg.Y, ptEnd.Y), Math.Abs(ptEnd.X - ptBeg.X), Math.Abs(ptEnd.Y - ptBeg.Y));
   }
}

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...