467,168 Members | 1,011 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,168 developers. It's quick & easy.

Want to Dispose the Image Object in Derived class (MDIChildForm)

I want to dispose the image object in my child form, unless I won't dispose this

object i can't delete the image file in my folder.
I get this error in MDIparent form

"An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll"
"Additional information: Invalid parameter used."

Here is my code:-

Public Class frmViewImage
Inherits System.Windows.Forms.Form

Dim myOleAdapter As OleDbDataAdapter
Dim mydataset As DataSet = New DataSet()
Dim mydatatable As DataTable = New DataTable()
Dim mycommander As OleDbCommandBuilder

Private savedImageName As String
Private curImage As Image = Nothing

Dim iRecordCount As Integer
Dim iCurrentPosition As Integer
Dim WithEvents oBinding As Binding

Dim flag As Boolean = True
Dim tmpStr As String

Dim myCommand As OleDbCommandBuilder
#Region " Windows Form Designer generated code "

Public Sub New()

'This call is required by the Windows Form Designer.

'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
End If

End If

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.
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents cmbUserName As System.Windows.Forms.ComboBox
Friend WithEvents cmdNext As System.Windows.Forms.Button
Friend WithEvents cmdFirst As System.Windows.Forms.Button
Friend WithEvents cmdPrev As System.Windows.Forms.Button
Friend WithEvents CmdLast As System.Windows.Forms.Button
Friend WithEvents txtImageCmnts As System.Windows.Forms.TextBox
Friend WithEvents CmdExit As System.Windows.Forms.Button
Friend WithEvents lblImageName As System.Windows.Forms.Label
Friend WithEvents CmbCategory As System.Windows.Forms.ComboBox
Friend WithEvents CmdExecute As System.Windows.Forms.Button
Friend WithEvents CmdDelete As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.cmbUserName = New System.Windows.Forms.ComboBox()
Me.CmbCategory = New System.Windows.Forms.ComboBox()
Me.cmdNext = New System.Windows.Forms.Button()
Me.cmdFirst = New System.Windows.Forms.Button()
Me.cmdPrev = New System.Windows.Forms.Button()
Me.CmdLast = New System.Windows.Forms.Button()
Me.txtImageCmnts = New System.Windows.Forms.TextBox()
Me.CmdExit = New System.Windows.Forms.Button()
Me.lblImageName = New System.Windows.Forms.Label()
Me.CmdExecute = New System.Windows.Forms.Button()
Me.CmdDelete = New System.Windows.Forms.Button()
Me.Button1 = New System.Windows.Forms.Button()
Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.PictureBox1.Location = New System.Drawing.Point(24, 56)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(536, 432)
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
Me.cmbUserName.Location = New System.Drawing.Point(64, 24)
Me.cmbUserName.Name = "cmbUserName"
Me.cmbUserName.Size = New System.Drawing.Size(121, 21)
Me.cmbUserName.TabIndex = 1
Me.CmbCategory.Location = New System.Drawing.Point(200, 24)
Me.CmbCategory.Name = "CmbCategory"
Me.CmbCategory.Size = New System.Drawing.Size(121, 21)
Me.CmbCategory.TabIndex = 2
Me.cmdNext.Location = New System.Drawing.Point(214, 504)
Me.cmdNext.Name = "cmdNext"
Me.cmdNext.TabIndex = 3
Me.cmdNext.TabStop = False
Me.cmdNext.Text = "Next"
Me.cmdFirst.Location = New System.Drawing.Point(48, 504)
Me.cmdFirst.Name = "cmdFirst"
Me.cmdFirst.TabIndex = 4
Me.cmdFirst.TabStop = False
Me.cmdFirst.Text = "First"
Me.cmdPrev.Location = New System.Drawing.Point(131, 504)
Me.cmdPrev.Name = "cmdPrev"
Me.cmdPrev.TabIndex = 5
Me.cmdPrev.TabStop = False
Me.cmdPrev.Text = "Previous"
Me.CmdLast.Location = New System.Drawing.Point(297, 504)
Me.CmdLast.Name = "CmdLast"
Me.CmdLast.TabIndex = 6
Me.CmdLast.TabStop = False
Me.CmdLast.Text = "Last"
Me.txtImageCmnts.Location = New System.Drawing.Point(568, 128)
Me.txtImageCmnts.Multiline = True
Me.txtImageCmnts.Name = "txtImageCmnts"
Me.txtImageCmnts.Size = New System.Drawing.Size(224, 352)
Me.txtImageCmnts.TabIndex = 7
Me.txtImageCmnts.Text = ""
Me.CmdExit.Location = New System.Drawing.Point(448, 504)
Me.CmdExit.Name = "CmdExit"
Me.CmdExit.TabIndex = 8
Me.CmdExit.Text = "Exit"
Me.lblImageName.Location = New System.Drawing.Point(608, 56)
Me.lblImageName.Name = "lblImageName"
Me.lblImageName.Size = New System.Drawing.Size(160, 23)
Me.lblImageName.TabIndex = 9
Me.lblImageName.Text = "Img"
Me.CmdExecute.Location = New System.Drawing.Point(384, 24)
Me.CmdExecute.Name = "CmdExecute"
Me.CmdExecute.TabIndex = 10
Me.CmdExecute.Text = "Execute"
Me.CmdDelete.Location = New System.Drawing.Point(376, 512)
Me.CmdDelete.Name = "CmdDelete"
Me.CmdDelete.TabIndex = 11
Me.CmdDelete.Text = "Delete"
Me.Button1.Location = New System.Drawing.Point(8, 512)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 12
Me.Button1.Text = "Button1"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(804, 550)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.

