custom midi background

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DaveL

    custom midi background

    when painting the background of a mdi app window
    how can i resolve the flicker when it paints
    from darker to lighter colors

    below is the code i wrote


    private void ShellWindow_Gra dient(object sender, PaintEventArgs e)
    {



    Graphics oGraphics = (Graphics)e.Gra phics;
    //enum i Defined
    if (this.StyleType == NetToolsUI.Wind owStyle.Solid)
    {

    this.oMdi.BackC olor = this.SolidColor ; //.RoyalBlue;
    //.FromArgb(35,7, 143); //.Brushes.AliceB lue;

    }
    else if (this.StyleType == NetToolsUI.Wind owStyle.Gradien t)
    {
    Rectangle rect = oMdi.ClientRect angle;
    rect.Inflate(2, 2);// to completely fill the client area

    LinearGradientB rush filler = new LinearGradientB rush(
    rect,
    this.SolidColor ,
    this.LightColor ,
    90,true); //this._angle);
    oGraphics.FillR ectangle(filler , rect);


    filler.Dispose( );
    }
    //Draw Some Text On the Window
    // Create string to draw.
    //e.MeasureString (drawString, this.Font);
    // Create font and brush.
    System.Drawing. SizeF TxtSize = oGraphics.Measu reString(Header ,
    this.HeaderFont );
    SolidBrush GreyBrush = new SolidBrush(this .ShadowColor);
    SolidBrush BlackBrush = new SolidBrush(this .HeaderColor);
    // Create point for upper-left corner of drawing.
    //x=widht
    //y=height
    //centers
    //float x = (this.ClientSiz e.Width / 2) - (TxtSize.Width / 2);
    //float y = (this.ClientSiz e.Height / 2) - (TxtSize.Height / 2);
    float x = (oMdi.ClientSiz e.Width / 2) - (TxtSize.Width / 2);
    float y = ((float)(oMdi.C lientSize.Heigh t
    /this.HeaderLoca tion)) - (float)(TxtSize .Height/HeaderLocation );
    // Set format of string.
    StringFormat drawFormat = new StringFormat();
    drawFormat.Form atFlags =
    StringFormatFla gs.MeasureTrail ingSpaces;
    //draw Shadow
    oGraphics.DrawS tring(Header, this.HeaderFont , GreyBrush, x + 3,
    y + 3, drawFormat);
    // Draw string to screen.

    oGraphics.DrawS tring(Header, this.HeaderFont , BlackBrush, x, y,
    drawFormat);
    //draw Owner Notice bottom Right


    BlackBrush = new SolidBrush(this .FooterColor);
    TxtSize = oGraphics.Measu reString(Footer , this.FooterFont );

    //text
    oGraphics.DrawS tring(Footer, this.FooterFont , BlackBrush,
    oMdi.ClientSize .Width - (TxtSize.Width+ 10),
    oMdi.ClientSize .Height
    - (TxtSize.Height +10), drawFormat);


    }

    Thanks DaveL


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: custom midi background

    Dave,

    Well, you are doing quite a bit of work there in the method.
    Specifically, I see three brushes (which should have Dispose called on them,
    btw) which you are creating each time that method is called. The paint
    event can be fired a number of times, so I would recommend that you create
    filler, blackbrush, greybrush, etc, etc outside of the paint method, and
    then change them when needed (when you change the color in your
    preferences). That way, you are not constantly allocating those objects.

    You would then dispose those brushes when the appropriate preferences
    change, or when the application terminates.

    You might also want to cache the StringFormat instance (or better yet,
    create it once for the lifetime of your app, since it doesn't seem like it
    is dependent on anything in it).


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "DaveL" <dvs_bis@sbcglo bal.netwrote in message
    news:7LEQk.2365 $%11.898@flpi14 4.ffdc.sbc.com. ..
    when painting the background of a mdi app window
    how can i resolve the flicker when it paints
    from darker to lighter colors
    >
    below is the code i wrote
    >
    >
    private void ShellWindow_Gra dient(object sender, PaintEventArgs e)
    {
    >
    >
    >
    Graphics oGraphics = (Graphics)e.Gra phics;
    //enum i Defined
    if (this.StyleType == NetToolsUI.Wind owStyle.Solid)
    {
    >
    this.oMdi.BackC olor = this.SolidColor ; //.RoyalBlue;
    //.FromArgb(35,7, 143); //.Brushes.AliceB lue;
    >
    }
    else if (this.StyleType == NetToolsUI.Wind owStyle.Gradien t)
    {
    Rectangle rect = oMdi.ClientRect angle;
    rect.Inflate(2, 2);// to completely fill the client area
    >
    LinearGradientB rush filler = new LinearGradientB rush(
    rect,
    this.SolidColor ,
    this.LightColor ,
    90,true); //this._angle);
    oGraphics.FillR ectangle(filler , rect);
    >
    >
    filler.Dispose( );
    }
    //Draw Some Text On the Window
    // Create string to draw.
    //e.MeasureString (drawString, this.Font);
    // Create font and brush.
    System.Drawing. SizeF TxtSize = oGraphics.Measu reString(Header ,
    this.HeaderFont );
    SolidBrush GreyBrush = new SolidBrush(this .ShadowColor);
    SolidBrush BlackBrush = new SolidBrush(this .HeaderColor);
    // Create point for upper-left corner of drawing.
    //x=widht
    //y=height
    //centers
    //float x = (this.ClientSiz e.Width / 2) - (TxtSize.Width / 2);
    //float y = (this.ClientSiz e.Height / 2) - (TxtSize.Height /
    2);
    float x = (oMdi.ClientSiz e.Width / 2) - (TxtSize.Width / 2);
    float y = ((float)(oMdi.C lientSize.Heigh t
    /this.HeaderLoca tion)) - (float)(TxtSize .Height/HeaderLocation );
    // Set format of string.
    StringFormat drawFormat = new StringFormat();
    drawFormat.Form atFlags =
    StringFormatFla gs.MeasureTrail ingSpaces;
    //draw Shadow
    oGraphics.DrawS tring(Header, this.HeaderFont , GreyBrush, x + 3,
    y + 3, drawFormat);
    // Draw string to screen.
    >
    oGraphics.DrawS tring(Header, this.HeaderFont , BlackBrush, x, y,
    drawFormat);
    //draw Owner Notice bottom Right
    >
    >
    BlackBrush = new SolidBrush(this .FooterColor);
    TxtSize = oGraphics.Measu reString(Footer , this.FooterFont );
    >
    //text
    oGraphics.DrawS tring(Footer, this.FooterFont , BlackBrush,
    oMdi.ClientSize .Width - (TxtSize.Width+ 10),
    >
    oMdi.ClientSize .Height - (TxtSize.Height +10), drawFormat);
    >
    >
    }
    >
    Thanks DaveL
    >
    >

    Comment

    • DaveL

      #3
      Re: custom midi background

      Thanks alot....will clean it up better

      DaveL

      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
      message news:%230tB0yCQ JHA.3936@TK2MSF TNGP06.phx.gbl. ..
      Dave,
      >
      Well, you are doing quite a bit of work there in the method.
      Specifically, I see three brushes (which should have Dispose called on
      them, btw) which you are creating each time that method is called. The
      paint event can be fired a number of times, so I would recommend that you
      create filler, blackbrush, greybrush, etc, etc outside of the paint
      method, and then change them when needed (when you change the color in
      your preferences). That way, you are not constantly allocating those
      objects.
      >
      You would then dispose those brushes when the appropriate preferences
      change, or when the application terminates.
      >
      You might also want to cache the StringFormat instance (or better yet,
      create it once for the lifetime of your app, since it doesn't seem like it
      is dependent on anything in it).
      >
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >
      "DaveL" <dvs_bis@sbcglo bal.netwrote in message
      news:7LEQk.2365 $%11.898@flpi14 4.ffdc.sbc.com. ..
      >when painting the background of a mdi app window
      >how can i resolve the flicker when it paints
      >from darker to lighter colors
      >>
      >below is the code i wrote
      >>
      >>
      > private void ShellWindow_Gra dient(object sender, PaintEventArgs e)
      > {
      >>
      >>
      >>
      > Graphics oGraphics = (Graphics)e.Gra phics;
      > //enum i Defined
      > if (this.StyleType == NetToolsUI.Wind owStyle.Solid)
      > {
      >>
      > this.oMdi.BackC olor = this.SolidColor ; //.RoyalBlue;
      >//.FromArgb(35,7, 143); //.Brushes.AliceB lue;
      >>
      > }
      > else if (this.StyleType == NetToolsUI.Wind owStyle.Gradien t)
      > {
      > Rectangle rect = oMdi.ClientRect angle;
      > rect.Inflate(2, 2);// to completely fill the client area
      >>
      > LinearGradientB rush filler = new LinearGradientB rush(
      > rect,
      > this.SolidColor ,
      > this.LightColor ,
      > 90,true); //this._angle);
      > oGraphics.FillR ectangle(filler , rect);
      >>
      >>
      > filler.Dispose( );
      > }
      > //Draw Some Text On the Window
      > // Create string to draw.
      > //e.MeasureString (drawString, this.Font);
      > // Create font and brush.
      > System.Drawing. SizeF TxtSize = oGraphics.Measu reString(Header ,
      >this.HeaderFon t);
      > SolidBrush GreyBrush = new SolidBrush(this .ShadowColor);
      > SolidBrush BlackBrush = new SolidBrush(this .HeaderColor);
      > // Create point for upper-left corner of drawing.
      > //x=widht
      > //y=height
      > //centers
      > //float x = (this.ClientSiz e.Width / 2) - (TxtSize.Width / 2);
      > //float y = (this.ClientSiz e.Height / 2) - (TxtSize.Height /
      >2);
      > float x = (oMdi.ClientSiz e.Width / 2) - (TxtSize.Width / 2);
      > float y = ((float)(oMdi.C lientSize.Heigh t
      >/this.HeaderLoca tion)) - (float)(TxtSize .Height/HeaderLocation );
      > // Set format of string.
      > StringFormat drawFormat = new StringFormat();
      > drawFormat.Form atFlags =
      >StringFormatFl ags.MeasureTrai lingSpaces;
      > //draw Shadow
      > oGraphics.DrawS tring(Header, this.HeaderFont , GreyBrush, x +
      >3, y + 3, drawFormat);
      > // Draw string to screen.
      >>
      > oGraphics.DrawS tring(Header, this.HeaderFont , BlackBrush, x,
      >y, drawFormat);
      > //draw Owner Notice bottom Right
      >>
      >>
      > BlackBrush = new SolidBrush(this .FooterColor);
      > TxtSize = oGraphics.Measu reString(Footer , this.FooterFont );
      >>
      > //text
      > oGraphics.DrawS tring(Footer, this.FooterFont , BlackBrush,
      >oMdi.ClientSiz e.Width - (TxtSize.Width+ 10),
      >>
      >oMdi.ClientSiz e.Height - (TxtSize.Height +10), drawFormat);
      >>
      >>
      > }
      >>
      >Thanks DaveL
      >>
      >>
      >
      >

      Comment

      Working...