Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,100 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,652 people online right now. Registration is fast and FREE... Join Now!




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

 
Reply to this topicStart new topic

[SOLVED]how to make Pencil tool of the Paint Program, how to make Pencil tool of the Paint Program (Help Plz)

ganni
20 Nov, 2007 - 06:52 PM
Post #1

New D.I.C Head
*

Joined: 21 Apr, 2007
Posts: 6


My Contributions
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
IPB Image
my code produce me this
IPB Image
my code
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 Nov, 2007 - 04:15 AM
User is offlineProfile CardPM
+Quote Post

Nayana
RE: [SOLVED]how To Make Pencil Tool Of The Paint Program
20 Nov, 2007 - 11:05 PM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
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):

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.
User is offlineProfile CardPM
+Quote Post

ganni
RE: [SOLVED]how To Make Pencil Tool Of The Paint Program
21 Nov, 2007 - 01:41 AM
Post #3

New D.I.C Head
*

Joined: 21 Apr, 2007
Posts: 6


My Contributions
Hey! Thank you Nayana!
That works! biggrin.gif biggrin.gif biggrin.gif biggrin.gif biggrin.gif biggrin.gif
icon_up.gif icon_up.gif icon_up.gif icon_up.gif icon_up.gif icon_up.gif icon_up.gif icon_up.gif



IPB Image

wub.gif wub.gif wub.gif wub.gif wub.gif wub.gif

This post has been edited by ganni: 21 Nov, 2007 - 01:42 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:49PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month