. NET component Programming (1) Basics

Source: Internet
Author: User
Tags datetime

Introduction to my work, the company is mainly the development of Third-party components (Component), Controls (control), I see the Friends in the garden to write this is not a lot (perhaps I did not see), so I intend to write a series on the development of components of the article.

First introduce the basic knowledge, a lot of friends do not know the difference between component and control, relatively simple image of the difference has the following two points:

1. Component cannot render the UI while run time, while control can render the UI at run time (but the SqlDataSource in ASP.net in vs 2005 is control, but it cannot render the UI).

2, component is affixed to the container container, and control is affixed to the Windows Form or Web form.

SqlCommand, for example, is a component,datagrid and a control.

So how do we develop a component? It's really simple, as long as we inherit a class from System.ComponentModel.Component (abbreviated Component below)

Let's write a simple component, open vs 2005 Add a new ClassLibrary project, name components, change CLASS1 code as follows:

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Components
{
    public class Component1 : Component
    {
        private int _id;
        private string _name;
        private DateTime _createDateTime;

    // 在Property窗口中为灰色显示。
        public int Id
        {
            get { return _id; }
        }

    // 在Property窗口中可以设置值。
        public string name
        {
            get { return _name; }
            set { _name = value; }
        }

    // 在Property窗口中不可见。
        public DateTime CreateDateTime
        {
            set { _createDateTime = value; }
        }
    }
}

When the compilation is complete, its property effects are as follows:

Note that the ID is gray and cannot be set to a value, and Createdatetime is not displayed in the property window.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.