Define user control : User Control « GUI Windows Form « 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 » GUI Windows Form » User ControlScreenshots 
Define user control
Define user control

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{

    private ClockUserControl clockUserControl1;

  public Form1() {
        InitializeComponent();
  }


      private void InitializeComponent()
      {
         this.clockUserControl1 = new ClockUserControl();
         this.SuspendLayout();
         // 
         // clockUserControl1
         // 
         this.clockUserControl1.Location = new System.Drawing.Point(1212);
         this.clockUserControl1.Name = "clockUserControl1";
         this.clockUserControl1.Size = new System.Drawing.Size(15474);
         this.clockUserControl1.TabIndex = 0;
         // 
         // Clock
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(17899);
         this.Controls.Add(this.clockUserControl1);
         this.Name = "Clock";
         this.Text = "Clock";
         this.ResumeLayout(false);

      }
  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}


public class ClockUserControl : UserControl
{
      private System.Windows.Forms.Label displayLabel;
      private System.Windows.Forms.Timer clockTimer;
      
      public ClockUserControl() {
         InitializeComponent();
      }  

      private void clockTimer_Tick(object sender, EventArgs e) {
         displayLabel.Text = DateTime.Now.ToLongTimeString();
      }
      private void InitializeComponent()
      {
         this.displayLabel = new System.Windows.Forms.Label();
         this.clockTimer = new System.Windows.Forms.Timernew System.ComponentModel.Container() );
         this.SuspendLayout();
         // 
         // displayLabel
         // 
         this.displayLabel.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
         this.displayLabel.Font = new System.Drawing.Font"Microsoft Sans Serif"12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte ) ( ) ) );
         this.displayLabel.Location = new System.Drawing.Point410 );
         this.displayLabel.Name = "displayLabel";
         this.displayLabel.Size = new System.Drawing.Size14352 );
         this.displayLabel.TabIndex = 0;
         this.displayLabel.Text = "12:55:55 AM";
         this.displayLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
         // 
         // clockTimer
         // 
         this.clockTimer.Enabled = true;
         this.clockTimer.Interval = 1000;
         this.clockTimer.Tick += new System.EventHandlerthis.clockTimer_Tick );
         // 
         // ClockUserControl
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF6F13F );
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.BackColor = System.Drawing.Color.White;
         this.Controls.Addthis.displayLabel );
         this.Name = "ClockUserControl";
         this.Size = new System.Drawing.Size15072 );
         this.ResumeLayoutfalse );

      }

}


           
       
Related examples in the same category
1.subclass System.Windows.Forms.UserControl to create custom control
2.Draw a Custom Control
3.Creating an event for a component.
4.The read-only property control.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.