Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error

Status
Not open for further replies.
Jul 1, 2005
4
GB
I am currently studing VB and have not much experience in troubleshooting runtime errors. I am studing out of a book MCSD Training and have designed a form using 5 object within the form.

A graphics object which will be used on the form to draw the graphics.

A hitcbrush object which calls on the fillelipse method.
This object imports from System.Drawing.Drawing2D namespace.

A image object which save the image as a JPG.

A brush object which is used to pass the fillelipse method to the texture brush object.

A linergradient object to pass the fillelipse method to it.

this is the code from the book which i have inclosed

Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
'error in this code'
Public Class StepByStep1_19
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()

'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()
components = New System.ComponentModel.Container
Me.Text = "StepByStep1_19"
End Sub

#End Region
Private Sub StepByStep1_19_paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles MyBase.Paint
Dim grfx As Graphics = e.Graphics
'create a hatchbrush object
'call fillellipse method by passing
'the created hatchbrush object
'The hatch brush is apart of the system.drawing.drawing2d namespace
Dim hb As HatchBrush = New HatchBrush(HatchStyle.HorizontalBrick, _
Color.Blue, Color.FromArgb(100, Color.Yellow))
grfx.FillEllipse(hb, 20, 10, 100, 100)

'create a texturebrush object
'create a fillellipse method by passing the created texture brush object'
Dim img As Image = New Bitmap("sunset.jpg")
Dim tb As Brush = New TextureBrush(img)
grfx.FillEllipse(tb, 150, 10, 100, 100)

'create a lineargradient object
'call fillellipse method by passing
'the created linergradientbrush object
'The lineargradient brush is apart of the system.drawing.drawing2d namespace
Dim lb As LinearGradientBrush = _
New LinearGradientBrush( _
New Rectangle(80, 150, 100, 100), _
Color.Red, Color.Yellow, _
LinearGradientMode.BackwardDiagonal)
grfx.FillEllipse(lb, 80, 150, 100, 100)
End Sub

End Class

The error i recevie is

An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

Additional information: Invalid parameter used.

if i click on continue nothing happens and it highlights
StepByStep1_19 in green

Just wondering what it could be i have tried to do a search on this but give me example on different scenerios getting the same error message.

Any feedback is much appricated.

Thanks
 
put the line...

Option Strict On

at the top of the page...this will higlight any obvious problems

The line...

New Bitmap("sunset.jpg")

could be the problem for 2 reasons

1) enter the full path of the file eg c:\temp\sunset.jpg as the default location is determined by the environment, not the application
you can get the application location from application.executablepath
2) try using Image instead of Bitmap (image.loadfromfile or something similar)

If that doesn't help try stepping through the code to see which line causes the error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top