我已经使用OnPaint事件绘制了一个圆形矩形:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
GraphicsPath path = RoundedRectangle.Create(5, 5, 20, 20);
e.Graphics.DrawPath(Pens.Black, path);
}我想在那个矩形上画一个控件。例如:一个TextBox
问:有没有办法知道GraphicsPath的Location或Point来设置我对它的控制?
发布于 2015-03-10 11:15:23
所以你想要看起来像这样的东西:

我的被设置为一个从控件继承的自定义类,并且有一个自定义的OnPaint来获取圆角边缘:
class RoundedText : Control
{
//Code
protected override void OnPaint(PaintEventArgs e)
{
//Code for rounded edges
}
}然后,为了显示文本框,我将textbox添加到控件中,就像添加表单一样:
class RoundedText : Control
{
public RoundedText()
{
TextBox t = new TextBox();
t.Left = 10;
t.Top = 1;
this.Controls.Add(t);
}
}这样,TextBox总是相对于矩形放置的,所以您不需要担心获取路径的位置。
https://stackoverflow.com/questions/28955380
复制相似问题