【发布时间】:2021-05-03 19:43:56
【问题描述】:
我想知道如何在 c#(visual studio) 中为带有圆角的文本框创建一个类。谁能帮帮我。我在网上找到了一个代码来创建它,但无法放大(拉伸)它
using System.Windows.Forms;
using System.Drawing;
using System;
class round : TextBox
{
[System.Runtime.InteropServices.DllImport("gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // X-coordinate of upper-left corner or padding at start
int nTopRect,// Y-coordinate of upper-left corner or padding at the top of the textbox
int nRightRect, // X-coordinate of lower-right corner or Width of the object
int nBottomRect,// Y-coordinate of lower-right corner or Height of the object
//RADIUS, how round do you want it to be?
int nheightRect, //height of ellipse
int nweightRect //width of ellipse
);
protected override void OnCreateControl()
{
base.OnCreateControl();
this.Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(2, 3, this.Width, this.Height, 15, 15)); //play with these values till you are happy
}
}
【问题讨论】:
-
圆角是圆角。您应该尝试将在按钮中找到的技术应用于文本框。因为真的没有什么可以帮助 - 你没有展示你的尝试并描述一个问题
-
更简单地使用无边框文本框并从容器的 Paint 事件中绘制圆度。
-
不值得麻烦。