Solved

drawing random dots on mouseclick

Posted on 1998-12-24
12
398 Views
Last Modified: 2010-05-03
i would like the user to be able to draw random size of dots when the user click on a picture box (something like the spray function in Paint)... the random size of dots should be different sizes of circles...how to do that?
0
Comment
Question by:lph
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1452430
In Form_Load:
Randomize Timer
In _MouseDown put:
Picture1.Circle X, Y, CInt(Rnd*10)

0
 

Author Comment

by:lph
ID: 1452431
what i wanted is on mouse_down, it will draw a few circles or dots of different sizes at one time and the dots are near each other.

i want the dots to be solid type (the whole circle is black, for example) and not with the circle in the middle...
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1452432
Set the .FillColor to the color you want it to be filled with, and then In _MouseDown put:
Picture1.Circle X, Y, CInt(Rnd*10), Picture1.FillColor

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lph
ID: 1452433
i need a few dots to be drawn at one mouse_click (like the one in the spray function in Paint).. your command only draw one dot at one time...
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1452434
Picture1.Circle X-5+cint(rnd*10), Y-5+cint(rnd*10), CInt(Rnd*10), Picture1.FillColor

0
 

Author Comment

by:lph
ID: 1452435
This does not do something like the spray function in Paint...
0
 
LVL 4

Accepted Solution

by:
chabaud earned 100 total points
ID: 1452436
Create a form Form1 with one PictureBox and one Timer and try this code:

Option Explicit

Private x0 As Integer, y0 As Integer

Private Sub Form_Load()
    Randomize Timer
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Picture1_MouseMove Button, Shift, X, Y
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If Button = 1 Then
        x0 = X
        y0 = Y
        Picture1.FillStyle = vbFSSolid
        Timer1.Enabled = True
        Timer1.Interval = 10
    End If
   
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
    Picture1.Circle (x0 + CInt(Rnd * 200) - 100, y0 + CInt(Rnd * 200) - 100), CInt(Rnd * 100)
End Sub

0
 

Author Comment

by:lph
ID: 1452437
i want the dots to be drawn on mouse click and not on mouse down...
and the dots that are to be drawn should appear around the mouse cursor and not anywhere in the picture box...
0
 
LVL 4

Expert Comment

by:chabaud
ID: 1452438
You could customize the code as you want it...

My code draw filled circles with random radius (from 0 to 10)
at a random position into a rectangle centered on the mouse (the size of the rectangle is 200).

My picture as width and height = 1500

In Paintbrush, the spray draw continuously (every 10ms) between the mousedown and the mouseup. That is not what you want ?

0
 
LVL 4

Expert Comment

by:chabaud
ID: 1452439
The MouseClick event is fired after the MouseDown and MouseUp events. So if you start to draw on MouseClick, when do you STOP to draw circles ???

0
 

Author Comment

by:lph
ID: 1452440
sorry, what i mean is i want the dots to be drawn on mouse down and not on mouse move....
0
 
LVL 4

Expert Comment

by:chabaud
ID: 1452441
Can't you change the code as follow by yourself...?

Option Explicit

Private x0 As Integer, y0 As Integer

Private Const pi = 3.141592

Private Sub Form_Load()
    Randomize Timer
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        x0 = X
        y0 = Y
        Picture1.FillStyle = vbFSSolid
        Timer1.Enabled = True
        Timer1.Interval = 10
    End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
    'Draw random circle into a circle
    Dim a As Double
   
    a = Rnd * 2 * pi
    Picture1.Circle (x0 + CInt(200 * Rnd * Cos(a)), y0 + CInt(200 * Rnd * Sin(a))), CInt(Rnd * 50)
End Sub

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question