473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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_Gradient(object sender, PaintEventArgs e)
{

Graphics oGraphics = (Graphics)e.Graphics;
//enum i Defined
if (this.StyleType == NetToolsUI.WindowStyle.Solid)
{

this.oMdi.BackColor = this.SolidColor; //.RoyalBlue;
//.FromArgb(35,7,143); //.Brushes.AliceBlue;

}
else if (this.StyleType == NetToolsUI.WindowStyle.Gradient)
{
Rectangle rect = oMdi.ClientRectangle;
rect.Inflate(2, 2);// to completely fill the client area

LinearGradientBrush filler = new LinearGradientBrush(
rect,
this.SolidColor,
this.LightColor,
90,true); //this._angle);
oGraphics.FillRectangle(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.MeasureString(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.ClientSize.Width / 2) - (TxtSize.Width / 2);
//float y = (this.ClientSize.Height / 2) - (TxtSize.Height / 2);
float x = (oMdi.ClientSize.Width / 2) - (TxtSize.Width / 2);
float y = ((float)(oMdi.ClientSize.Height
/this.HeaderLocation)) - (float)(TxtSize.Height/HeaderLocation );
// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags =
StringFormatFlags.MeasureTrailingSpaces;
//draw Shadow
oGraphics.DrawString(Header, this.HeaderFont, GreyBrush, x + 3,
y + 3, drawFormat);
// Draw string to screen.

oGraphics.DrawString(Header, this.HeaderFont, BlackBrush, x, y,
drawFormat);
//draw Owner Notice bottom Right
BlackBrush = new SolidBrush(this.FooterColor);
TxtSize = oGraphics.MeasureString(Footer, this.FooterFont);

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

Thanks DaveL
Nov 6 '08 #1
2 2064
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]
- mv*@spam.guard.caspershouse.com

"DaveL" <dv*****@sbcglobal.netwrote in message
news:7L****************@flpi144.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_Gradient(object sender, PaintEventArgs e)
{

Graphics oGraphics = (Graphics)e.Graphics;
//enum i Defined
if (this.StyleType == NetToolsUI.WindowStyle.Solid)
{

this.oMdi.BackColor = this.SolidColor; //.RoyalBlue;
//.FromArgb(35,7,143); //.Brushes.AliceBlue;

}
else if (this.StyleType == NetToolsUI.WindowStyle.Gradient)
{
Rectangle rect = oMdi.ClientRectangle;
rect.Inflate(2, 2);// to completely fill the client area

LinearGradientBrush filler = new LinearGradientBrush(
rect,
this.SolidColor,
this.LightColor,
90,true); //this._angle);
oGraphics.FillRectangle(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.MeasureString(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.ClientSize.Width / 2) - (TxtSize.Width / 2);
//float y = (this.ClientSize.Height / 2) - (TxtSize.Height /
2);
float x = (oMdi.ClientSize.Width / 2) - (TxtSize.Width / 2);
float y = ((float)(oMdi.ClientSize.Height
/this.HeaderLocation)) - (float)(TxtSize.Height/HeaderLocation );
// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags =
StringFormatFlags.MeasureTrailingSpaces;
//draw Shadow
oGraphics.DrawString(Header, this.HeaderFont, GreyBrush, x + 3,
y + 3, drawFormat);
// Draw string to screen.

oGraphics.DrawString(Header, this.HeaderFont, BlackBrush, x, y,
drawFormat);
//draw Owner Notice bottom Right
BlackBrush = new SolidBrush(this.FooterColor);
TxtSize = oGraphics.MeasureString(Footer, this.FooterFont);

//text
oGraphics.DrawString(Footer, this.FooterFont, BlackBrush,
oMdi.ClientSize.Width - (TxtSize.Width+10),

oMdi.ClientSize.Height - (TxtSize.Height+10), drawFormat);
}

Thanks DaveL


Nov 6 '08 #2
Thanks alot....will clean it up better

DaveL

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:%2****************@TK2MSFTNGP06.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]
- mv*@spam.guard.caspershouse.com

"DaveL" <dv*****@sbcglobal.netwrote in message
news:7L****************@flpi144.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_Gradient(object sender, PaintEventArgs e)
{

Graphics oGraphics = (Graphics)e.Graphics;
//enum i Defined
if (this.StyleType == NetToolsUI.WindowStyle.Solid)
{

this.oMdi.BackColor = this.SolidColor; //.RoyalBlue;
//.FromArgb(35,7,143); //.Brushes.AliceBlue;

}
else if (this.StyleType == NetToolsUI.WindowStyle.Gradient)
{
Rectangle rect = oMdi.ClientRectangle;
rect.Inflate(2, 2);// to completely fill the client area

LinearGradientBrush filler = new LinearGradientBrush(
rect,
this.SolidColor,
this.LightColor,
90,true); //this._angle);
oGraphics.FillRectangle(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.MeasureString(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.ClientSize.Width / 2) - (TxtSize.Width / 2);
//float y = (this.ClientSize.Height / 2) - (TxtSize.Height /
2);
float x = (oMdi.ClientSize.Width / 2) - (TxtSize.Width / 2);
float y = ((float)(oMdi.ClientSize.Height
/this.HeaderLocation)) - (float)(TxtSize.Height/HeaderLocation );
// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags =
StringFormatFlags.MeasureTrailingSpaces;
//draw Shadow
oGraphics.DrawString(Header, this.HeaderFont, GreyBrush, x +
3, y + 3, drawFormat);
// Draw string to screen.

oGraphics.DrawString(Header, this.HeaderFont, BlackBrush, x,
y, drawFormat);
//draw Owner Notice bottom Right
BlackBrush = new SolidBrush(this.FooterColor);
TxtSize = oGraphics.MeasureString(Footer, this.FooterFont);

//text
oGraphics.DrawString(Footer, this.FooterFont, BlackBrush,
oMdi.ClientSize.Width - (TxtSize.Width+10),

oMdi.ClientSize.Height - (TxtSize.Height+10), drawFormat);
}

Thanks DaveL



Nov 6 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Max M | last post by:
If anybody is interrested in Midi, but are not on the Python Midi list, I will just notify that I have released the first version of a high level midi package for Python. It is fully functional....
2
by: Mad Scientist Jr | last post by:
any sample code or information would be most appreciated i have been wanting to learn MIDI programming but would rather learn it in my current language (either vb.net or c#)
11
by: Kuba Araszkiewicz | last post by:
Hello! I have to write a program, which would convert midi files to notes, notes to midi files and which would make one MIDI file from two different. I'm totally lame in C (and any other...
0
by: tom | last post by:
Hallo, I need help on MIDI file, and precisely about retrieving few note values (mainly the "Velocity" value, corrisponding to the intensity of a played note) while the MIDI is playing.
1
by: tim | last post by:
Someone using Python Midi Package from http://www.mxm.dk/products/public/ lately? I want to do the following : write some note events in a midi file then after doing that, put some controllers...
4
by: sreekant | last post by:
Hi folks I hope someone here might be able to help. I scavenged some info and even code from the net and am trying to write a module that reads a text file and spits out a midi file. So far I...
9
by: outstretchedarm | last post by:
How exactly does HTML/Javascript handle playing midi files? Does it have a player imbedded in it? Or does it borrow from the computer's midi player? How could you make a webpage play certain...
6
by: Massi | last post by:
Hi everyone, I'm searching for "something" which allows me to write scripts which handle midi files. I'm totally a newbie in audio manipulation, therefore any suggestion or link related to this...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.