CmdDelete, Me.CmdExecute, Me.lblImageName, Me.CmdExit, Me.txtImageCmnts, Me.CmdLast,

Me.cmdPrev, Me.cmdFirst, Me.cmdNext, Me.CmbCategory, Me.cmbUserName, Me.PictureBox1})
Me.Name = "frmViewImage"
Me.Text = "frmViewImage"
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized

End Sub

#End Region

Private Sub CmdExit_Click(ByVal sender As System.Object, ByVal e As System.

EventArgs) Handles CmdExit.Click
End Sub

Private Sub frmViewImage_Load(ByVal sender As System.Object, ByVal e As System.

EventArgs) Handles MyBase.Load
If conn.State <> ConnectionState.Open Then
End If

myOleAdapter = New OleDbDataAdapter("select UserId,UserName from UserInfo

", conn)
myOleAdapter.Fill(mydataset, "UserInfo")
mydatatable = mydataset.Tables("UserInfo")

cmbUserName.DataSource = mydatatable
cmbUserName.DisplayMember = "UserName"
cmbUserName.ValueMember = "UserId"
Console.WriteLine("Error Opening {0}", conn.DataSource)
End Try

myOleAdapter = New OleDbDataAdapter("select CategoryName from Category",

myOleAdapter.Fill(mydataset, "category")
mydatatable = mydataset.Tables("Category")

CmbCategory.DataSource = mydatatable
CmbCategory.DisplayMember = "CategoryName"
Catch ex As Exception
Console.Write("Error Opening {0}", conn.DataSource)
End Try

myOleAdapter = New OleDbDataAdapter("select * from Users", conn)
myOleAdapter.Fill(mydataset, "Users")
mydatatable = mydataset.Tables("Users")

Catch ex As Exception
Console.WriteLine("Error opening {0}", conn.DataSource)
End Try

myCommand = New OleDbCommandBuilder(myOleAdapter)

End Sub

Private Sub cmdFirst_Click(ByVal sender As System.Object, ByVal e As System.

EventArgs) Handles cmdFirst.Click
iCurrentPosition = 0
End Sub

Private Sub CmdLast_Click(ByVal sender As System.Object, ByVal e As System.

EventArgs) Handles CmdLast.Click
iCurrentPosition = mydataset.Tables("Users").Rows.Count - 1
End Sub

Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.

EventArgs) Handles cmdNext.Click
If (iCurrentPosition < mydataset.Tables("Users").Rows.Count - 1) Then
iCurrentPosition = iCurrentPosition + 1
flag = False
cmdPrev.Enabled = True
'cmdNext.Enabled = False
MessageBox.Show("Last Record")
Catch efrm As Exception
End Try
End If

End Sub

Private Sub cmdPrev_Click(ByVal sender As System.Object, ByVal e As System.

EventArgs) Handles cmdPrev.Click
If (iCurrentPosition > 0) Then
iCurrentPosition = iCurrentPosition - 1
cmdNext.Enabled = True
cmdPrev.Enabled = False
MessageBox.Show("First Record")

End If
End Sub

Private Sub CmdExecute_Click(ByVal sender As System.Object, ByVal e As System.

EventArgs) Handles CmdExecute.Click
Dim sql As String

mydataset = New DataSet()
mydatatable = New DataTable()
sql = "select * from Users where CategoryName='" & CmbCategory.Text & "'"

If conn.State <> ConnectionState.Open Then
End If

myOleAdapter = New OleDbDataAdapter(sql, conn)
myOleAdapter.Fill(mydataset, "Users")
mydatatable = mydataset.Tables("Users")

Catch ex As Exception
End Try
End Sub

Private Sub CmdDelete_Click(ByVal sender As System.Object, ByVal e As System.

EventArgs) Handles CmdDelete.Click

Dim dr As DataRow
dr = mydataset.Tables("Users").Rows(iCurrentPosition)

Catch ex As Exception
End Try

myOleAdapter.Update(mydataset, "Users")
Catch ex As Exception
End Try

iCurrentPosition = mydataset.Tables("Users").Rows.Count - 1


End Sub

Private Sub display()
txtImageCmnts.DataBindings.Add(New Binding("Text", mydataset.Tables("Users"),

lblImageName.DataBindings.Add(New Binding("Text", mydataset.Tables("Users"),

savedImageName = lblImageName.Text
iCurrentPosition = 0
End Sub

Private Sub callblob()

' Display image
curImage = Image.FromFile(savedImageName)
PictureBox1.Image = curImage
End Sub

Private Sub showData()
lblImageName.Text = mydataset.Tables("Users").Rows(iCurrentPosition)("

txtImageCmnts.Text = mydataset.Tables("Users").Rows(iCurrentPosition)(" Cmnts

savedImageName = lblImageName.Text
End Sub

Private Sub DeleteAll()
If flag = False Then
flag = True
End If
End Sub
End Class

I hope anybody can solve this to me
And thanks in advance
From: Deepak C.G

Posted by a user from .NET 247 (http://www.dotnet247.com/)

Nov 21 '05 #1
  • viewed: 1648

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Andreas Huber | last post: by
4 posts views Thread by Sunit Joshi | last post: by
6 posts views Thread by Cody Powell | last post: by
16 posts views Thread by Jeremy | last post: by
1 post views Thread by Just Me | last post: by
156 posts views Thread by Dennis | last post: by
13 posts views Thread by Grafix | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.