4 Replies - 313 Views - Last Post: 13 May 2014 - 01:55 PM Rate Topic: -----

#1 xD@t0m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 61
  • Joined: 13-May 14

Problems making a Paint program

Posted 13 May 2014 - 01:44 PM

Hi everyone, first time posting here. I hope I don't break any rules.

I've been working on some code for a few weeks. My goal is to achieve a Paint program with lots of functions. Currently it has many code so I won't post it all here, instead download the attachment as it has multiple forms and a module.

I'm trying to make a tool which allows you to draw ellipses and rectangles on a PictureBox. The ellipse drawing is fine but when drawing a rectangle nothing happens (Form1.vb, line 125). I'm stuck and trying to fix this all day, tried everything. No error is displayed. Can anyone help?

Thanks in advance!

P.S. If you find any other mistakes in my code, feel free to fix.

Is This A Good Question/Topic? 0
  • +

Replies To: Problems making a Paint program

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: Problems making a Paint program

Posted 13 May 2014 - 01:46 PM

Quote

The ellipse drawing is fine but when drawing a rectangle nothing happens (Form1.vb, line 125). I'm stuck and trying to fix this all day, tried everything. No error is displayed. Can anyone help?


Would you post the relevant sections of code, at least?
Was This Post Helpful? 0
  • +
  • -

#3 xD@t0m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 61
  • Joined: 13-May 14

Re: Problems making a Paint program

Posted 13 May 2014 - 01:51 PM

My bad, I think the code didn't get attached. If not get it here.

Off-topic, where's the edit function here? Still new :(

Public Class MainWindow
' (...)
    Dim brushmode As String = "brush"
    Dim toolstate As String
    Dim startpoint, endpoint As Point
' (...)
    Private Sub Image_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Image.MouseDown
        draw = True
        On Error GoTo pixeldrawhandler
        StatusLabel.Text = "Drawing..."
        Dim pensize As Single
        pensize = BrushSize.Text
        If draw = True Then
            If brushmode = "brush" Then
                If shape = "o" Then
                    Image.CreateGraphics.FillEllipse(brush, e.X - (pensize / 2), e.Y - (pensize / 2), pensize, pensize)
                End If
                If shape = "[]" Then
                    Image.CreateGraphics.FillRectangle(brush, e.X - (pensize / 2), e.Y - (pensize / 2), pensize, pensize)
                End If
                If shape = "" Then
                    Image.CreateGraphics.DrawString(drawstring, stringfont, brush, e.X, e.Y)
                End If
            End If
        End If
        If brushmode = "tool" Then
            If toolstate = "waitForStart" Then
                startpoint = New Point(e.X, e.Y)
                Label4.Text = "Click ending point on drawing"
                toolstate = "waitForEnd"
                StatusLabel.Text = "Ready"
                Exit Sub
            End If
            If toolstate = "waitForEnd" Then
                endpoint = New Point(e.X, e.Y)
                Label4.Text = "Text:"
                Label4.Visible = False
                If shape = "o" Then
                    Image.CreateGraphics.FillEllipse(brush, startpoint.X, startpoint.Y, endpoint.X - startpoint.X, endpoint.Y - startpoint.Y)
                End If
                If shape = "[]" Then
                    Image.CreateGraphics.FillRectangle(brush, startpoint.X, startpoint.Y, endpoint.X - startpoint.X, endpoint.Y - startpoint.Y)
                End If
                BrushModeToBrush.Enabled = True
                BrushModeToTool.Enabled = True
                BrushShapeToCircleButton.Enabled = True
                BrushShapeToSquareButton.Enabled = True
                Red.Enabled = True
                Green.Enabled = True
                Blue.Enabled = True
                NewButton.Enabled = True
                NewShortcut.Enabled = True
                OpenButton.Enabled = True
                OpenShortcut.Enabled = True
                SaveButton.Enabled = True
                SaveShortcut.Enabled = True
                CloseButton.Enabled = True
                CloseShortcut.Enabled = True
                AboutButton.Enabled = True
                HelpMenu.Enabled = True
                toolstate = "waitForStart"
                toolstate = ""
            End If
        End If
        StatusLabel.Text = "Ready"
        Exit Sub
pixeldrawhandler:
        MsgBox("Crashed - String not accepted in Brush Size TextBox!", MsgBoxStyle.Critical, "Error")
        End
    End Sub
