subclass System.Windows.Forms.UserControl to create custom 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 
subclass System.Windows.Forms.UserControl to create custom control
 


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

public class UserControl1 : System.Windows.Forms.UserControl {
    private System.ComponentModel.Container components = null;

    public UserControl1() {
        this.Name = "UserControl1";
        this.Paint += new
         System.Windows.Forms.PaintEventHandler(this.OnPaint);

    }


    private void OnPaint(object sender,
         System.Windows.Forms.PaintEventArgs e) {
        e.Graphics.DrawString("Hello world", Font,
           new SolidBrush(Color.Blue), ClientRectangle);
    }
}
public class Form1 : System.Windows.Forms.Form {
    private System.ComponentModel.Container components = null;
    private System.Windows.Forms.Label label1;
    private UserControl1 control1;

    public Form1() {
        this.control1 = new UserControl1();
        this.label1 = new System.Windows.Forms.Label();
        this.SuspendLayout();
        this.control1.Location = new System.Drawing.Point(3248);
        this.control1.Size = new System.Drawing.Size(8024);
        this.label1.Location = new System.Drawing.Point(3224);
        this.label1.Size = new System.Drawing.Size(14424);
        this.label1.Text = "Custom Control:";
        this.AutoScaleBaseSize = new System.Drawing.Size(513);
        this.ClientSize = new System.Drawing.Size(292273);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {
        this.label1,
        this.control1});
        this.ResumeLayout(false);
    }

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

 
Related examples in the same category
1.Draw a Custom Control
2.Define user controlDefine user 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.