?
Solved

How to make call Class Function (Code supplied)

Posted on 2002-04-26
6
Medium Priority
?
205 Views
Last Modified: 2013-11-23
Could someone please show me the syntax to make the functions work in the code below. The code draws a circle on a picture box but I don't know how to execute it. Help!
Gmoney


Private Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim gobj as Object
Dim cdrawingobjects as Collection

    With Picture1
           .DrawMode = vbInvert
           .FillStyle = vbFSTransparent
           .DrawWidth = 1
    End With
           
    siFirstX = X
    siFirstY = Y
    siLastX = X
    siLastY = Y

    Set gobj = New cls_draw_Circle
    With gobj
         .X0 = (siFirstX + siLastX) / 2
         .X0 = (siFirstX + siLastX) / 2
         .Radius = 80
    End With
   
    cDrawingObjects.Add gobj
    Set gobj.Picture1 = Form1.Picture1
    gobj.Draw
End Sub

The following is the code for DrawCircle Class :
Option Explicit

' The PictureBox we draw on.
Public picCanvas As PictureBox

' The rectangle's drawing attributes.
Public X0 As Single
Public Y0 As Single
Public Radius As Single
Public DrawWidth As Integer
Public ForeColor As OLE_COLOR
Public FillColor As OLE_COLOR
Public FillStyle As FillStyleConstants
Public DrawStyle As DrawStyleConstants

' Default property values.
Private Const m_def_X0 = 0
Private Const m_def_Y0 = 0
Private Const m_def_Radius = 80
Private Const m_def_DrawWidth = 1
Private Const m_def_ForeColor = vbBlack
Private Const m_def_FillColor = vbBlack
Private Const m_def_FillStyle = vbBlack
Private Const m_def_DrawStyle = vbSolid

' Draw on picCanvas.
Public Sub Draw()

   Form1.Picture1.ForeColor = ForeColor
   ' Set other drawing attributes.
   With fmyform(iCurrentProcId).picCanvas
       .FillStyle = FillStyle
       .FillColor = FillColor
       .DrawWidth = DrawWidth
       .DrawStyle = DrawStyle
   End With

   ' Draw the object.
   Form1.Picture1.Circle (X0, Y0), Radius, Form1.Picture1.ForeColor
End Sub

' Set default property values.
Private Sub SetDefaultProperties()
   X0 = m_def_Y0
   Y0 = m_def_X0
   Radius = m_def_Radius
   DrawWidth = m_def_DrawWidth
   ForeColor = m_def_ForeColor
   FillColor = m_def_FillColor
   FillStyle = m_def_FillStyle
   DrawStyle = m_def_DrawStyle
End Sub

' Set some defaults.
Private Sub Class_Initialize()
   SetDefaultProperties
End Sub
0
Comment
Question by:Gmoney
[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
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6971906
Picture targer has AutoRedraw property to true?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6971909
i meant:
picture target
0
 
LVL 4

Expert Comment

by:gencross
ID: 6971931
Create a project add everything up until the line:

The following is the code for DrawCircle Class :

To a form containing two pic boxes, picCanvas and Picture1

Everything below this line add to a Class module.  You will need to rename the Class or the name of the class in the code.  Also, it does not appear to me that this code is going to run as is.  I was getting errors trying to run it.  You are probably going to have to modify the code, but this is the way to get it to run.

Hope this helps
0
Technology Partners: 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!

 
LVL 4

Expert Comment

by:gencross
ID: 6971951
After more looking...

It appears that you only need one pic box on the form, but you need to do some renaming in the code.  I still cannot get it to run properly...
0
 
LVL 4

Accepted Solution

by:
gencross earned 200 total points
ID: 6971968
Try this code, it is based on the code you have, but I did it a little simpler.  It is not as versatile, but it runs.

Create a picture box names Picture1 and paste this code in the form.

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   
    Dim iXO As Integer
    Dim iYO As Integer
   
    Dim iFirstX As Integer
    Dim iFirstY As Integer
    Dim iLastX As Integer
    Dim iLastY As Integer
   
    iFirstX = X
    iFirstY = Y
    iLastX = X
    iLastY = Y
   
    iX0 = (iFirstX + iLastX) / 2
    iY0 = (iFirstY + iLastY) / 2
    Radius = 80
   
    Picture1.Circle (iX0, iY0), Radius, Form1.Picture1.ForeColor 'vbRed

End Sub
0
 

Author Comment

by:Gmoney
ID: 6972638
gencross can you make your code work by using a Class?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month11 days, 23 hours left to enroll

752 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