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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料