Click here to Skip to main content
15,905,587 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a usercontrol (link: http://www.mediafire.com/?h635lk4fazr9e7z), I don't understand what reason that I can't drag it into my Form, when I do this then VS2008 is out. Please check it to help me, thanks.
Posted
Updated 24-Aug-12 17:48pm
v2
Comments
Sergey Alexandrovich Kryukov 25-Aug-12 1:10am    
I tried it and confirm it for VS 2008. If I insert your component in the form explicitly, without stupid Designer, it is shown normally, but I cannot not say it behaves nicely: no correct behavior on docking (behaves like a fixed-size thing), looks ugly. At least nothing crashes. Of course, Studio should not crash even if you have some bugs, so this is a Studio bug.

First, do you really need your control to work with Designer? If I don't supply my components for the external users, I don't care about it -- Designer is pretty much a trash part of the Studio to work with it seriously.

If you need to supply your control to some external users, you need to investigate it. First of all, refactor your code to make it less dirty. Remove all hard-coded constants. The ugliest thing you have is "catch {}" -- you block propagation of exceptions -- never do it. Also you have "else {}". You explicitly call dispose of something local, but need to use "using" statement of dispose in "finally". You have "Graphics g = control.CreateGraphics();" which is not used anywhere. I'm almost sure you have more problems. I would not even try to test the control if the code is so dirty...

To investigate, you need to run the whole Studio under debugger. Or you will need to simplify the control down until problem disappears, and restore functionality step by step until you have this problem, to pin-point it. It will take a lot of time...

Sorry, I don't see immediate reason for the crash, it's just needs more time than I can invest; besides, I don't see much sense in it -- I would rather started re-writing it.

However, I have just on good advice on the instrument you can use...

--SA

1 solution

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:
C#
if (!DesignMode) {
   //rendering, setters, and a lot more...
}


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
 
Share this answer
 
Comments
Andrewpeter 25-Aug-12 5:13am    
Thank you very much for your advice, i put

if (!DesignMode) {


}

into my usercontrol methods, but VS still crashes. I very very confuse about this. I used to use Visual Basic 6.0 to work my projects, but now I use VS2008 (VC#) to do this, I only begin learning C#, if you can you help me re-write this code. I hope I will be learnt more C# language from you. Thanks.
Andrewpeter 25-Aug-12 12:30pm    
Oh, I find error:

public string BsungX
{
get
{
return BsungX; // This error: tmpBsungX, not BsungX
}
set
{
tmpBsungX = value;
txtBsungX.Text = tmpBsungX;
Invalidate();
}
}

Thanks SA.
Sergey Alexandrovich Kryukov 5-Sep-12 3:20am    
Great.
Good luck, call again.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900