1.没有这个功能,你要自己包装
2.对应Delphi的Align属性的是Dock属性
给你一个数字编辑框的类源代码
-------------------
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace 这里换成你自己的命名空间
{
/// <summary>
/// NumBox 的摘要说明。
/// </summary>
///
//[ToolboxBitmap(typeof(NumericTextBox), "NumericTextBox.ico")]
public class NumericBox : System.Windows.Forms.TextBox
{
public delegate void InvalidUserEntryEvent(object sender,KeyPressEventArgs e);
public event InvalidUserEntryEvent InvalidUserEntry;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public NumericBox(System.ComponentModel.IContainer container)
{
/// <summary>
/// Required for Windows.Forms Class Composition Designer support
/// </summary>
container.Add(this);
InitializeComponent();
}
public NumericBox()
{
/// <summary>
/// Required for Windows.Forms Class Composition Designer support
/// </summary>
InitializeComponent();
}
#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();
}
#endregion
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{
int asciiInteger = Convert.ToInt32(e.KeyChar);
if (asciiInteger >= 47 &&
asciiInteger <= 57)
{
e.Handled = false;
return;
}
if (asciiInteger == 8)
{
e.Handled = false;
return;
}
e.Handled = true;
if (InvalidUserEntry != null)
InvalidUserEntry(this, e);
}
public override string Text
{
get
{
return base.Text;
}
set
{
try
{
int.Parse(value);
base.Text = value;
return;
}
catch
{
return;
}
/*if (value == null)
{
base.Text = value;
return;
}
*/
}
}
}
}