摘自:http://www.cnblogs.com/greatverve/archive/2012/04/25/user-control-inherit.html
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinFormControlLibrary
{
public partial class UcButton : Button
{
public UcButton()
{
InitializeComponent();
}
// Creates the private variable that will store the value of your
// property.
private int varValue;
// Declares the property.
public int ButtonValue
{
// Sets the method for retrieving the value of your property.
get
{
return varValue;
}
// Sets the method for setting the value of your property.
set
{
varValue = value;
}
}
}
}
namespace WinFormControlLibrary
{
partial class UcButton
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
//把这句注释掉
//this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinFormControlLibrary
{
public partial class UcLabel : Label
{
public UcLabel()
{
InitializeComponent();
}
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
this.Font = new Font("宋体", 10F, FontStyle.Underline);
}
protected override void OnMouseLeave(System.EventArgs e)
{
base.OnMouseLeave(e);
this.Font = new Font("宋体", 10F, FontStyle.Regular);
}
}
}