J
JoshuaAT123
Guest
Hi. I need help with this error. I was just trying to get this DrawCurve function to work. However, this error keeps messing me up and I don't know how to fix it. I am trying to interactively draw a line by clicking and then moving the mouse.
The code is below
Public Class Form1
Dim BMP As New Drawing.Bitmap(640, 480)
Dim GFX As Graphics = Graphics.FromImage(BMP)
Dim g As System.Drawing.Graphics
Dim r As System.Drawing.Graphics
Dim col As Color
Dim D As Integer
Dim p As Pen = New Pen(col, D)
Dim q As Pen = New Pen(Color.Black, 0)
Dim n As Pen = New Pen(Color.Black, 5)
Dim myPointsArray As New List(Of PointF)
Dim myPointsArrays(100)
Dim ShowGrid As Boolean = False
Dim Draw As Boolean = False
Dim isDrag As Boolean = False
Dim theRectangle As New Rectangle(New Point(0, 0), New Size(0, 0))
Dim startPoint As Point
'Dim penformat As
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PictureBox1.Refresh()
Dim H, W As Integer
r = PictureBox1.CreateGraphics
D = Depth.Text
W = Width.Text
H = Height.Text
p.Color = col
p.Width = D
g = PictureBox1.CreateGraphics
g.DrawRectangle(p, 100, 30, 60 * W, 60 * H)
g.DrawRectangle(p, 100, 450, 60 * W, 60 * H)
g.DrawRectangle(p, 588, 449, 60 * W, 60 * H)
r.DrawLine(n, 500, 15, 500, 900)
r.DrawLine(n, 117, 313, 847, 313)
End Sub
'Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
'PictureBox1.Refresh()
'Dim myGraphics As Graphics = Me.CreateGraphics
'Dim OurPen As Pen
'OurPen = New Pen(Brushes.DarkOrange, 5)
'g = PictureBox1.CreateGraphics
'g.DrawLine(OurPen, 360, 150, 380, 150)
'End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
col = Color.Red
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub White_CheckedChanged(sender As Object, e As EventArgs) Handles White.CheckedChanged
col = Color.White
End Sub
Private Sub Blue_CheckedChanged(sender As Object, e As EventArgs) Handles Blue.CheckedChanged
col = Color.Blue
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
p.DashStyle = Drawing2D.DashStyle.Solid
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
p.DashStyle = Drawing2D.DashStyle.Dash
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
Draw = True
End Sub
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
'fprintf("Line Color");
End Sub
Private Sub PictureBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseClick
Label5.Text = "X = " & e.X & " ; Y = " & e.Y
End Sub
Private Sub About_Click(sender As Object, e As EventArgs) Handles About.Click
'FileOpen(1, "c:\readme.txt", ) ' Open file for output.
End Sub
' Private Sub Button2_Click(sender As Object, e As EventArgs)
' ShowGrid = Not ShowGrid
' PictureBox1.Invalidate()
'End Sub
Private Sub CheckBox3_CheckedChanged_1(sender As Object, e As EventArgs) Handles gridon.CheckedChanged
For i As Integer = 1 To 44
g.DrawLine(q, 20 * i, 0, 20 * i, 735)
Next
For j As Integer = 1 To 37
g.DrawLine(q, 0, 20 * j, 878, 20 * j)
Next
End Sub
Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
Dim offset As Integer = 2
Dim numSegments As Integer = 4
Dim tension As Single = 0.0F
'If else statement here
If Draw = True Then
Label5.Text = "X = " & e.X & " ; Y = " & e.Y
Dim x As Integer = e.X
Dim y As Integer = e.Y
Dim len As Integer
myPointsArray.Add(New PointF(x, y))
len = myPointsArray.Count
Dim array(len) As PointF
For i As Integer = 0 To len - 1
array(i) = myPointsArray(i)
Next
PictureBox1.Refresh()
g.DrawCurve(p, array, offset, numSegments, tension)
End If
' g.DrawPoint(p, e.X, e.Y, NewPoint(e.X, e.Y))
End Sub
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
End Sub
' Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As _System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
' Set the isDrag variable to true and get the starting point
' by using the PointToScreen method to convert form coordinates to
' screen coordinates.
' If (e.Button = MouseButtons.Left) Then
' isDrag = True
' End If
' Dim control As Control = CType(sender, Control)
' Calculate the startPoint by using the PointToScreen
' method.
' startPoint = control.PointToScreen(New Point(e.X, e.Y))
'End Sub
End Class
Thanks
Continue reading...
The code is below
Public Class Form1
Dim BMP As New Drawing.Bitmap(640, 480)
Dim GFX As Graphics = Graphics.FromImage(BMP)
Dim g As System.Drawing.Graphics
Dim r As System.Drawing.Graphics
Dim col As Color
Dim D As Integer
Dim p As Pen = New Pen(col, D)
Dim q As Pen = New Pen(Color.Black, 0)
Dim n As Pen = New Pen(Color.Black, 5)
Dim myPointsArray As New List(Of PointF)
Dim myPointsArrays(100)
Dim ShowGrid As Boolean = False
Dim Draw As Boolean = False
Dim isDrag As Boolean = False
Dim theRectangle As New Rectangle(New Point(0, 0), New Size(0, 0))
Dim startPoint As Point
'Dim penformat As
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PictureBox1.Refresh()
Dim H, W As Integer
r = PictureBox1.CreateGraphics
D = Depth.Text
W = Width.Text
H = Height.Text
p.Color = col
p.Width = D
g = PictureBox1.CreateGraphics
g.DrawRectangle(p, 100, 30, 60 * W, 60 * H)
g.DrawRectangle(p, 100, 450, 60 * W, 60 * H)
g.DrawRectangle(p, 588, 449, 60 * W, 60 * H)
r.DrawLine(n, 500, 15, 500, 900)
r.DrawLine(n, 117, 313, 847, 313)
End Sub
'Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
'PictureBox1.Refresh()
'Dim myGraphics As Graphics = Me.CreateGraphics
'Dim OurPen As Pen
'OurPen = New Pen(Brushes.DarkOrange, 5)
'g = PictureBox1.CreateGraphics
'g.DrawLine(OurPen, 360, 150, 380, 150)
'End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
col = Color.Red
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub White_CheckedChanged(sender As Object, e As EventArgs) Handles White.CheckedChanged
col = Color.White
End Sub
Private Sub Blue_CheckedChanged(sender As Object, e As EventArgs) Handles Blue.CheckedChanged
col = Color.Blue
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
p.DashStyle = Drawing2D.DashStyle.Solid
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
p.DashStyle = Drawing2D.DashStyle.Dash
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
Draw = True
End Sub
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
'fprintf("Line Color");
End Sub
Private Sub PictureBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseClick
Label5.Text = "X = " & e.X & " ; Y = " & e.Y
End Sub
Private Sub About_Click(sender As Object, e As EventArgs) Handles About.Click
'FileOpen(1, "c:\readme.txt", ) ' Open file for output.
End Sub
' Private Sub Button2_Click(sender As Object, e As EventArgs)
' ShowGrid = Not ShowGrid
' PictureBox1.Invalidate()
'End Sub
Private Sub CheckBox3_CheckedChanged_1(sender As Object, e As EventArgs) Handles gridon.CheckedChanged
For i As Integer = 1 To 44
g.DrawLine(q, 20 * i, 0, 20 * i, 735)
Next
For j As Integer = 1 To 37
g.DrawLine(q, 0, 20 * j, 878, 20 * j)
Next
End Sub
Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
Dim offset As Integer = 2
Dim numSegments As Integer = 4
Dim tension As Single = 0.0F
'If else statement here
If Draw = True Then
Label5.Text = "X = " & e.X & " ; Y = " & e.Y
Dim x As Integer = e.X
Dim y As Integer = e.Y
Dim len As Integer
myPointsArray.Add(New PointF(x, y))
len = myPointsArray.Count
Dim array(len) As PointF
For i As Integer = 0 To len - 1
array(i) = myPointsArray(i)
Next
PictureBox1.Refresh()
g.DrawCurve(p, array, offset, numSegments, tension)
End If
' g.DrawPoint(p, e.X, e.Y, NewPoint(e.X, e.Y))
End Sub
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
End Sub
' Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As _System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
' Set the isDrag variable to true and get the starting point
' by using the PointToScreen method to convert form coordinates to
' screen coordinates.
' If (e.Button = MouseButtons.Left) Then
' isDrag = True
' End If
' Dim control As Control = CType(sender, Control)
' Calculate the startPoint by using the PointToScreen
' method.
' startPoint = control.PointToScreen(New Point(e.X, e.Y))
'End Sub
End Class
Thanks
Continue reading...