6

これは私にとって継続的な問題であり、私は素晴らしい透明性を備えたカスタム描画フォームを作成しようとしています。

これは私が今得ることができる限り近いです、私はちょうど30分前にそれを始めました。

編集: 最新のSunilla http://i.stack.imgur.com/rqvDe.pngのように、カスタムフォームのデザインとコントロールを最初から作成します。そして、私はそれに良いドロップシャドウを付けたいと思っていました。あるいは、ウィンドウズアレオのように見える別のデザインを作りたいと思っていました。

form.opacityを0%に設定してから、現在のところ500ミリ秒ごとにフォームのすぐ後ろにある画面の画像(画面上のすべてのもの、現在実行中のプログラム、デスクトップなど)を取得し、それを背景として設定して表示します。透明度を100%に戻します。だから私はそれに何でも描くことができ、それは完璧に見えます!しかし、私が得る唯一の問題は、それが仕事をするとき、それがちらつくことです。はい、DoubleBufferingをtrueに設定して試しましたが、違いはありません。

メインコードを聞く:

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));
        }
    }
}

注: ExtDrawing2Dは別のクラスであり、ほぼ完璧な丸い角を描画することで多くの重い作業を行います。そして、それは問題ではありません。私は半年前にそれを開発しました、そしてすべての私のプロジェクトでそれで問題があったことは一度もありませんでした。

結果:

この全体的な問題を突き刺すより良い方法があれば、私は長い間ウェブを見回してきましたが、喜んでそれを聞くのが大好きです。

4

1 に答える 1

1

あなたが何を達成しようとしているのか理解できなかったので、私はあなたのコードを試しました、そしてそうです、それはたくさんちらつきます。ただし、これは、不透明度を0に設定し、0.5秒ごとに1に戻すためです。透明なウィンドウをシミュレートしようとしているように見える場合。透明な窓を使ってみませんか?すなわち。FormBorderStyle = Noneで、BackColorとTransparencyKeyを同じ色(例:赤)に設定します。

于 2012-06-26T01:20:47.690 に答える