Welcome to Dream.In.Code
Become a VB Expert!

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




adding width to a drawpen

 
Reply to this topicStart new topic

adding width to a drawpen

lab3tech
5 Dec, 2006 - 11:13 AM
Post #1

New D.I.C Head
*

Joined: 28 Oct, 2006
Posts: 46


My Contributions

This is a continuation of an earlier post where I asked about getting the x and y co-ordinates for the mouse position in a picturebox. I am doing this program as a class assignment. After getting the proper code to use to get the co-ordinates (Thanks, Hangman!) I have been able to do the programming to have the user select a drawing tool and a line width and then draw lines, rectangles and freehand in the picture box. I am having problems in getting the user selected width into the code. If I try to add the selected width (called mysize) I get a message that "no accessible drawline will accept that number of arguments". What do I need to do to get the new width added to the code?

Thanks!!
CODE

Private Sub Picbox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Picbox.MouseUp


        x2 = MousePosition.X - Me.Left - Picbox.Left
        y2 = MousePosition.Y - Me.Left - Picbox.Left

        If drawtool = "Line" Then
            mywidth = CmbWidth.SelectedIndex + 1
            drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.None
            drawgraphics.DrawLine(drawpen, x1, y1, x2, y2)
            Picbox.Image = drawbitmap

        ElseIf drawtool = "Rectangle" Then
            mywidth = CmbWidth.SelectedIndex + 1
            drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.None
            drawgraphics.DrawRectangle(drawpen, x1, y1, x2, y2)
            Picbox.Image = drawbitmap

        ElseIf drawtool = "Freehand" Then
            mywidth = CmbWidth.SelectedIndex + 1
            drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.None
            drawgraphics.DrawLine(drawpen, x1, y1, x2, y2)
            Picbox.Image = drawbitmap
        End If

        'Stop drawing.
        drawing = False


    End Sub

User is offlineProfile CardPM
+Quote Post

the_hangman
RE: Adding Width To A Drawpen
5 Dec, 2006 - 01:32 PM
Post #2

D.I.C Addict
Group Icon

Joined: 18 Jan, 2006
Posts: 593



Thanked: 1 times
Dream Kudos: 200
My Contributions
I havent tested this, but you can try it. Instead of mywidth = CmbWidth.SelectedIndex + 1 try drawpen.Width = CmbWidth.SelectedIndex + 1

Also, if you are going to perform an action that is exactly the same in every outcome, there is no real need to type it more than once. Save space and just do it once

CODE
Private Sub Picbox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Picbox.MouseUp

        x2 = MousePosition.X - Me.Left - Picbox.Left
        y2 = MousePosition.Y - Me.Left - Picbox.Left

            drawpen.Width = CmbWidth.SelectedIndex + 1
            drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.None

        If drawtool = "Line" Then
            drawgraphics.DrawLine(drawpen, x1, y1, x2, y2)
        ElseIf drawtool = "Rectangle" Then
            drawgraphics.DrawRectangle(drawpen, x1, y1, x2, y2)
        ElseIf drawtool = "Freehand" Then
            drawgraphics.DrawLine(drawpen, x1, y1, x2, y2)
        End If

        Picbox.Image = drawbitmap

        'Stop drawing.
        drawing = False

    End Sub

User is offlineProfile CardPM
+Quote Post

lab3tech
RE: Adding Width To A Drawpen
5 Dec, 2006 - 11:20 PM
Post #3

New D.I.C Head
*

Joined: 28 Oct, 2006
Posts: 46


My Contributions
QUOTE(the_hangman @ 5 Dec, 2006 - 02:32 PM) *

I havent tested this, but you can try it. Instead of mywidth = CmbWidth.SelectedIndex + 1 try drawpen.Width = CmbWidth.SelectedIndex + 1

Also, if you are going to perform an action that is exactly the same in every outcome, there is no real need to type it more than once. Save space and just do it once

CODE
Private Sub Picbox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Picbox.MouseUp

        x2 = MousePosition.X - Me.Left - Picbox.Left
        y2 = MousePosition.Y - Me.Left - Picbox.Left

            drawpen.Width = CmbWidth.SelectedIndex + 1
            drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.None

        If drawtool = "Line" Then
            drawgraphics.DrawLine(drawpen, x1, y1, x2, y2)
        ElseIf drawtool = "Rectangle" Then
            drawgraphics.DrawRectangle(drawpen, x1, y1, x2, y2)
        ElseIf drawtool = "Freehand" Then
            drawgraphics.DrawLine(drawpen, x1, y1, x2, y2)
        End If

        Picbox.Image = drawbitmap

        'Stop drawing.
        drawing = False

    End Sub





I got this to work by making a widepen = mycolor,mysize. I changed the way I did the colors from pens.black to color.black, for example. Then I changed drawpen in the code to widepen. I got this done last night and didn't see your post until this morning. May not be the best way to "get the job done" but it works. I will now make the change the way I entered the code toimplement your latest recommendation. Thanks so much!!


CODE
                      
                               widepen = mycolor,mysize            
        If drawtool = "Line" Then
            drawgraphics.DrawLine(widepen, x1, y1, x2, y2)
        ElseIf drawtool = "Rectangle" Then
            drawgraphics.DrawRectangle(widepen, x1, y1, x2, y2)
        ElseIf drawtool = "Freehand" Then
            drawgraphics.DrawLine(widepen, x1, y1, x2, y2)
        End If


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 07:36PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month