• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Visual Basic 6 – Drawing Code Help

indyjones

OSNN.net Adventurer
#1
Hey all
Learning VB6 at the moment and was wondering if someone could help me please by telling me how to draw an ellipse by using a command button then changing its aspect ratio via a scrollbar.
Any help will be much much appreciated! :)

IJ
 

Kush

High On Life!
#2
i did this last year, i forgot, sorry man, its kinda confusing at first, but once u get the hang of it it will be easy, it has to do with coordinetes though (x,y) thats all i remember
 

XPos

OSNN Addict
#3
Hope this will help. Hope I didn't go too overboard.

Don't forget to set your min values to 1. You can set the max values to what ever you want. Just make sure the reset values reflect that number.
Code:
Option Explicit
'Declare variables
  Dim CX As Integer
  Dim CY As Integer
  Dim sngAspect As Single
  Dim intRadius As Integer
  
Private Sub Command1_Click()
'Calculate the aspect ratio
  sngAspect = HScroll1.Value / VScroll1.Value
  
'Clear the form
  Me.Cls
  
'Reset the scroll bar values
  HScroll1.Value = 200
  VScroll1.Value = 200
  
'Draw the circle/ellipse
  Me.Circle (CX, CY), intRadius, vbBlack, , , sngAspect
End Sub

Private Sub Form_Load()
'Reset the scroll bar values
  HScroll1.Value = 200
  VScroll1.Value = 200
End Sub

Private Sub Form_Resize()
'If the form is not minimized resize all object to fit on the form
  If Me.WindowState <> 1 Then
  'Move the command button
    Command1.Move Me.ScaleWidth - 15, Me.ScaleHeight - 15, 15, 15
    
  'Move the scroll bars
    HScroll1.Move 0, Me.ScaleHeight - 15, Me.ScaleWidth - 15, 15
    VScroll1.Move Me.ScaleWidth - 15, 0, 15, Me.ScaleHeight - 15
    
  'Recalculate the center of the circle
    CX = Me.ScaleWidth / 2 - VScroll1.Width
    CY = Me.ScaleHeight / 2 - HScroll1.Height
    
  'Calculate the radius of the circle
    If CX > CY Then
      intRadius = CX / 2
    Else
      intRadius = CY / 2
    End If
  End If
End Sub

Private Sub HScroll1_Change()
'Reset the vertical scroll bar
  VScroll1.Value = 200
  
'Recalculate the aspect ratio
  sngAspect = HScroll1.Value / VScroll1.Value
  
'Clear the form
  Me.Cls
  
'Redraw the circle/ellipse
  Me.Circle (CX, CY), intRadius, vbBlack, , , sngAspect
End Sub

Private Sub VScroll1_Change()
'Reset the horizontal scroll bar
  HScroll1.Value = 200
  
'Recalculate the aspect ratio
  sngAspect = HScroll1.Value / VScroll1.Value
  
'Clear the form
  Me.Cls
  
'Redraw the circle/ellipse
  Me.Circle (CX, CY), intRadius, vbBlack, , , sngAspect
End Sub
 

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,962
Messages
673,248
Members
89,017
Latest member
Seggar