首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在GraphicsPath上添加控件

如何在GraphicsPath上添加控件
EN

Stack Overflow用户
提问于 2015-03-10 10:54:48
回答 1查看 340关注 0票数 0

我已经使用OnPaint事件绘制了一个圆形矩形:

代码语言:javascript
复制
   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的LocationPoint来设置我对它的控制?

EN

回答 1

Stack Overflow用户

发布于 2015-03-10 11:15:23

所以你想要看起来像这样的东西:

我的被设置为一个从控件继承的自定义类,并且有一个自定义的OnPaint来获取圆角边缘:

代码语言:javascript
复制
class RoundedText : Control
{
    //Code
    protected override void OnPaint(PaintEventArgs e)
    {
        //Code for rounded edges
    }
}

然后,为了显示文本框,我将textbox添加到控件中,就像添加表单一样:

代码语言:javascript
复制
class RoundedText : Control
{
    public RoundedText()
    {
        TextBox t = new TextBox();
        t.Left = 10;
        t.Top = 1;
        this.Controls.Add(t);
    }
}

这样,TextBox总是相对于矩形放置的,所以您不需要担心获取路径的位置。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28955380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档