[SOLVED]how to make Pencil tool of the Paint Program

how to make Pencil tool of the Paint Program (Help Plz)

Page 1 of 1

2 Replies - 16100 Views - Last Post: 21 November 2007 - 02:41 AM Rate Topic: -----

#1 ganni  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 21-April 07

[SOLVED]how to make Pencil tool of the Paint Program

Posted 20 November 2007 - 07:52 PM

I want to make simple paint. but i cant make pencil tool. please help me!

what should I do?
I want it to be like this
Posted Image
my code produce me this
Posted Image
my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace simplePencil
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		bool dragable = false;
		int firstX;
		int firstY;

		private void Form1_MouseDown(object sender, MouseEventArgs e)
		{
			dragable = true;
			firstX = e.X;
			firstY = e.Y;
		}

		private void Form1_MouseMove(object sender, MouseEventArgs e)
		{
			Graphics g = this.CreateGraphics();
			Pen myPen = new Pen(Color.Black, 1);
		   // GraphicsPath myPath=new GraphicsPath(

			if (dragable == true)
			{
				//g.Clear(Color.White);
				g.DrawLine(myPen, e.X-1, e.Y-1, e.X, e.Y);
				//g.DrawPath(myPen, GraphicsPath
				//g.DrawRectangle(myPen, e.X, e.Y, 1, 1);
			}
			
		}

		private void Form1_MouseUp(object sender, MouseEventArgs e)
		{
			dragable = false;
		}
	}
}


Help Plz!

This post has been edited by ganni: 21 November 2007 - 05:15 AM


Is This A Good Question/Topic? 0
  • +

#5 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: [SOLVED]how to make Pencil tool of the Paint Program

Posted 21 November 2007 - 12:05 AM

OK, what you should know:
* The faster the mouse moves, the more it jumps around the screen (so the dots are further apart.

What you need to do is remember the last point the mouse was at, so that you can draw a line from there to the current position, similar to below (psuedo code):

DrawLine(OldX, OldY, NewX, NewY);
OldX = NewX;
OldY = NewY;



The OldX and OldY should be declared static (in order to be remembered).

Your code should also know if OldX and OldY do not exist (i.e. drawing has just started), and only draw a dot at the NewX and NewY (or X,Y if they are called that)

I hope you understand this.
Was This Post Helpful? 2

#6 ganni  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 21-April 07

Re: [SOLVED]how to make Pencil tool of the Paint Program

Posted 21 November 2007 - 02:41 AM

Hey! Thank you Nayana!
That works! :D :D :D :D :D :D
:^: :^: :^: :^: :^: :^: :^: :^:



Posted Image

:wub: :wub: :wub: :wub: :wub: :wub:

This post has been edited by ganni: 21 November 2007 - 02:42 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1