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
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