
{filelink=15661}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
namespace Composant
{
public class ExempleGradientPanel : Form
{
private GradientPanel gradientPanel1;
private System.Windows.Forms.Label lbl2;
private System.Windows.Forms.Button btn;
private System.Windows.Forms.Label lbl3;
private System.Windows.Forms.Label lbl1;
public ExempleGradientPanel()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.gradientPanel1 = new Composant.GradientPanel();
this.lbl2 = new System.Windows.Forms.Label();
this.btn = new System.Windows.Forms.Button();
this.lbl3 = new System.Windows.Forms.Label();
this.lbl1 = new System.Windows.Forms.Label();
this.gradientPanel1.SuspendLayout();
this.SuspendLayout();
//
// gradientPanel1
//
this.gradientPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.gradientPanel1.AutoScroll = true;
this.gradientPanel1.Controls.Add(this.lbl2);
this.gradientPanel1.Controls.Add(this.btn);
this.gradientPanel1.Controls.Add(this.lbl3);
this.gradientPanel1.Controls.Add(this.lbl1);
this.gradientPanel1.Location = new System.Drawing.Point(-3, -2);
this.gradientPanel1.Name = "gradientPanel1";
this.gradientPanel1.Size = new System.Drawing.Size(438, 260);
this.gradientPanel1.TabIndex = 1;
//
// lbl2
//
this.lbl2.BackColor = System.Drawing.Color.Transparent;
this.lbl2.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbl2.ForeColor = System.Drawing.Color.White;
this.lbl2.Location = new System.Drawing.Point(144, 59);
this.lbl2.Name = "lbl2";
this.lbl2.Size = new System.Drawing.Size(100, 39);
this.lbl2.TabIndex = 2;
this.lbl2.Text = "text.";
//
// btn
//
this.btn.Location = new System.Drawing.Point(205, 205);
this.btn.Name = "btn";
this.btn.Size = new System.Drawing.Size(75, 23);
this.btn.TabIndex = 1;
this.btn.Text = "Test Bouton";
//
// lbl3
//
this.lbl3.AutoSize = true;
this.lbl3.BackColor = System.Drawing.Color.Transparent;
this.lbl3.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbl3.ForeColor = System.Drawing.Color.White;
this.lbl3.Location = new System.Drawing.Point(66, 194);
this.lbl3.Name = "lbl3";
this.lbl3.Size = new System.Drawing.Size(129, 37);
this.lbl3.TabIndex = 1;
this.lbl3.Text = "Label 2";
this.lbl3.Click += new System.EventHandler(this.label2_Click);
//
// lbl1
//
this.lbl1.AutoSize = true;
this.lbl1.BackColor = System.Drawing.Color.Transparent;
this.lbl1.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbl1.ForeColor = System.Drawing.Color.White;
this.lbl1.Location = new System.Drawing.Point(-7, 4);
this.lbl1.Name = "lbl1";
this.lbl1.Size = new System.Drawing.Size(415, 37);
this.lbl1.TabIndex = 0;
this.lbl1.Text = "Exemple Texte Trasparent";
//
// ExempleGradientPanel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(435, 260);
this.Controls.Add(this.gradientPanel1);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Name = "ExempleGradientPanel";
this.Text = "GradientPanel";
this.gradientPanel1.ResumeLayout(false);
this.gradientPanel1.PerformLayout();
this.ResumeLayout(false);
}
/*[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new ExempleGradientPanel());
}*/
private void label2_Click(object sender, EventArgs e)
{
}
}
public class GradientPanel : Panel
{
private Color couleur1 = Color.YellowGreen;
private Color couleur2 = Color.Red;
private LinearGradientMode GradientFillStyle = LinearGradientMode.ForwardDiagonal;
private Brush gradientBrush;
public GradientPanel()
{
handlerGradientChanged = new EventHandler(GradientChanged);
ResizeRedraw = true;
}
private EventHandler handlerGradientChanged;
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
{
gradientBrush = new LinearGradientBrush(ClientRectangle, couleur1, couleur2, GradientFillStyle);
e.Graphics.FillRectangle(gradientBrush, ClientRectangle);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (gradientBrush != null) gradientBrush.Dispose();
}
base.Dispose(disposing);
}
protected override void OnScroll(ScrollEventArgs se)
{
Invalidate();
}
private void GradientChanged(object sender, EventArgs e)
{
if (gradientBrush != null) gradientBrush.Dispose();
gradientBrush = null;
Invalidate();
}
}
}