Gradient Label : Gradient « 2D Graphics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » 2D Graphics » GradientScreenshots 
Gradient Label
Gradient Label


/*
Code revised from chapter 3


GDI+ Custom Controls with Visual C# 2005
By Iulian Serban, Dragos Brezoi, Tiberiu Radu, Adam Ward 

Language English
Paperback 272 pages [191mm x 235mm]
Release date July 2006
ISBN 1904811604

Sample chapter
http://www.packtpub.com/files/1604_CustomControls_SampleChapter.pdf


For More info on GDI+ Custom Control with Microsoft Visual C# book 
visit website www.packtpub.com 


*/ 

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;

namespace GradientLabelTest00
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        private void InitializeComponent()
        {
            this.gradientLabel1 = new GradientLabelTest00.GradientLabel();
            this.SuspendLayout();

            this.gradientLabel1.BackColor = System.Drawing.SystemColors.ControlLight;
            this.gradientLabel1.BackColor2 = System.Drawing.SystemColors.ControlDarkDark;
            this.gradientLabel1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
            this.gradientLabel1.Location = new System.Drawing.Point(6668);
            this.gradientLabel1.Name = "gradientLabel1";
            this.gradientLabel1.Size = new System.Drawing.Size(15047);
            this.gradientLabel1.TabIndex = 0;
            this.gradientLabel1.Text = "Gradient Label";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292266);
            this.Controls.Add(this.gradientLabel1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

        #endregion

        private GradientLabel gradientLabel1;        
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

    }
    public partial class GradientLabel : Control
    {
        private Color backColor2 = SystemColors.ControlLight;
        public GradientLabel()
        {
            InitializeComponent();
        }
        public Color BackColor2
        {
            get
            {
                return backColor2;
            }
            set
            {
                if (backColor2 != value)
                {
                    backColor2 = value;
                    Invalidate();
                }
            }
        }

        private void GradientLabel_Paint(object sender, PaintEventArgs e)
        {
        }
        protected override void OnPaint(PaintEventArgs e)
        {
                base.OnPaint(e);
                LinearGradientBrush brush = new LinearGradientBrush(new Point(00)new Point(0, Height), BackColor, BackColor2);
                e.Graphics.FillRectangle(brush, ClientRectangle);
                Brush foreBrush = new SolidBrush(ForeColor);
                SizeF textSize = e.Graphics.MeasureString(Text, Font);
                e.Graphics.DrawString(Text, Font, foreBrush, (Width - textSize.Width2(Height - textSize.Height2);
                brush.Dispose();
                foreBrush.Dispose();
        }

        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
        #region Component Designer generated code

        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.BackColor = System.Drawing.SystemColors.ControlDarkDark;
            this.ForeColor = System.Drawing.SystemColors.HotTrack;
            this.Size = new System.Drawing.Size(15024);
            this.Text = "Gradient Label";
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.GradientLabel_Paint);
            this.ResumeLayout(false);
        }
        #endregion        
    }
}
           
       
Related examples in the same category
1.Path Gradient DemoPath Gradient Demo
2.All Linear Gradient ModeAll Linear Gradient Mode
3.Simple way to create linear gradient brushSimple way to create linear gradient brush
4.Path Gradient Brush from Graphics PathPath Gradient Brush from Graphics Path
5.Use LinearGradientBrush to draw a RectangleUse LinearGradientBrush to draw a Rectangle
6.Gradient ButtonGradient Button
7.Gradient BrushesGradient Brushes
8.Gradient DemoGradient  Demo
9.Gradient WrapGradient Wrap
10.Gradient Label HostGradient Label Host
11.Line GradientLine Gradient
12.Path GradientPath Gradient
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.