c# - Why does this single line of code cause Visual Studio to crash? -


with 1 line of code, can cause vs2012 crash consistently. (by "crash" mean when hit build, visual studio hangs indefinitely , have kill task manager.) here's code (in custom user control):

public class transparentpanel : system.windows.forms.panel {     protected override void onpaintbackground(painteventargs pe)     {         this.invalidate(); //this offending line     } } 

to reproduce problem, create control based on above code , add windows form; try build solution. "build started..." displayed in status bar , vs , permanently freeze up. tried troubleshooting, using devenv /log, activity log displayed no errors or warnings. question is, why code fatal c# compiler? (it causes problems in ide too. example, after adding transparent control, properties pane becomes frozen whenever form designer open.)

side question: should bug reported microsoft? if so, how? (i tried submit bug on the ms connect site, apparently accepting bugs vs2013.)


[if want know background of why trying use line, read on.]

i created custom (windows forms) control application. (i trying create control partially transparent image, location changed through mouse interactions.) used following code, gave me image (on panel) transparency looking for:

public class transparentpanel : system.windows.forms.panel {     public image image { get; set; }      protected override void onpaint(painteventargs pe)     {         rectangle rect = new rectangle(this.location, this.size);         if (image != null)             pe.graphics.drawimage(image, this.displayrectangle);     }      protected override void onpaintbackground(painteventargs pe)     {         //this.invalidate();         brush brush = new solidbrush(color.fromargb(0, 0, 0, 0));         pe.graphics.fillrectangle(brush, pe.cliprectangle);     }      protected override createparams createparams     {                 {             createparams cp = base.createparams;             cp.exstyle |= 0x20; // ws_ex_transparent                    return cp;         }     } } 

however, transparency doesn't "stick". when control relocated, example event handler:

    private void transparentpanel1_mouseclick(object sender, mouseeventargs e)     {         int y = this.transparentpanel1.location.y ;         int x = this.transparentpanel1.location.x ;         this.transparentpanel1.location = new system.drawing.point(x-5, y-5);     } 

...the transparent portion of control retains same background had when first painted. (this can seen if control placed behind it. sorry, hard describe.) attempting use invalidate() repaint control, , therefore, repaint transparent portion match whatever behind control after relocation. when vs bug appeared. (actually didn't notice bug right away, rather excruciating isolate offending line of code.)

public class transparentpanel : system.windows.forms.panel {     protected override void onpaintbackground(painteventargs pe)     {         this.invalidate(); //this offending line     } } 

that akin infinite loop.

when panel repaints, handler called... , tell invalidate itself... causes repaint... calls handler... etc.

the designer loses mind. don't need or want invalidate control within onpaintbackground, unless conditional (still rare).


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -