winforms 如何减少True Transparency WinForm更新时的 Flink ?还是有更好的办法

2hh7jdfx  于 7个月前  发布在  Flink
关注(0)|答案(1)|浏览(80)

这一直是一个持续的问题与我,我一直试图使一个自定义绘制的形式与尼斯的透明度。
这是我现在能做的最接近的了,我半小时前才开始做的。

  • 编辑:* 我从头开始定制表单设计和控件,比如我最新的Sunilla https://i.stack.imgur.com/rqvDe.png。我想有一个很好的阴影上,或使另一个设计,看起来有点像windows areo。

它设置form.opacity为0%,然后从现在开始每隔500毫秒抓取窗体后面的屏幕图像(屏幕上的任何内容,当前运行的程序,桌面等),并将其设置为背景并将透明度恢复为100%。所以我可以在上面画任何东西,它看起来很完美!但我得到的唯一问题是,当它做的工作,它 Flink 。是的,我尝试了它与DoubleBuffering设置为真,没有区别。
听到主代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TTTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            Opacity = 100;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = !timer1.Enabled;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            Opacity = 0;
            Bitmap img = new Bitmap(this.Width, this.Height);
            Graphics gr = Graphics.FromImage(img);
            gr.CopyFromScreen(Location, Point.Empty, Size);
            this.BackgroundImage = img;
            Opacity = 100;
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;

            ExtDrawing2D.FillRoundRect(g, new SolidBrush(Color.FromArgb(100, 255, 255, 255)), new RectangleF(1, 1, Width - 3, Height - 3), 4f);
            g.DrawPath(new Pen(Color.FromArgb(100, 0, 0, 0)), ExtDrawing2D.GetRoundedRect(new RectangleF(0, 0, Width - 1, Height - 1), 5f));
            g.DrawPath(new Pen(Color.FromArgb(100, 255,255,255)), ExtDrawing2D.GetRoundedRect(new RectangleF(1,1, Width - 3, Height - 3), 4f));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1_Tick(sender, e);
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;

            ExtDrawing2D.FillRoundRect(g, new SolidBrush(Color.FromArgb(150, 255,255,255)), new RectangleF(1, 1, panel1.Width - 3, panel1.Height - 3), 2f);
            g.DrawPath(new Pen(Color.FromArgb(100, 0, 0, 0)), ExtDrawing2D.GetRoundedRect(new RectangleF(0, 0, panel1.Width - 1, panel1.Height - 1), 3f));
            g.DrawPath(new Pen(Color.FromArgb(100, 255, 255, 255)), ExtDrawing2D.GetRoundedRect(new RectangleF(1, 1, panel1.Width - 3, panel1.Height - 3), 2f));
        }
    }
}
  • 注意:* ExtDrawing 2D是一个单独的类,它完成了很多繁重的工作,绘制几乎完美的圆角。这不是问题,我半年前开发了它,在我所有的项目中从来没有遇到过问题。

结果:

如果有一个更好的方式刺在这个整体的问题,我很高兴听到它,虽然我一直在寻找周围的网络很长一段时间。

ryoqjall

ryoqjall1#

我试过你的代码,因为我不知道你想实现什么,是的,它 Flink 了很多。但这是因为您每半秒将不透明度设置为0和1。如果看起来像是在尝试模拟透明窗口。为什么不使用透明的Windows?也就是说,FormBorderStyle=None,并将BackColor和BackrencyKey设置为相同的颜色(例如,红色)。

相关问题