您可以使用SetWindowRgnAPI 函数来更改窗口的形状。正如您在此处看到的,该函数获取三个参数:
Handle属性获取它。您可以TextBox使用OnHandleCreatedMethod 中的此函数从子类化并创建椭圆形 TextBox。该类可以是这样的:
class OvalTextBox : TextBox
{
[DllImport("user32.dll")]
static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);
[DllImport("gdi32.dll")]
static extern IntPtr CreateRoundRectRgn(int x1, int y1, int x2, int y2, int cx, int cy);
public OvalTextBox()
{
base.BorderStyle = System.Windows.Forms.BorderStyle.None;
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
SetWindowRgn(this.Handle, CreateRoundRectRgn(0, 0, this.Width, this.Height, 20, 20), true);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8071 次 |
| 最近记录: |