Please see my comment to the question.
I promised one advice…
Use the following tool to investigate the Studio crash: put almost all of your code of your control in this block:
if (!DesignMode) {
}
Please see:
http://msdn.microsoft.com/en-us/library/system.componentmodel.component.designmode.aspx[
^].
This way, most of the code will work as it works not (I tested it, it does work somehow), but not under design mode, which should prevent Studio crash. Add some functionality feature you really need in design mode one by one until you have the crash again. This way, you will be able to locate the problem. Again, there is a Studio bug, so you just need a workaround. Your final result should still use this
(!DesignMode)
condition — many things really should never appear in design mode.
But first of all, I would re-write the code.
I found another big problem: your rendering is based on
PictureBox
. There is no single reason to use this control for the purpose you do. It does not help you at all, only adds up hassles, eats up your development time and resources. This control does not help at all. You should use
System.Windows.Forms.Control
instead and render everything in the overridden method
OnPaint
. This is a very usual mistake to abuse
PictureBox
.
For further detail, please see my past answers:
How do I clear a panel from old drawing[
^],
draw a rectangle in C#[
^],
Append a picture within picturebox[
^],
Drawing Lines between mdi child forms[
^],
capture the drawing on a panel[
^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[
^].
—SA