Drawing in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gwbob
    New Member
    • Oct 2008
    • 14

    Drawing in VB

    so im making a project in VB like MS paint. and i want to be able to switch between say push the mouse down to make a dot and draging the mouse to draw a line. and i can get the program to do both i understand that but i am not sure on how to get the program to switch between the two by the push of a button, so if someone could lend me a hand that would be great
    thanks a lot
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    you need to handle mouseup, mouse down and mouse move events.

    Comment

    • vdraceil
      New Member
      • Jul 2007
      • 236

      #3
      In the mouse down event write code to set the pixel clicked to black color(or any other pen color) by using pset() method..

      Comment

      • gwbob
        New Member
        • Oct 2008
        • 14

        #4
        ok i might not have been to clear thats my fault. or maybe i just dont understand... i dont know but i know how to get the program to draw dots and stuff with the mouse but i want to switch between clicking the mouse to put dots, to moving the mouse to draw a line, with the push of a button on the form and the push button event sub is different from the mouse down sub or move mouse sub and i dont think you can put both in the same sub. thats my problem.
        thanks a lot

        Comment

        • vdraceil
          New Member
          • Jul 2007
          • 236

          #5
          So you have 2 buttons.The first one when pressed must enable the user to draw freely(dots and irregular shapes) and when the other button is pressed the user must be able to draw only lines.
          Is this what you want to do?

          Comment

          • gwbob
            New Member
            • Oct 2008
            • 14

            #6
            ya pretty much one button will let me click to make dots and the other one will let me draw lines.
            thanks a lot

            Comment

            • vdraceil
              New Member
              • Jul 2007
              • 236

              #7
              when the first button's click event write flag=1 and in second button's click event write flag=2...flag enables you to know which button was pressed last.
              then,

              Code:
              Private Sub Form_MouseDown(...)
              If flag=1 Then
               'here write code for dots
              Else
               'here code for lines
               'on this mousedown event save the coordinates(x,y) clicked to x1,y1
               'on the next mousedown event you'll get another pair of coordinates x2,y2
               'draw line using line(x1,y1,x2,y2) method
               'then transfer x2,y2 to x1,y1,so that x2,y2 becomes free for next input
              End If
              End Sub
              Is that of any help?

              Comment

              • gwbob
                New Member
                • Oct 2008
                • 14

                #8
                ok i understand that but i think my code is set up in a way where thats not working here is my code:
                -------------------------------------------------
                Dim drawing

                Private Sub Command1_Click( )
                Picture1.Cls
                End Sub

                Private Sub cmdclear_Click( )
                Picture1.Cls
                End Sub

                Private Sub cmddots_Click()
                flag = 1
                End Sub

                Private Sub cmdline_Click()
                flag = 2
                End Sub

                Private Sub Form_Load()
                drawing = False
                End Sub

                Private Sub mnufileexit_Cli ck()
                End
                End Sub

                Private Sub mnufilenew_Clic k()
                Picture1.Cls
                End Sub

                Private Sub Picture1_MouseD own(Button As Integer, Shift As Integer, X As Single, Y As Single)
                If flag = 1 Then
                drawing = True
                PSet (X, Y), vbBlack
                End If
                End Sub

                Private Sub Picture1_MouseM ove(Button As Integer, Shift As Integer, X As Single, Y As Single)
                drawing = True
                End Sub

                Private Sub Picture1_MouseU p(Button As Integer, Shift As Integer, X As Single, Y As Single)
                drawing = False
                End Sub
                ------------------------------------------------------------------------
                i think im doing something wrong maybe not, but if there is theres my code and you should b able to find it or show me where in the code i have a problem
                thanks a lot again

                Comment

                Working...