winform怎么把textbox变成圆角

sw01 2012-08-04 11:30:37
picturebox + textbox + 圆角图片。。这种效果不是很好。。
能不能到达这种效果。。
http://my.csdn.net/my/album/detail/1239337
...全文
2992 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
Justin881216 2012-08-06
  • 打赏
  • 举报
回复
从TextBox继承一个新的控件,重新画边框,圆角矩形,方便维护,要是直接在TextBox上做手脚,那要做多少次...
ms 2012-08-05
  • 打赏
  • 举报
回复
目前我只会用背景图
Ernset 2012-08-05
  • 打赏
  • 举报
回复
DEV 控件是个垫脚好的选择吧。
sw01 2012-08-05
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

直接贴背景图
[/Quote]

能发我几张背景图吗。。dengjiejie1990@163.com
sw01 2012-08-05
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 的回复:]

重写OnPaintBackground 事件
C# code

protected override void OnPaintBackground(PaintEventArgs e)
{

base.OnPaintBackground(e);
e.Graphics.SmoothingMode = Smo……
[/Quote]

画的范围好大。。能不能画一个和textbox控件大小差不多的。。
sw01 2012-08-05
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]

如果要比较炫的界面,也许可以考虑使用 WPF来实现,或者去找找 第三方控件,厄,我个人不是很喜欢写控件,也许一不小心就会留个小BUG,改来改去很麻烦...
[/Quote]

winform已经搞了一大半。。WPF估计来不及了。。
zypine 2012-08-05
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]
引用 12 楼 的回复:

重写OnPaintBackground 事件
C# code

protected override void OnPaintBackground(PaintEventArgs e)
{

base.OnPaintBackground(e);
e.Graphics.SmoothingMode = Smo……


画的范围好大。。能不能画一个和te……
[/Quote]


public partial class Component1 : Control
{
TextBox box = new TextBox();
public Component1()
{
InitializeComponent();
box.BorderStyle = BorderStyle.None;

//这儿需要的事件自己加

this.Controls.Add(box);
}

[DefaultValue("")]
public new string Text
{
get { return box.Text ; }
set
{
box.Text = value;

}
}

int r = 7;
[ Category("布局"), Description("倒角半径。")]
public int R
{
get { return r; }
set
{
r= value;

}
}

protected override void OnPaintBackground(PaintEventArgs e)
{

int w = R * 2;
base.OnPaintBackground(e);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (GraphicsPath path = new GraphicsPath())
{
path.AddArc(0, 0, w , w, 180, 90);
path.AddArc(this.Width - w -1, 0, w, w, -90, 90);
path.AddArc(this.Width - w -1, this.Height - w-1, w, w, 0, 90);
path.AddArc(0, this.Height - w -1, w, w, 90, 90);
path.CloseFigure();

e.Graphics.FillPath(Brushes.White, path);
using (Pen pen = new Pen(Color.Green ))
{
e.Graphics.DrawPath(pen, path);
}


}
}

private void Component1_Resize(object sender, EventArgs e)
{
box.Left = Height/2;
box.Top = Height/2 - box.Height /2;
box.Width = this.Width - Height ;

}
}



猴头 2012-08-05
  • 打赏
  • 举报
回复
就像这样重绘控件吧,
[Quote=引用 12 楼 的回复:]

重写OnPaintBackground 事件
C# code

protected override void OnPaintBackground(PaintEventArgs e)
{

base.OnPaintBackground(e);
e.Graphics.SmoothingMode = Smo……
[/Quote]
bwangel 2012-08-04
  • 打赏
  • 举报
回复
自已开发一个
SocketUpEx 2012-08-04
  • 打赏
  • 举报
回复
找几个设置窗体的API,把窗体的句柄换成TextBox的
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);

private void Form1_Load(object sender, System.EventArgs e)
{
Int32 width = textBox1.Width;
Int32 height = textBox1.Height;

SetWindowRgn(this.textBox1.Handle, CreateRoundRectRgn(2, 2, width, height, width, height), true);
}




风之影子 2012-08-04
  • 打赏
  • 举报
回复
用图片效果还不好啊。

网页上也是用图片和CSS实现的
失落的神庙 2012-08-04
  • 打赏
  • 举报
回复
textbox边框去掉。然后在这个textbox后面放一张背景图
zypine 2012-08-04
  • 打赏
  • 举报
回复
重写OnPaintBackground 事件

protected override void OnPaintBackground(PaintEventArgs e)
{

base.OnPaintBackground(e);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (GraphicsPath path = new GraphicsPath())
{
path.AddArc(0, 0, Height - 1, Height - 1, 90, 180);
path.AddArc(Width - Height, 0, Height - 1, Height - 1, 270, 180);
path.CloseFigure();

e.Graphics.FillPath(Brushes.White, path);
using (Pen pen = new Pen(Color.Green ))
{
e.Graphics.DrawPath(pen, path);
}
}
}
wushuai1346 2012-08-04
  • 打赏
  • 举报
回复
如果要比较炫的界面,也许可以考虑使用 WPF来实现,或者去找找 第三方控件,厄,我个人不是很喜欢写控件,也许一不小心就会留个小BUG,改来改去很麻烦...
零-点 2012-08-04
  • 打赏
  • 举报
回复
这个可以引用一些Winform皮肤
sw01 2012-08-04
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

引用 6 楼 的回复:

引用 3 楼 的回复:

找几个设置窗体的API,把窗体的句柄换成TextBox的
TextBox也是窗体嘛

比如:
C# code
[DllImport("user32.dll")]
static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);

[DllI……
[/Quote]

可是我没有好看的背景图额。。能发我几张吗。。dengjiejie1990@163.com
SocketUpEx 2012-08-04
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

引用 3 楼 的回复:

找几个设置窗体的API,把窗体的句柄换成TextBox的
TextBox也是窗体嘛

比如:
C# code
[DllImport("user32.dll")]
static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);

[DllImport("gdi3……

……
[/Quote]

其实
你图片里那种效果更加好实现
外面是一个大背景图片
里面再放一个小的文本框
让人看起来就像是文本框有圆角一样了


jiongxiaotao 2012-08-04
  • 打赏
  • 举报
回复
直接贴背景图
sw01 2012-08-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

找几个设置窗体的API,把窗体的句柄换成TextBox的
TextBox也是窗体嘛

比如:
C# code
[DllImport("user32.dll")]
static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);

[DllImport("gdi3……
[/Quote]

貌似这样文本边框就看不见了。。如何才能达到我连接上的图片中的效果。。
sw01 2012-08-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

用图片效果还不好啊。

网页上也是用图片和CSS实现的
[/Quote]

但是在winform中。效果不是很好额。。

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