I'm having some trouble with a usercontrol i made (for a graphical button).
It uses 6 hidden pictureboxes.
3 pictureboxes for the source of graphical states (normal, rollover, clicked) ( controlarray picSrc(0,1,2) )
3 more for temporary pictures. ( picBut(0,1,2) )
at initialize time and usercontrol_resize i resize pictureboxes picBut() to the size of the usercontrol.
Then i fill them using picturebox.paintpicture from picSrc. (I use 3 paintpicture calls for each so i can scale the ends separatly from the middle so the buttons keep nicely pill shaped.)
Heres the code:
The actual variables and maths isn't important, that much works.
' left end
picBut(i).PaintPicture picSrc(i).Picture, 0, 0, butCurve2, ctlHeight, 0, 0, butCurve, butHeight
picBut(i).PaintPicture picSrc(i).Picture, butCurve2 - 10, 0, ctlWidth - (butCurve2 * 2) + 20, ctlHeight, butCurve, 0, butWidth - (butCurve * 2), butHeight
' right end
picBut(i).PaintPicture picSrc(i).Picture, ctlWidth - butCurve2, 0, butCurve2, ctlHeight, butWidth - butCurve, 0, butCurve, butHeight
at this point I also set the usercontrols maskimage property to one of the picBut()s, to get the transparency right.
"Set UserControl.MaskPicture = picBut(0).Image"
Now whenever i want to actually draw the button i just set the usercontrols image to the relevent picBut() depending on the mouse state etc. (another thing i tried that works the same is using usercontrol.paintpicture)
"Set UserControl.Picture = picBut(intState).Image" or
"UserControl.PaintPicture picBut(intState).Image, 0, 0"
Sorry if this is confusingly written so far, i'm getting to the point
Now this all works and looks fine.
Looking at the task manager I see that each instance of the usercontrol uses multiple megabytes of memory. (the pictures are only ~ 150x50 pixels and there are only 3 states. The amount of memory used goes up fast with the size of the control. if i resize the control to around 400x200 or so it uses around 60+ megabytes of memory! this is for each instance or a form.
I've tried a few things.
By commenting out the lines about the memory problem goes
away. (but the control doesn't display anything :P )
Commenting them out one by one shows that they all play a part in the missing memory.
I'm not sure what the problem is. I thought the code looked safe and simple. I'm not doing anything tricky with the API or DC's or anything. I just can't figure where those megs of memory are going.
Also, the memory usage for the VBIDE in task manager doesn't go up, only the total system memory used does, and the memory coems straight back after deleting the usercontrol from the form, so it's not like the is memory being lost forever.
If anyone knows what could be causing this it would be a big help.