' (...)
Private Sub BrushShapeToCircleButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrushShapeToCircleButton.Click
        StatusLabel.Text = "Changing Brush Shape..."
        shape = "o"
        If brushmode = "brush" Then
            Label2.Visible = True
            BrushSize.Visible = True
            FontButton.Visible = False
            Label3.Text = "Brush Color:"
            Label4.Visible = False
            TextToDrawBox.Visible = False
            TextToDrawBox.Enabled = False
            Label5.Text = "Preview Brush:"
            Dim pensize, coord As Single
            pensize = BrushSize.Text
            BrushPreview.CreateGraphics.FillRectangle(bgbrush, 0, 0, BrushPreview.Width, BrushPreview.Height)
            coord = (BrushPreview.Size.Width - pensize) / 2
            BrushPreview.CreateGraphics.FillEllipse(brush, coord, coord, pensize, pensize)
            StatusLabel.Text = "Ready"
            BrushShapeToSquareButton.Enabled = True
            BrushShapeToTextButton.Enabled = True
            BrushShapeToCircleButton.Enabled = False
        End If
        If brushmode = "tool" Then
            Label4.Visible = True
            Label4.Text = "Click starting point on drawing"
            BrushModeToBrush.Enabled = False
            BrushModeToTool.Enabled = False
            BrushShapeToCircleButton.Enabled = False
            BrushShapeToSquareButton.Enabled = False
            Red.Enabled = False
            Green.Enabled = False
            Blue.Enabled = False
            NewButton.Enabled = False
            NewShortcut.Enabled = False
            OpenButton.Enabled = False
            OpenShortcut.Enabled = False
            SaveButton.Enabled = False
            SaveShortcut.Enabled = False
            CloseButton.Enabled = False
            CloseShortcut.Enabled = False
            AboutButton.Enabled = False
            HelpMenu.Enabled = False
            toolstate = "waitForStart"
            StatusLabel.Text = "Ready"
        End If
    End Sub

    Private Sub BrushShapeToSquareButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrushShapeToSquareButton.Click
        StatusLabel.Text = "Changing Brush Shape..."
        shape = "[]"
        If brushmode = "brush" Then
            Label2.Visible = True
            BrushSize.Visible = True
            FontButton.Visible = False
            Label3.Text = "Brush Color:"
            Label4.Visible = False
            TextToDrawBox.Visible = False
            TextToDrawBox.Enabled = False
            Label5.Text = "Preview Brush:"
            Dim pensize, coord As Single
            pensize = BrushSize.Text
            BrushPreview.CreateGraphics.FillRectangle(bgbrush, 0, 0, BrushPreview.Width, BrushPreview.Height)
            coord = (BrushPreview.Size.Width - pensize) / 2
            BrushPreview.CreateGraphics.FillRectangle(brush, coord, coord, pensize, pensize)
            StatusLabel.Text = "Ready"
            BrushShapeToCircleButton.Enabled = True
            BrushShapeToTextButton.Enabled = True
            BrushShapeToSquareButton.Enabled = False
        End If
        If brushmode = "tool" Then
            Label4.Visible = True
            Label4.Text = "Click starting point on drawing"
            BrushModeToBrush.Enabled = False
            BrushModeToTool.Enabled = False
            BrushShapeToCircleButton.Enabled = False
            BrushShapeToSquareButton.Enabled = False
            Red.Enabled = False
            Green.Enabled = False
            Blue.Enabled = False
            NewButton.Enabled = False
            NewShortcut.Enabled = False
            OpenButton.Enabled = False
            OpenShortcut.Enabled = False
            SaveButton.Enabled = False
            SaveShortcut.Enabled = False
            CloseButton.Enabled = False
            CloseShortcut.Enabled = False
            AboutButton.Enabled = False
            HelpMenu.Enabled = False
            toolstate = "waitForStart"
            StatusLabel.Text = "Ready"
        End If
    End Sub

    Private Sub BrushShapeToTextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrushShapeToTextButton.Click
        StatusLabel.Text = "Changing Brush Shape..."
        shape = ""
        If brushmode = "brush" Then
            Label2.Visible = False
            BrushSize.Visible = False
            FontButton.Visible = True
            Label3.Text = "  Text Color:"
            Label4.Visible = True
            TextToDrawBox.Enabled = True
            TextToDrawBox.Visible = True
            Label5.Text = "  Preview Text:"
            Dim pensize As Single
            pensize = BrushSize.Text
            BrushPreview.CreateGraphics.FillRectangle(bgbrush, 0, 0, BrushPreview.Width, BrushPreview.Height)
            BrushPreview.CreateGraphics.DrawString(drawstring, stringfont, brush, 0, 0)
            StatusLabel.Text = "Ready"
            BrushShapeToCircleButton.Enabled = True
            BrushShapeToSquareButton.Enabled = True
            BrushShapeToTextButton.Enabled = False
        End If
        If brushmode = "tool" Then
            Label4.Visible = False
            TextToDrawBox.Visible = False
            TextToDrawBox.Enabled = False
            FontButton.Visible = False
            shape = "o"
        End If
    End Sub
