当前位置:  开发笔记 > 编程语言 > 正文

如何在设计视图中为自定义控件添加边框?

如何解决《如何在设计视图中为自定义控件添加边框?》经验,为你挑选了1个好方法。

透明图像在Windows窗体中是纯粹的邪恶,这就是为什么我创建了一个自定义控件类来处理它们.设计师在空的时候不显示我的控制权.我想添加一个微妙的边框,但只在设计视图中(当用户没有添加边框时).我该怎么做?

我的班级是:

class TransparentImage : Control
{
    public Image Image { get; set; }

    protected Graphics graphics;

    public string FilePath { get; set; }

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT

            return cp;
        }
    }

    protected override void OnPaintBackground(PaintEventArgs pevent)
    {
        // Don't paint background
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        // Update the private member so we can use it in the OnDraw method
        this.graphics = e.Graphics;

        // Set the best settings possible (quality-wise)
        this.graphics.TextRenderingHint =
            System.Drawing.Text.TextRenderingHint.AntiAlias;
        this.graphics.InterpolationMode =
            System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
        this.graphics.PixelOffsetMode =
            System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
        this.graphics.SmoothingMode =
            System.Drawing.Drawing2D.SmoothingMode.HighQuality;

        if (Image != null)
        {
            // Sets the images' sizes and positions
            var width = Image.Size.Width;
            var height = Image.Size.Height;
            var size = new Rectangle(0, 0, width, height);

            // Draws the two images
            this.graphics.DrawImage(Image, size);
        }
    }
}

SLaks.. 6

检查if (this.DesignMode)你的OnPaint电话DrawRectangle.

你可能想用一个 new Pen(SystemColors.ActiveBorder) { DashStyle = DashStyle.Dot }



1> SLaks..:

检查if (this.DesignMode)你的OnPaint电话DrawRectangle.

你可能想用一个 new Pen(SystemColors.ActiveBorder) { DashStyle = DashStyle.Dot }

推荐阅读
周扒pi
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有