rubbernilly
Programmer
Hello, all...
Problem Basics:
I have an icon-heavy richtextboxex control on a secondary form, built from my main form. The first time I instantiate a new form2 and build the contents of the RTBex, the form displays no problem. The second time, it dumps out with an unhandled exception in System.Drawing.dll, telling me it cannot access a disposed object named 'Icon.'
This only happens when the lines of the RTBex number in the thousands. Less than that, and the form can be shown over and over and over.
Code and more detail (if necessary) is below.
Problem Detail:
I am trying to output the contents of a string array to a RichTextBoxEx (from the MSDN example).
From Form1, I build the string array, which has a leading character that references a icon index in an ImageList that I am passing to the second form and procedure. I strip that character off and convert it to an integer, then put that ImageIndex bitmap on the clipboard to paste into the RTBex control. After that, I parse the string around a pipe character. I write what comes before the pipe character to the RTBex control, then I paste the image from the ImageList, then I write what came after the pipe character in the string.
For example, the first element of the string array that I am working with might read:
That would be MyImageList.Images(3), and the output line in the RTBex would translate to:
Code:
Here is the relevant code:
Like I said, this works fine for small numbers of lines being written - the form can be opened over and over. With a large number of lines (i'm not sure how many), the form works the first time, but I get the error when I close that form and open it again.
Problem Basics:
I have an icon-heavy richtextboxex control on a secondary form, built from my main form. The first time I instantiate a new form2 and build the contents of the RTBex, the form displays no problem. The second time, it dumps out with an unhandled exception in System.Drawing.dll, telling me it cannot access a disposed object named 'Icon.'
This only happens when the lines of the RTBex number in the thousands. Less than that, and the form can be shown over and over and over.
Code and more detail (if necessary) is below.
Problem Detail:
I am trying to output the contents of a string array to a RichTextBoxEx (from the MSDN example).
From Form1, I build the string array, which has a leading character that references a icon index in an ImageList that I am passing to the second form and procedure. I strip that character off and convert it to an integer, then put that ImageIndex bitmap on the clipboard to paste into the RTBex control. After that, I parse the string around a pipe character. I write what comes before the pipe character to the RTBex control, then I paste the image from the ImageList, then I write what came after the pipe character in the string.
For example, the first element of the string array that I am working with might read:
Code:
3 | c:\documents
Code:
{Bitmap} c:\documents
Code:
Here is the relevant code:
Code:
'Form1 code
'sVal and sRet are ArrayLists
'ilDirFil is the ImageList
Dim frt As New DirectoryOutput.frmRTF()
frt.FillRTB(sVal, Me.ilDirFil)
GC.Collect() 'thought it might be a memory leak
frt.Show()
frt = Nothing 'thought it might be eating resources
'Form2 code
Public Overloads Sub FillRTB(ByVal sVal As ArrayList, ByVal iml As ImageList)
Dim a As Long, sText As String, iImage As Integer, objBitMap(iml.Images.Count - 1) As Bitmap, _
sSplit() As String
'assign the bitmap array elements to the imagelist elements
For a = 0 To iml.Images.Count - 1
objBitMap(a) = New Bitmap(iml.Images(a))
Next
For a = 0 To sVal.Count - 1
'get the correct image index
iImage = CInt(Microsoft.VisualBasic.Left(sVal(a), 1))
sText = sVal(a)
'remove the image index key from the front of the string
sText = sText.Remove(0, 1)
Clipboard.SetDataObject(objBitMap(iImage))
'split the string about the pipe character
sSplit = Split(sText, "|")
'put the three parts into the RTBex
Me.rtxOutput.AppendText(sSplit(0))
Me.rtxOutput.Paste(DataFormats.GetFormat(DataFormats.Bitmap))
Me.rtxOutput.AppendText(" " + sSplit(1) + vbCrLf)
System.Windows.Forms.Application.DoEvents()
Next
Me.rtxOutput.SelectionStart = 0
End Sub
Like I said, this works fine for small numbers of lines being written - the form can be opened over and over. With a large number of lines (i'm not sure how many), the form works the first time, but I get the error when I close that form and open it again.