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.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.