UserControl 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供一个可用来创建其他控件的空控件。
public ref class UserControl : System::Windows::Forms::ContainerControl
public class UserControl : System.Windows.Forms.ContainerControl
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
public class UserControl : System.Windows.Forms.ContainerControl
type UserControl = class
inherit ContainerControl
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type UserControl = class
inherit ContainerControl
Public Class UserControl
Inherits ContainerControl
- 继承
- 派生
- 属性
示例
下面的代码示例创建 UserControl 可在多个应用程序中重复使用以获取用户信息的 。 此示例将多个 Label 控件、 TextBox 控件和 添加到 ErrorProvider , UserControl 以收集用户的信息。 此外,在 发生 时TextBox验证用户的电子邮件地址Validating,并在ErrorProvider数据验证失败时使用 对象向用户提供反馈。 代码旨在编译为 DLL,以便在其他应用程序中引用。
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::ComponentModel;
namespace UserControls
{
public ref class MyCustomerInfoUserControl: public System::Windows::Forms::UserControl
{
private:
// Create the controls.
System::Windows::Forms::ErrorProvider^ errorProvider1;
System::Windows::Forms::TextBox^ textName;
System::Windows::Forms::TextBox^ textAddress;
System::Windows::Forms::TextBox^ textCity;
System::Windows::Forms::TextBox^ textStateProvince;
System::Windows::Forms::TextBox^ textPostal;
System::Windows::Forms::TextBox^ textCountryRegion;
System::Windows::Forms::TextBox^ textEmail;
System::Windows::Forms::Label ^ labelName;
System::Windows::Forms::Label ^ labelAddress;
System::Windows::Forms::Label ^ labelCityStateProvincePostal;
System::Windows::Forms::Label ^ labelCountryRegion;
System::Windows::Forms::Label ^ labelEmail;
System::ComponentModel::IContainer^ components;
public:
// Define the constructor.
MyCustomerInfoUserControl()
{
InitializeComponent();
}
// Initialize the control elements.
void InitializeComponent()
{
// Initialize the controls.
components = gcnew System::ComponentModel::Container;
errorProvider1 = gcnew System::Windows::Forms::ErrorProvider;
textName = gcnew System::Windows::Forms::TextBox;
textAddress = gcnew System::Windows::Forms::TextBox;
textCity = gcnew System::Windows::Forms::TextBox;
textStateProvince = gcnew System::Windows::Forms::TextBox;
textPostal = gcnew System::Windows::Forms::TextBox;
textCountryRegion = gcnew System::Windows::Forms::TextBox;
textEmail = gcnew System::Windows::Forms::TextBox;
labelName = gcnew System::Windows::Forms::Label;
labelAddress = gcnew System::Windows::Forms::Label;
labelCityStateProvincePostal = gcnew System::Windows::Forms::Label;
labelCountryRegion = gcnew System::Windows::Forms::Label;
labelEmail = gcnew System::Windows::Forms::Label;
// Set the tab order, text alignment, size, and location of the controls.
textName->Location = System::Drawing::Point( 120, 8 );
textName->Size = System::Drawing::Size( 232, 20 );
textName->TabIndex = 0;
textAddress->Location = System::Drawing::Point( 120, 32 );
textAddress->Size = System::Drawing::Size( 232, 20 );
textAddress->TabIndex = 1;
textCity->Location = System::Drawing::Point( 120, 56 );
textCity->Size = System::Drawing::Size( 96, 20 );
textCity->TabIndex = 2;
textStateProvince->Location = System::Drawing::Point( 216, 56 );
textStateProvince->Size = System::Drawing::Size( 56, 20 );
textStateProvince->TabIndex = 3;
textPostal->Location = System::Drawing::Point( 272, 56 );
textPostal->Size = System::Drawing::Size( 80, 20 );
textPostal->TabIndex = 4;
textCountryRegion->Location = System::Drawing::Point( 120, 80 );
textCountryRegion->Size = System::Drawing::Size( 232, 20 );
textCountryRegion->TabIndex = 5;
textEmail->Location = System::Drawing::Point( 120, 104 );
textEmail->Size = System::Drawing::Size( 232, 20 );
textEmail->TabIndex = 6;
labelName->Location = System::Drawing::Point( 8, 8 );
labelName->Size = System::Drawing::Size( 112, 23 );
labelName->Text = "Name:";
labelName->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
labelAddress->Location = System::Drawing::Point( 8, 32 );
labelAddress->Size = System::Drawing::Size( 112, 23 );
labelAddress->Text = "Address:";
labelAddress->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
labelCityStateProvincePostal->Location = System::Drawing::Point( 8, 56 );
labelCityStateProvincePostal->Size = System::Drawing::Size( 112, 23 );
labelCityStateProvincePostal->Text = "City, St/Prov. Postal:";
labelCityStateProvincePostal->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
labelCountryRegion->Location = System::Drawing::Point( 8, 80 );
labelCountryRegion->Size = System::Drawing::Size( 112, 23 );
labelCountryRegion->Text = "Country/Region:";
labelCountryRegion->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
labelEmail->Location = System::Drawing::Point( 8, 104 );
labelEmail->Size = System::Drawing::Size( 112, 23 );
labelEmail->Text = "email:";
labelEmail->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
// Add the Validating and Validated handlers for textEmail.
textEmail->Validating += gcnew System::ComponentModel::CancelEventHandler( this, &MyCustomerInfoUserControl::textEmail_Validating );
textEmail->Validated += gcnew System::EventHandler( this, &MyCustomerInfoUserControl::textEmail_Validated );
// Add the controls to the user control.
array<System::Windows::Forms::Control^>^temp0 = {labelName,labelAddress,labelCityStateProvincePostal,labelCountryRegion,labelEmail,textName,textAddress,textCity,textStateProvince,textPostal,textCountryRegion,textEmail};
Controls->AddRange( temp0 );
// Size the user control.
Size = System::Drawing::Size( 375, 150 );
}
private:
void MyValidatingCode()
{
// Confirm there is text in the control.
if ( textEmail->Text->Length == 0 )
{
throw gcnew Exception( "Email address is a required field." );
}
// Confirm that there is a "." and an "@" in the email address.
else
// Confirm that there is a "." and an "@" in the email address.
if ( textEmail->Text->IndexOf( "." ) == -1 || textEmail->Text->IndexOf( "@" ) == -1 )
{
throw gcnew Exception( "Email address must be valid email address format.\nFor example: 'someone@example.com'" );
}
}
// Validate the data input by the user into textEmail.
void textEmail_Validating( Object^ /*sender*/, System::ComponentModel::CancelEventArgs^ e )
{
try
{
MyValidatingCode();
}
catch ( Exception^ ex )
{
// Cancel the event and select the text to be corrected by the user.
e->Cancel = true;
textEmail->Select(0,textEmail->Text->Length);
// Set the ErrorProvider error with the text to display.
this->errorProvider1->SetError( textEmail, ex->Message );
}
}
void textEmail_Validated( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
//If all conditions have been met, clear the error provider of errors.
errorProvider1->SetError( textEmail, "" );
}
};
}
// End Class
// End Namespace
using System;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
namespace UserControls
{
public class MyCustomerInfoUserControl : System.Windows.Forms.UserControl
{
// Create the controls.
private System.Windows.Forms.ErrorProvider errorProvider1;
private System.Windows.Forms.TextBox textName;
private System.Windows.Forms.TextBox textAddress;
private System.Windows.Forms.TextBox textCity;
private System.Windows.Forms.TextBox textStateProvince;
private System.Windows.Forms.TextBox textPostal;
private System.Windows.Forms.TextBox textCountryRegion;
private System.Windows.Forms.TextBox textEmail;
private System.Windows.Forms.Label labelName;
private System.Windows.Forms.Label labelAddress;
private System.Windows.Forms.Label labelCityStateProvincePostal;
private System.Windows.Forms.Label labelCountryRegion;
private System.Windows.Forms.Label labelEmail;
private System.ComponentModel.IContainer components;
// Define the constructor.
public MyCustomerInfoUserControl()
{
InitializeComponent();
}
// Initialize the control elements.
public void InitializeComponent()
{
// Initialize the controls.
components = new System.ComponentModel.Container();
errorProvider1 = new System.Windows.Forms.ErrorProvider();
textName = new System.Windows.Forms.TextBox();
textAddress = new System.Windows.Forms.TextBox();
textCity = new System.Windows.Forms.TextBox();
textStateProvince = new System.Windows.Forms.TextBox();
textPostal = new System.Windows.Forms.TextBox();
textCountryRegion = new System.Windows.Forms.TextBox();
textEmail = new System.Windows.Forms.TextBox();
labelName = new System.Windows.Forms.Label();
labelAddress = new System.Windows.Forms.Label();
labelCityStateProvincePostal = new System.Windows.Forms.Label();
labelCountryRegion = new System.Windows.Forms.Label();
labelEmail = new System.Windows.Forms.Label();
// Set the tab order, text alignment, size, and location of the controls.
textName.Location = new System.Drawing.Point(120, 8);
textName.Size = new System.Drawing.Size(232, 20);
textName.TabIndex = 0;
textAddress.Location = new System.Drawing.Point(120, 32);
textAddress.Size = new System.Drawing.Size(232, 20);
textAddress.TabIndex = 1;
textCity.Location = new System.Drawing.Point(120, 56);
textCity.Size = new System.Drawing.Size(96, 20);
textCity.TabIndex = 2;
textStateProvince.Location = new System.Drawing.Point(216, 56);
textStateProvince.Size = new System.Drawing.Size(56, 20);
textStateProvince.TabIndex = 3;
textPostal.Location = new System.Drawing.Point(272, 56);
textPostal.Size = new System.Drawing.Size(80, 20);
textPostal.TabIndex = 4;
textCountryRegion.Location = new System.Drawing.Point(120, 80);
textCountryRegion.Size = new System.Drawing.Size(232, 20);
textCountryRegion.TabIndex = 5;
textEmail.Location = new System.Drawing.Point(120, 104);
textEmail.Size = new System.Drawing.Size(232, 20);
textEmail.TabIndex = 6;
labelName.Location = new System.Drawing.Point(8, 8);
labelName.Size = new System.Drawing.Size(112, 23);
labelName.Text = "Name:";
labelName.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
labelAddress.Location = new System.Drawing.Point(8, 32);
labelAddress.Size = new System.Drawing.Size(112, 23);
labelAddress.Text = "Address:";
labelAddress.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
labelCityStateProvincePostal.Location = new System.Drawing.Point(8, 56);
labelCityStateProvincePostal.Size = new System.Drawing.Size(112, 23);
labelCityStateProvincePostal.Text = "City, St/Prov. Postal:";
labelCityStateProvincePostal.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
labelCountryRegion.Location = new System.Drawing.Point(8, 80);
labelCountryRegion.Size = new System.Drawing.Size(112, 23);
labelCountryRegion.Text = "Country/Region:";
labelCountryRegion.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
labelEmail.Location = new System.Drawing.Point(8, 104);
labelEmail.Size = new System.Drawing.Size(112, 23);
labelEmail.Text = "email:";
labelEmail.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// Add the Validating and Validated handlers for textEmail.
textEmail.Validating += new System.ComponentModel.CancelEventHandler(textEmail_Validating);
textEmail.Validated += new System.EventHandler(textEmail_Validated);
// Add the controls to the user control.
Controls.AddRange(new System.Windows.Forms.Control[]
{
labelName,
labelAddress,
labelCityStateProvincePostal,
labelCountryRegion,
labelEmail,
textName,
textAddress,
textCity,
textStateProvince,
textPostal,
textCountryRegion,
textEmail
});
// Size the user control.
Size = new System.Drawing.Size(375, 150);
}
private void MyValidatingCode()
{
// Confirm there is text in the control.
if (textEmail.Text.Length == 0)
{
throw new Exception("Email address is a required field.");
}
// Confirm that there is a "." and an "@" in the email address.
else if(textEmail.Text.IndexOf(".") == -1 || textEmail.Text.IndexOf("@") == -1)
{
throw new Exception("Email address must be valid email address format." +
"\nFor example: 'someone@example.com'");
}
}
// Validate the data input by the user into textEmail.
private void textEmail_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
MyValidatingCode();
}
catch(Exception ex)
{
// Cancel the event and select the text to be corrected by the user.
e.Cancel = true;
textEmail.Select(0, textEmail.Text.Length);
// Set the ErrorProvider error with the text to display.
this.errorProvider1.SetError(textEmail,ex.Message);
}
}
private void textEmail_Validated(Object sender, System.EventArgs e)
{
//If all conditions have been met, clear the error provider of errors.
errorProvider1.SetError(textEmail, "");
}
} // End Class
} // End Namespace
Imports System.Windows.Forms
Imports System.Drawing
Imports System.ComponentModel
Namespace UserControls
Public Class MyCustomerInfoUserControl
Inherits System.Windows.Forms.UserControl
' Create the controls.
Private errorProvider1 As System.Windows.Forms.ErrorProvider
Private textName As System.Windows.Forms.TextBox
Private textAddress As System.Windows.Forms.TextBox
Private textCity As System.Windows.Forms.TextBox
Private textStateProvince As System.Windows.Forms.TextBox
Private textPostal As System.Windows.Forms.TextBox
Private textCountryRegion As System.Windows.Forms.TextBox
Private WithEvents textEmail As System.Windows.Forms.TextBox
Private labelName As System.Windows.Forms.Label
Private labelAddress As System.Windows.Forms.Label
Private labelCityStateProvincePostal As System.Windows.Forms.Label
Private labelCountryRegion As System.Windows.Forms.Label
Private labelEmail As System.Windows.Forms.Label
Private components As System.ComponentModel.IContainer
' Define the constructor.
Public Sub New()
InitializeComponent()
End Sub
' Initialize the control elements.
Public Sub InitializeComponent()
' Initialize the controls.
components = New System.ComponentModel.Container()
errorProvider1 = New System.Windows.Forms.ErrorProvider()
textName = New System.Windows.Forms.TextBox()
textAddress = New System.Windows.Forms.TextBox()
textCity = New System.Windows.Forms.TextBox()
textStateProvince = New System.Windows.Forms.TextBox()
textPostal = New System.Windows.Forms.TextBox()
textCountryRegion = New System.Windows.Forms.TextBox()
textEmail = New System.Windows.Forms.TextBox()
labelName = New System.Windows.Forms.Label()
labelAddress = New System.Windows.Forms.Label()
labelCityStateProvincePostal = New System.Windows.Forms.Label()
labelCountryRegion = New System.Windows.Forms.Label()
labelEmail = New System.Windows.Forms.Label()
' Set the tab order, text alignment, size, and location of the controls.
textName.Location = New System.Drawing.Point(120, 8)
textName.Size = New System.Drawing.Size(232, 20)
textName.TabIndex = 0
textAddress.Location = New System.Drawing.Point(120, 32)
textAddress.Size = New System.Drawing.Size(232, 20)
textAddress.TabIndex = 1
textCity.Location = New System.Drawing.Point(120, 56)
textCity.Size = New System.Drawing.Size(96, 20)
textCity.TabIndex = 2
textStateProvince.Location = New System.Drawing.Point(216, 56)
textStateProvince.Size = New System.Drawing.Size(56, 20)
textStateProvince.TabIndex = 3
textPostal.Location = New System.Drawing.Point(272, 56)
textPostal.Size = New System.Drawing.Size(80, 20)
textPostal.TabIndex = 4
textCountryRegion.Location = New System.Drawing.Point(120, 80)
textCountryRegion.Size = New System.Drawing.Size(232, 20)
textCountryRegion.TabIndex = 5
textEmail.Location = New System.Drawing.Point(120, 104)
textEmail.Size = New System.Drawing.Size(232, 20)
textEmail.TabIndex = 6
labelName.Location = New System.Drawing.Point(8, 8)
labelName.Size = New System.Drawing.Size(112, 23)
labelName.Text = "Name:"
labelName.TextAlign = System.Drawing.ContentAlignment.MiddleRight
labelAddress.Location = New System.Drawing.Point(8, 32)
labelAddress.Size = New System.Drawing.Size(112, 23)
labelAddress.Text = "Address:"
labelAddress.TextAlign = System.Drawing.ContentAlignment.MiddleRight
labelCityStateProvincePostal.Location = New System.Drawing.Point(8, 56)
labelCityStateProvincePostal.Size = New System.Drawing.Size(112, 23)
labelCityStateProvincePostal.Text = "City, St/Prov. Postal:"
labelCityStateProvincePostal.TextAlign = System.Drawing.ContentAlignment.MiddleRight
labelCountryRegion.Location = New System.Drawing.Point(8, 80)
labelCountryRegion.Size = New System.Drawing.Size(112, 23)
labelCountryRegion.Text = "Country/Region:"
labelCountryRegion.TextAlign = System.Drawing.ContentAlignment.MiddleRight
labelEmail.Location = New System.Drawing.Point(8, 104)
labelEmail.Size = New System.Drawing.Size(112, 23)
labelEmail.Text = "email:"
labelEmail.TextAlign = System.Drawing.ContentAlignment.MiddleRight
' Add the controls to the user control.
Controls.AddRange(New System.Windows.Forms.Control() {labelName, _
labelAddress, labelCityStateProvincePostal, labelCountryRegion, _
labelEmail, textName, textAddress, textCity, textStateProvince, _
textPostal, textCountryRegion, textEmail})
' Size the user control.
Size = New System.Drawing.Size(375, 150)
End Sub
Private Sub MyValidatingCode()
' Confirm there is text in the control.
If textEmail.Text.Length = 0 Then
Throw New Exception("Email address is a required field")
Else
' Confirm that there is a "." and an "@" in the email address.
If textEmail.Text.IndexOf(".") = - 1 Or textEmail.Text.IndexOf("@") = - 1 Then
Throw New Exception("Email address must be valid email address format." + _
Microsoft.VisualBasic.ControlChars.Cr + "For example 'someone@example.com'")
End If
End If
End Sub
' Validate the data input by the user into textEmail.
Private Sub textEmail_Validating(sender As Object, _
e As System.ComponentModel.CancelEventArgs) Handles textEmail.Validating
Try
MyValidatingCode()
Catch ex As Exception
' Cancel the event and select the text to be corrected by the user.
e.Cancel = True
textEmail.Select(0, textEmail.Text.Length)
' Set the ErrorProvider error with the text to display.
Me.errorProvider1.SetError(textEmail, ex.Message)
End Try
End Sub
Private Sub textEmail_Validated(sender As Object, _
e As System.EventArgs) Handles textEmail.Validated
' If all conditions have been met, clear the error provider of errors.
errorProvider1.SetError(textEmail, "")
End Sub
End Class
End Namespace
注解
通过扩展 ContainerControl, UserControl 继承用户控件中所需的所有标准定位和助记键处理代码。
UserControl使你能够创建可在应用程序或组织中的多个位置使用的控件。 可以包含验证要求用户输入的常见数据所需的所有代码;例如电子邮件地址 (请参阅示例部分) 、电话号码和邮政编码。 用户控件的另一个有效用途是,只需将 或 ListBox 与几乎每个应用程序中常用的静态项目一起预加载ComboBox;其中一些示例包括国家/地区、城市、州和办公地点。 有关创作自定义控件的详细信息,请参阅使用.NET Framework开发自定义Windows 窗体控件。
注意
可以考虑创建包含多个用户控件类的命名空间,并将其编译为一个 DLL。 此 DLL 可与应用程序或组织内的所有应用程序一起引用和分发。 这使你能够在许多应用程序中引用用户控件,并节省对用户控件的包含元素进行布局和编码的时间。 用户控件还提供应用程序内部或应用程序之间的一致性;例如,所有地址信息输入块都将具有相同的外观和行为。 一致性使应用程序的外观更加完善和专业。
您可以托管Windows 窗体UserControl派生类在窗体内部、在另一个 UserControl、网页的 Internet Explorer 内部或托管在窗体上的控件内WebBrowser。
注意
在 控件内部WebBrowser承载 UserControl 时,不能使用META
标记值 MSThemeCompatible
关闭视觉样式。 有关视觉样式的详细信息,请参阅 使用视觉样式呈现控件。
构造函数
UserControl() |
初始化 UserControl 类的新实例。 |
字段
ScrollStateAutoScrolling |
确定 AutoScroll 属性的值。 (继承自 ScrollableControl) |
ScrollStateFullDrag |
确定用户是否启用了全窗口拖动。 (继承自 ScrollableControl) |
ScrollStateHScrollVisible |
确定 HScroll 属性的值是否设置为 |
ScrollStateUserHasScrolled |
确定用户是否滚动了 ScrollableControl 控件。 (继承自 ScrollableControl) |
ScrollStateVScrollVisible |
确定 VScroll 属性的值是否设置为 |
属性
AccessibilityObject |
获取分配给该控件的 AccessibleObject。 (继承自 Control) |
AccessibleDefaultActionDescription |
获取或设置控件的默认操作说明以供具有辅助功能的客户端应用程序使用。 (继承自 Control) |
AccessibleDescription |
获取或设置辅助功能客户端应用程序使用的控件说明。 (继承自 Control) |
AccessibleName |
获取或设置辅助功能客户端应用程序所使用的控件名称。 (继承自 Control) |
AccessibleRole |
获取或设置控件的辅助性角色。 (继承自 Control) |
ActiveControl |
获取或设置容器控件上的活动控件。 (继承自 ContainerControl) |
AllowDrop |
获取或设置一个值,该值指示控件是否可以接受用户拖放到它上面的数据。 (继承自 Control) |
Anchor |
获取或设置控件绑定到的容器的边缘并确定控件如何随其父级一起调整大小。 (继承自 Control) |
AutoScaleDimensions |
获取或设置控件的设计尺寸。 (继承自 ContainerControl) |
AutoScaleFactor |
获取当前和设计时自动缩放尺寸之间的缩放因子。 (继承自 ContainerControl) |
AutoScaleMode |
获取或设置控件的自动缩放模式。 (继承自 ContainerControl) |
AutoScroll |
获取或设置一个值,该值指示容器是否允许用户滚动到任何放置在其可见边界之外的控件。 (继承自 ScrollableControl) |
AutoScrollMargin |
获取或设置自动滚动边距的大小。 (继承自 ScrollableControl) |
AutoScrollMinSize |
获取或设置自动滚动的最小尺寸。 (继承自 ScrollableControl) |
AutoScrollOffset |
获取或设置一个值,该值指示在 ScrollControlIntoView(Control) 中将控件滚动到何处。 (继承自 Control) |
AutoScrollPosition |
获取或设置自动滚动定位的位置。 (继承自 ScrollableControl) |
AutoSize |
此属性与此类无关。 |
AutoSize |
此属性与此类无关。 (继承自 Control) |
AutoSizeMode |
获取或设置控件将如何调整其自身大小。 |
AutoValidate |
获取或设置当用户将焦点更改到另一个控件时控件如何执行验证。 |
AutoValidate |
获取或设置一个值,该值指示当焦点更改时是否自动验证此容器内的控件。 (继承自 ContainerControl) |
BackColor |
获取或设置控件的背景色。 (继承自 Control) |
BackgroundImage |
获取或设置在控件中显示的背景图像。 (继承自 Control) |
BackgroundImageLayout |
获取或设置在 ImageLayout 枚举中定义的背景图像布局。 (继承自 Control) |
BindingContext |
获取或设置控件的 BindingContext。 (继承自 ContainerControl) |
BorderStyle |
获取或设置用户控件的边框样式。 |
Bottom |
获取控件下边缘与其容器的工作区上边缘之间的距离(以像素为单位)。 (继承自 Control) |
Bounds |
获取或设置控件(包括其非工作区元素)相对于其父控件的大小和位置(以像素为单位)。 (继承自 Control) |
CanEnableIme |
获取一个用以指示是否可以将 ImeMode 属性设置为活动值的值,以启用 IME 支持。 (继承自 ContainerControl) |
CanFocus |
获取一个值,该值指示控件是否可以接收焦点。 (继承自 Control) |
CanRaiseEvents |
确定是否可以在控件上引发事件。 (继承自 Control) |
CanSelect |
获取一个值,该值指示是否可以选中控件。 (继承自 Control) |
Capture |
获取或设置一个值,该值指示控件是否已捕获鼠标。 (继承自 Control) |
CausesValidation |
获取或设置一个值,该值指示控件是否会引起在任何需要在接收焦点时执行验证的控件上执行验证。 (继承自 Control) |
ClientRectangle |
获取表示控件的工作区的矩形。 (继承自 Control) |
ClientSize |
获取或设置控件的工作区的高度和宽度。 (继承自 Control) |
CompanyName |
获取包含控件的应用程序的公司名称或创建者。 (继承自 Control) |
Container |
获取包含 IContainer 的 Component。 (继承自 Component) |
ContainsFocus |
获取一个值,该值指示控件或它的一个子控件当前是否有输入焦点。 (继承自 Control) |
ContextMenu |
获取或设置与控件关联的快捷菜单。 (继承自 Control) |
ContextMenuStrip |
获取或设置与此控件关联的 ContextMenuStrip。 (继承自 Control) |
Controls |
获取包含在控件内的控件的集合。 (继承自 Control) |
Created |
获取一个值,该值指示控件是否已经创建。 (继承自 Control) |
CreateParams |
获取创建控件句柄时所需要的创建参数。 |
CreateParams |
获取创建控件句柄时所需要的创建参数。 (继承自 ContainerControl) |
CurrentAutoScaleDimensions |
获取屏幕的当前运行时尺寸。 (继承自 ContainerControl) |
Cursor |
获取或设置当鼠标指针位于控件上时显示的光标。 (继承自 Control) |
DataBindings |
为该控件获取数据绑定。 (继承自 Control) |
DataContext |
获取或设置用于数据绑定的数据上下文。 这是一个环境属性。 (继承自 Control) |
DefaultCursor |
获取或设置控件的默认光标。 (继承自 Control) |
DefaultImeMode |
获取控件支持的默认输入法编辑器 (IME) 模式。 (继承自 Control) |
DefaultMargin |
获取控件之间默认指定的间距(以像素为单位)。 (继承自 Control) |
DefaultMaximumSize |
获取以像素为单位的长度和高度,此长度和高度被指定为控件的默认最大大小。 (继承自 Control) |
DefaultMinimumSize |
获取以像素为单位的长度和高度,此长度和高度被指定为控件的默认最小大小。 (继承自 Control) |
DefaultPadding |
获取 控件内容的默认内部间距(以像素为单位)。 (继承自 Control) |
DefaultSize |
获取控件的默认大小。 |
DesignMode |
获取一个值,用以指示 Component 当前是否处于设计模式。 (继承自 Component) |
DeviceDpi |
获取显示当前控件的显示设备的 DPI 值。 (继承自 Control) |
DisplayRectangle |
获取表示控件的虚拟显示区域的矩形。 (继承自 ScrollableControl) |
Disposing |
获取一个值,该值指示 Control 基类是否在释放进程中。 (继承自 Control) |
Dock |
获取或设置哪些控件边框停靠到其父控件并确定控件如何随其父级一起调整大小。 (继承自 Control) |
DockPadding |
获取控件的所有边缘的停靠边距设置。 (继承自 ScrollableControl) |
DoubleBuffered |
获取或设置一个值,该值指示此控件是否应使用辅助缓冲区重绘其图面,以减少或避免闪烁。 (继承自 Control) |
Enabled |
获取或设置一个值,该值指示控件是否可以对用户交互作出响应。 (继承自 Control) |
Events |
获取附加到此 Component 的事件处理程序的列表。 (继承自 Component) |
Focused |
获取一个值,该值指示控件是否有输入焦点。 (继承自 Control) |
Font |
获取或设置控件显示的文字的字体。 (继承自 Control) |
FontHeight |
获取或设置控件的字体的高度。 (继承自 Control) |
ForeColor |
获取或设置控件的前景色。 (继承自 Control) |
Handle |
获取控件绑定到的窗口句柄。 (继承自 Control) |
HasChildren |
获取一个值,该值指示控件是否包含一个或多个子控件。 (继承自 Control) |
Height |
获取或设置控件的高度。 (继承自 Control) |
HorizontalScroll |
获取与水平滚动条关联的特征。 (继承自 ScrollableControl) |
HScroll |
获取或设置一个值,该值指示水平滚动条是否可见。 (继承自 ScrollableControl) |
ImeMode |
获取或设置控件的输入法编辑器 (IME) 模式。 (继承自 Control) |
ImeModeBase |
获取或设置控件的 IME 模式。 (继承自 Control) |
InvokeRequired |
获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用 Invoke 方法,因为调用方位于创建控件所在的线程以外的线程中。 (继承自 Control) |
IsAccessible |
获取或设置一个值,该值指示控件对辅助功能应用程序是否可见。 (继承自 Control) |
IsAncestorSiteInDesignMode |
指示此控件的上级之一是否位于 DesignMode 中以及该站点。 此属性为只读。 (继承自 Control) |
IsDisposed |
获取一个值,该值指示控件是否已经被释放。 (继承自 Control) |
IsHandleCreated |
获取一个值,该值指示控件是否有与它关联的句柄。 (继承自 Control) |
IsMirrored |
获取一个值,该值指示此控件是否为镜像控件。 (继承自 Control) |
LayoutEngine |
获取控件的布局引擎的缓存实例。 (继承自 Control) |
Left |
获取或设置控件左边缘与其容器的工作区左边缘之间的距离(以像素为单位)。 (继承自 Control) |
Location |
获取或设置该控件的左上角相对于其容器的左上角的坐标。 (继承自 Control) |
Margin |
获取或设置控件之间的空间。 (继承自 Control) |
MaximumSize |
获取或设置大小,该大小是 GetPreferredSize(Size) 可以指定的上限。 (继承自 Control) |
MinimumSize |
获取或设置大小,该大小是 GetPreferredSize(Size) 可以指定的下限。 (继承自 Control) |
Name |
获取或设置控件的名称。 (继承自 Control) |
Padding |
获取或设置控件内的空白。 (继承自 Control) |
Parent |
获取或设置控件的父容器。 (继承自 Control) |
ParentForm |
获取将容器控件分配给的窗体。 (继承自 ContainerControl) |
PreferredSize |
获取可以容纳控件的矩形区域的大小。 (继承自 Control) |
ProductName |
获取包含控件的程序集的产品名称。 (继承自 Control) |
ProductVersion |
获取包含控件的程序集的版本。 (继承自 Control) |
RecreatingHandle |
获取一个值,该值指示控件当前是否在重新创建其句柄。 (继承自 Control) |
Region |
获取或设置与控件关联的窗口区域。 (继承自 Control) |
RenderRightToLeft |
已过时.
已过时.
此属性现已过时。 (继承自 Control) |
ResizeRedraw |
获取或设置一个值,该值指示控件在调整大小时是否重绘自己。 (继承自 Control) |
Right |
获取控件右边缘与其容器的工作区左边缘之间的距离(以像素为单位)。 (继承自 Control) |
RightToLeft |
获取或设置一个值,该值指示是否将控件的元素对齐以支持使用从右向左的字体的区域设置。 (继承自 Control) |
ScaleChildren |
获取一个值,该值确定子控件的缩放。 (继承自 Control) |
ShowFocusCues |
获取一个值,该值指示控件是否应显示聚焦框。 (继承自 Control) |
ShowKeyboardCues |
获取一个值,该值指示用户界面是否处于适当的状态以显示或隐藏键盘快捷键。 (继承自 Control) |
Site |
获取或设置控件的站点。 (继承自 Control) |
Size |
获取或设置控件的高度和宽度。 (继承自 Control) |
TabIndex |
获取或设置控件在其容器内的 Tab 键顺序。 (继承自 Control) |
TabStop |
获取或设置一个值,该值指示用户能否使用 Tab 键将焦点放到该控件上。 (继承自 Control) |
Tag |
获取或设置包含有关控件的数据的对象。 (继承自 Control) |
Text |
获取或设置与此控件关联的文本。 |
Top |
获取或设置控件上边缘与其容器的工作区上边缘之间的距离(以像素为单位)。 (继承自 Control) |
TopLevelControl |
获取没有另一个 Windows 窗体控件作为其父级的父控件。 通常,这是控件所在的最外面的 Form。 (继承自 Control) |
UseWaitCursor |
获取或设置一个值,该值指示是否将等待光标用于当前控件以及所有子控件。 (继承自 Control) |
VerticalScroll |
获取与垂直滚动条相关联的特性。 (继承自 ScrollableControl) |
Visible |
获取或设置一个值,该值指示是否显示该控件及其所有子控件。 (继承自 Control) |
VScroll |
获取或设置一个值,该值指示垂直滚动条是否可见。 (继承自 ScrollableControl) |
Width |
获取或设置控件的宽度。 (继承自 Control) |
WindowTarget |
此属性与此类无关。 (继承自 Control) |
方法
事件
显式接口实现
IContainerControl.ActivateControl(Control) |
激活指定的控件。 (继承自 ContainerControl) |
IDropTarget.OnDragDrop(DragEventArgs) |
引发 DragDrop 事件。 (继承自 Control) |
IDropTarget.OnDragEnter(DragEventArgs) |
引发 DragEnter 事件。 (继承自 Control) |
IDropTarget.OnDragLeave(EventArgs) |
引发 DragLeave 事件。 (继承自 Control) |
IDropTarget.OnDragOver(DragEventArgs) |
引发 DragOver 事件。 (继承自 Control) |