invalid parameter

davco1

New member
Joined
Aug 10, 2005
Messages
4
Programming Experience
Beginner
Can anyone tell me what causes this to throw an exception:'System.ArgumentException`

Imports System.Drawing

Public Class Form1

Inherits System.Windows.Forms.Form

#
Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

Me.BackColor = Color.Black

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 266)

Me.Name = "Form1"

Me.Text = "Form1"

End Sub

#End Region

Public Sub form1_Paint(ByVal e As System.Windows.Forms.PaintEventArgs)

End Sub

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

Dim g As Graphics = e.Graphics

Dim stripe As Image = New Bitmap("e:\colorbars.jpg")

Dim b1 As TextureBrush = New TextureBrush(stripe)

Dim b2 As SolidBrush = New SolidBrush(Color.Aquamarine)

Dim p1 As Pen

p1 =
New Pen(b1, 10)

g.DrawLine(p1, 20, 20,
Me.Width - 40, Me.Height - 40)

System.Threading.Thread.CurrentThread.Sleep(1000)

p1 =
New Pen(b2, 10)

g.DrawLine(p1, 20, 20,
Me.Width - 40, Me.Height - 40)

System.Threading.Thread.CurrentThread.Sleep(1000)

p1 =
New Pen(Color.BlanchedAlmond, 10)

g.DrawLine(p1, 20, 20,
Me.Width - 40, Me.Height - 40)

System.Threading.Thread.CurrentThread.Sleep(1000)

b1.Dispose()

b2.Dispose()

p1.Dispose()

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



End Sub



End Class

 
I don't know. Could you point out where the error is happening. Also is that the full error msg? Something feels like it's missing.

Is this copied directly from the IDE? I ask because it looks like there's a lot of spaces between words that is missing.
ProtectedOverloadsOverridesSub should be Protected Overloades Overrides Sub.
EndSub should be End Sub

Tg
 
It was copied from the ide but the code is right in the editor.
I don`t know what happened to it here.
The full msg is:An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Invalid parameter used.
When I step into the debugger I come to the no sub main found for mypen.form1 found.
I added a sub main in a module but still no success.
The debugger points to the {public class form1 } line of the code when I run it.
 
Check your project properties... it may be that it's set to Main as the start up object, rather than your form.

Tg
-I saw your other posting, it seems that the elimination of spaces is a problem with the forums here, and not your code.... but one can't be too careful.

:p
 
Back
Top