' (...)
Private Sub BrushModeToBrush_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrushModeToBrush.CheckedChanged
        StatusLabel.Text = "Changing Brush Mode..."
        If BrushModeToBrush.Checked = True Then
            brushmode = "brush"
            BrushShapeToCircleButton.Enabled = True
            BrushShapeToSquareButton.Enabled = True
            BrushShapeToTextButton.Visible = True
            BrushShapeToTextButton.Enabled = True
            If shape = "o" Then BrushShapeToCircleButton.Enabled = False
            If shape = "[]" Then BrushShapeToSquareButton.Enabled = False
            If shape = "" Then BrushShapeToTextButton.Enabled = False
            Label1.Text = "Brush Shape:"
            Label2.Visible = True
            BrushSize.Visible = True
            Label3.Text = "Brush Color:"
            Label5.Text = "Preview Brush:"
            Dim pensize, coord As Single
            coord = (BrushPreview.Size.Width - pensize) / 2
            If shape = "o" Then
                BrushPreview.CreateGraphics.FillEllipse(brush, coord, coord, pensize, pensize)
            End If
            If shape = "[]" Then
                BrushPreview.CreateGraphics.FillRectangle(brush, coord, coord, pensize, pensize)
            End If
            StatusLabel.Text = "Ready"
        Else
            brushmode = "tool"
            BrushShapeToCircleButton.Enabled = True
            BrushShapeToSquareButton.Enabled = True
            BrushShapeToTextButton.Enabled = True
            BrushShapeToTextButton.Visible = False
            If shape = "" Then
                Label4.Visible = False
                TextToDrawBox.Visible = False
                TextToDrawBox.Enabled = False
                FontButton.Visible = False
                shape = "o"
            End If
            Label1.Text = "             Tool:"
            Label2.Visible = False
            BrushSize.Visible = False
            Label3.Text = "  Tool Color:"
            Label5.Text = "Preview Tool Color:"
            BrushPreview.CreateGraphics.FillRectangle(brush, 0, 0, BrushPreview.Width, BrushPreview.Height)
            StatusLabel.Text = "Ready"
        End If
    End Sub

    Private Sub BrushModeToTool_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrushModeToTool.CheckedChanged
        StatusLabel.Text = "Changing Brush Mode..."
        If BrushModeToTool.Checked = True Then
            brushmode = "tool"
            BrushShapeToCircleButton.Enabled = True
            BrushShapeToSquareButton.Enabled = True
            BrushShapeToTextButton.Enabled = True
            BrushShapeToTextButton.Visible = False
            If shape = "" Then
                Label4.Visible = False
                TextToDrawBox.Visible = False
                TextToDrawBox.Enabled = False
                FontButton.Visible = False
                shape = "o"
            End If
            Label1.Text = "             Tool:"
            Label2.Visible = False
            BrushSize.Visible = False
            Label3.Text = "  Tool Color:"
            Label5.Text = "Preview Tool Color:"
            BrushPreview.CreateGraphics.FillRectangle(brush, 0, 0, BrushPreview.Width, BrushPreview.Height)
            StatusLabel.Text = "Ready"
        Else
            brushmode = "brush"
            BrushShapeToCircleButton.Enabled = True
            BrushShapeToSquareButton.Enabled = True
            BrushShapeToTextButton.Visible = True
            BrushShapeToTextButton.Enabled = True
            If shape = "o" Then BrushShapeToCircleButton.Enabled = False
            If shape = "[]" Then BrushShapeToSquareButton.Enabled = False
            If shape = "" Then BrushShapeToTextButton.Enabled = False
            Label1.Text = "Brush Shape:"
            Label2.Visible = True
            BrushSize.Visible = True
            Label3.Text = "Brush Color:"
            Label5.Text = "Preview Brush:"
            Dim pensize, coord As Single
            coord = (BrushPreview.Size.Width - pensize) / 2
            If shape = "o" Then
                BrushPreview.CreateGraphics.FillEllipse(brush, coord, coord, pensize, pensize)
            End If
            If shape = "[]" Then
                BrushPreview.CreateGraphics.FillRectangle(brush, coord, coord, pensize, pensize)
            End If
            StatusLabel.Text = "Ready"
        End If
    End Sub
End Class



I think this is affected.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: Problems making a Paint program

Posted 13 May 2014 - 01:51 PM

Quote

My bad, I think the code didn't get attached. If not get it here.

Again, would you post the relevant section of code? Some folk are a bit leery heading off to who knows what destination mediafire, or cannot access it at all.

Quote

Off-topic, where's the edit function here? Still new

http://www.dreaminco...-to-edit-times/

This post has been edited by modi123_1: 13 May 2014 - 01:51 PM
Reason for edit:: seems the post was added to as i was writing my reply

Was This Post Helpful? 0
  • +
  • -

#5 xD@t0m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 61
  • Joined: 13-May 14

Re: Problems making a Paint program

Posted 13 May 2014 - 01:55 PM

View Postmodi123_1, on 13 May 2014 - 01:51 PM, said:



still cant edit, i didnt mean to quote that last line up there
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1