qq_14987897 2018-01-30 07:20 采纳率: 50%
浏览 1229
已结题

拖动picturebox上的图片,上层的透明控件闪烁

透明控件代码

public partial class RoundButton : Control
    {
        public RoundButton()
        {
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.BackColor = Color.Transparent;
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.DrawRectangle(Pens.DarkCyan, new Rectangle(0, 0, this.Width - 1, this.Height - 1));
            using (SolidBrush sb = new SolidBrush(this.ForeColor))
            {
                SizeF se = g.MeasureString(this.Text, this.Font);
                g.DrawString(this.Text, this.Font, sb, (this.Width - se.Width) / 2, (this.Height - se.Height)/2);
            } 
            base.OnPaint(e);
        }

        protected override void OnPaintBackground(PaintEventArgs e) //不画背景
        {
            base.OnPaintBackground(e);  
        }

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams para = base.CreateParams;
                para.ExStyle |= 0x20; //WS_EX_TRANSPARENT 透明支持
                return para;
            }
        } 
    } 

拖动图片时,透明控件会消失,静止才出现。

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-01-30 16:32
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?