/// <summary>
/// Inherits from Form and has additional features including the ability to center an image on the form at all times with transparency if you want. You can also paint the background with any brush you want.
/// </summary>
public class aForm : Form
{
Brush backgrdBrush=null;
Image backgrdImage=null;
int backgrdImageTransp=100;
bool controlsTransp=true;
bool controlsTranspInclBut=false;
/// <summary>
/// If some controls are not being colored right you may be able to figure out why.
/// </summary>
public string Errors="Check to see if the FormBorderStyle is set to 3D.\n\n";
/// <summary>
/// A brush to paint the background any color you want. Will always be behind the image.
/// </summary>
public Brush BackgrdBrush
{
get{return backgrdBrush;}
set{backgrdBrush=value; this.Invalidate();}
}
/// <summary>
/// Places an image in the center of the form keeping its proportions.
/// </summary>
public Image BackgrdIm
{
get{return backgrdImage;}
set{backgrdImage=value; this.Invalidate();}
}
/// <summary>
/// Sets the transparency percent to the backgrdImage. 0 is clear. If the image is not transparent at all the painting will draw faster: 100.
/// </summary>
public int BackgrdImTransp
{
get{return backgrdImageTransp;}
set{backgrdImageTransp=value; this.Invalidate();}
}
/// <summary>
/// Set to false if you want the controls on the form to take on the BackColor of the form.
/// </summary>
public bool ControlsTransp
{
get{return this.controlsTransp;}
set{this.controlsTransp=value; this.Invalidate();}
}
/// <summary>
/// You want your buttons to be transparent too.
/// </summary>
public bool ControlsTranspInclBut
{
get{return this.controlsTranspInclBut;}
set{this.controlsTranspInclBut=value; this.Invalidate();}
}
//------------------------
public aForm()
{
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.BackColor= a.Colors.aControl;
}
//------------------------
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
base.OnPaint(e);
if( (controlsTransp || controlsTranspInclBut) && (this.backgrdBrush != null || this.backgrdImage != null) )
{
if(controlsTranspInclBut)
{
foreach(Control c in this.Controls)
{
try
{
if(c is Label || c is GroupBox || c is Panel || c is LinkLabel || c is Button || c is CheckBox || c is RadioButton)
((Control)c).BackColor= Color.FromArgb(0,0,0,0);
/*else if(c is TabControl)
{
foreach(TabPage tp in ((TabControl)c).TabPages)
tp.BackColor= Color.FromArgb(0,0,0,0);
}*/
}
catch(Exception er) { this.Errors+= er+"\n\n"+c+"\n\n"; }
}
}
else
{
ArrayList buttonsList= new ArrayList(2);
ArrayList buttonsColorList= new ArrayList(2);
foreach(Control c in this.Controls)
{
try
{
if(c is Label || c is GroupBox || c is Panel || c is LinkLabel || c is CheckBox || c is RadioButton)
((Control)c).BackColor= Color.FromArgb(0,0,0,0);
else if(c is TabControl)
{
foreach(TabPage tp in ((TabControl)c).TabPages)
{
foreach(Control tc in tp.Controls)
{
if(tc is Button)
{
buttonsList.Add(tc);
buttonsColorList.Add(tc.BackColor);
}
}
tp.BackColor= Color.FromArgb(0,0,0,0);
for(int i=0; i<buttonsList.Count; i++)
{
((Button)buttonsList[i]).BackColor= ((Color)buttonsColorList[i]);
}
}
}
}
catch(Exception er) { this.Errors+= er+"\n\n"+c+"\n\n"; }
}
}
}
try
{
if(this.backgrdBrush != null)
{
//LinearGradientBrush LGB=new LinearGradientBrush(this.backgrdBrush.FillStartEndArea, this.backgrdBrush.Color1, this.backgrdBrush.Color2, this.backgrdBrush.Rotation);
e.Graphics.FillRectangle(this.backgrdBrush, this.ClientRectangle);
}
if(this.backgrdImage != null)
{
Size ImSize= a.graphics.ProportionalSize(backgrdImage.Size, new Size(this.ClientRectangle.Width, this.ClientRectangle.Height));
Rectangle centerR= a.graphics.CenterRect(this.ClientRectangle, ImSize);
if(this.backgrdImageTransp != 100)
{
ImageAttributes IA = a.graphics.TrasparentImage(backgrdImageTransp);
e.Graphics.DrawImage(backgrdImage, centerR, 0, 0, backgrdImage.Size.Width, backgrdImage.Size.Height, GraphicsUnit.Pixel, IA);
}
else
e.Graphics.DrawImage(backgrdImage, centerR, 0, 0, backgrdImage.Size.Width, backgrdImage.Size.Height, GraphicsUnit.Pixel);
//e.Graphics.DrawImageUnscaled(backgrdImage, 2, 2);
}
}
catch(Exception er) { this.Errors += er+"\n\n"; }
}
//-------------------
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if(this.backgrdBrush != null || this.backgrdImage != null)
this.Invalidate();
}
}