School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,418 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,561 people online right now. Registration is fast and FREE... Join Now!




Creating a SketchPad

 
Reply to this topicStart new topic

> Creating a SketchPad, We're goin' to create a basic sketchpad using a picture box it

Rating  5
Nikhil_07n
Group Icon



post 26 Jan, 2009 - 04:46 AM
Post #1


Intro : This program basically creates a Sketchpad on which lines can be created on clicking and holding mouse button.

Concept : When the mouse_down event of picture box picCanvas is triggered, a dot is created.

When mouse_move event is triggered, a line is created to the current coordinates of the mouse.

Coding:

CODE


Private Sub Form_Load()
    picCanvas.AutoRedraw = True
    picCanvas.DrawWidth = 2
    picCanvas.ForeColor = vbBlue
    picCanvas.BackColor = vbWhite
End Sub



Explaination : Not needed, just the basic properties.(Blue line will be created on a white-backgrounded picture box)

CODE


Private Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        picCanvas.Line (X, Y)-(X, Y)
    End If
End Sub



Explaination : On holding mouse down, a dot is created, i.e., a line with initial and final coordinates SAME.


CODE


Private Sub picCanvas_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        picCanvas.Line -(X, Y)
    End If
End Sub



Explaination : The line is extended till the CURRENT coordinates of the mouse.

I think its clear now, for a working sample, download the ATTACHMENT.


Attached File(s)
Attached File  Sketchpad_Sample.zip ( 2.22k ) Number of downloads: 252
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/7/09 11:36PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month