extends UserControl to create your own control : UserControl « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » UserControl 
23.88.1.extends UserControl to create your own control
using System.Drawing;
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

  public class PhoneControl : UserControl
  {    
    public String Phone 
    {      
      get 
      {
        return "("+areaCodeBox.Text+") "+phoneNoBox1.Text+"-" +phoneNoBox2.Text;
      }
    }
    private Label areaCodeLabel;
    private Label phoneNumberLabel;
    private TextBox phoneNoBox1;
    private TextBox phoneNoBox2;
    private TextBox areaCodeBox;
    private System.ComponentModel.Container components = null;

    public PhoneControl()
    {
      this.areaCodeLabel = new Label();
      this.areaCodeBox = new TextBox();
      this.phoneNoBox1 = new TextBox();
      this.phoneNumberLabel = new Label();
      this.phoneNoBox2 = new TextBox();
      this.SuspendLayout();
      // 
      this.areaCodeLabel.Location = new Point(816);
      this.areaCodeLabel.Name = "areaCodeLabel";
      this.areaCodeLabel.Size = new Size(7220);
      this.areaCodeLabel.TabIndex = 0;
      this.areaCodeLabel.Text = "Area Code";
      // 
      this.areaCodeBox.Location = new Point(9616);
      this.areaCodeBox.MaxLength = 3;
      this.areaCodeBox.Name = "areaCodeBox";
      this.areaCodeBox.Size = new Size(3220);
      this.areaCodeBox.TabIndex = 1;
      this.areaCodeBox.Text = "";
      // 
      this.phoneNoBox1.Location = new Point(9640);
      this.phoneNoBox1.MaxLength = 3;
      this.phoneNoBox1.Name = "phoneNoBox1";
      this.phoneNoBox1.Size = new Size(3220);
      this.phoneNoBox1.TabIndex = 2;
      this.phoneNoBox1.Text = "";
      // 
      this.phoneNumberLabel.Location = new Point(840);
      this.phoneNumberLabel.Name = "phoneNumberLabel";
      this.phoneNumberLabel.Size = new Size(8020);
      this.phoneNumberLabel.TabIndex = 2;
      this.phoneNumberLabel.Text = "Phone Number";
      // 
      this.phoneNoBox2.Location = new Point(14440);
      this.phoneNoBox2.MaxLength = 4;
      this.phoneNoBox2.Name = "phoneNoBox2";
      this.phoneNoBox2.Size = new Size(4020);
      this.phoneNoBox2.TabIndex = 3;
      this.phoneNoBox2.Text = "";
      // 
      this.Controls.Add(this.phoneNoBox2);
      this.Controls.Add(this.phoneNoBox1);
      this.Controls.Add(this.phoneNumberLabel);
      this.Controls.Add(this.areaCodeBox);
      this.Controls.Add(this.areaCodeLabel);
      this.Name = "PhoneControl";
      this.Size = new Size(20072);
      this.ResumeLayout(false);
    }
  }
  public class Form1 : Form
  {
    private Button ShowButton;
    private Label PhoneLabel;
    private PhoneControl phoneControl;
    private Label label1;
    private System.ComponentModel.Container components = null;
    public Form1()
    {
      this.phoneControl = new PhoneControl();
      this.ShowButton = new Button();
      this.PhoneLabel = new Label();
      this.label1 = new Label();
      this.SuspendLayout();
      // 
      this.phoneControl.Location = new Point(968);
      this.phoneControl.Name = "phoneControl";
      this.phoneControl.Size = new Size(20072);
      this.phoneControl.TabIndex = 0;
      // 
      // ShowButton
      // 
      this.ShowButton.Location = new Point(48112);
      this.ShowButton.Name = "ShowButton";
      this.ShowButton.Size = new Size(19224);
      this.ShowButton.TabIndex = 1;
      this.ShowButton.Text = "Show Phone No";
      this.ShowButton.Click += new System.EventHandler(this.ShowButton_Click);
      // 
      // PhoneLabel
      // 
      this.PhoneLabel.Location = new Point(8168);
      this.PhoneLabel.Name = "PhoneLabel";
      this.PhoneLabel.Size = new Size(27224);
      this.PhoneLabel.TabIndex = 2;
      this.PhoneLabel.TextAlign = ContentAlignment.MiddleCenter;
      // 
      // label1
      // 
      this.label1.Location = new Point(80);
      this.label1.Name = "label1";
      this.label1.Size = new Size(8080);
      this.label1.TabIndex = 3;
      this.label1.Text = "Phone No:";
      this.label1.TextAlign = ContentAlignment.MiddleCenter;
      // 
      // Form1
      // 
      this.AutoScaleBaseSize = new Size(513);
      this.ClientSize = new Size(292197);
      this.Controls.Add(this.label1);
      this.Controls.Add(this.PhoneLabel);
      this.Controls.Add(this.ShowButton);
      this.Controls.Add(this.phoneControl);
      this.Name = "Form1";
      this.Text = "Form1";
      this.ResumeLayout(false);

    }
    [STAThread]
    static void Main() 
    {
      Application.Run(new Form1());
    }
    private void ShowButton_Click(object sender, System.EventArgs e)
    {
      PhoneLabel.Text = phoneControl.Phone;
    }
  }
23.88.UserControl
23.88.1.extends UserControl to create your own 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.