反转(负)Form C# 的所有颜色

Swa*_*and 0 c# colors

我有一个 GUI 应用程序,它有很多颜色,如绿色、红色、白色、棕色——所有这些都在黑色背景上。

我想为此应用程序添加一个屏幕截图按钮。我对其进行了编码(并且工作正常),但我必须向用户提供有关屏幕截图已拍摄的视觉指示(不是通过任何 MessageBox)。

我能想到的最好方法之一是暂时反转所有颜色并恢复正常(就像 Adob​​e Reader 中的快照一样)。

谁能帮我这个?

或者您认为可以确认屏幕截图的任何其他想法。

或者你能告诉我如何“重新绘制”整个窗口吗?

我需要一个线索来开始我的探索!:(

提前致谢!

更新:作为临时灵魂,即使在“捕获”按钮上,我也这样做了:-

   this.BackColor = Color.White;  // My Original BackColor is Black
   Update();
   Refresh();
   Thread.Sleep(250);  // I don't want responsive UI... It's like Still Picture frame. :)
   this.BackColor = Color.Black;  // Back to Normal
   Update();
   Refresh();
Run Code Online (Sandbox Code Playgroud)

Dmi*_*lov 5

我的项目中有类似的任务,但我想在连接丢失时使我的应用程序 GUI 灰度化。我想建议你三个步骤:

  1. 截取您的应用程序的屏幕截图
  2. 颠倒它
  3. 在窗口上以透明推子形式显示此屏幕截图。

每个步骤的一些操作方法:

  1. 截取屏幕截图(代码应该放置在主窗口内):

    Point lefttopinscreencoords = this.PointToScreen(new System.Drawing.Point(0, 0));
    Bitmap bg = new Bitmap(this.Width, this.Height);
    this.DrawToBitmap(bg, new Rectangle(0, 0, bg.Width, bg.Height));
    
    Run Code Online (Sandbox Code Playgroud)
  2. 变换图像(这里是转换为灰度):

    ColorMatrix cm = new ColorMatrix(new float[][]
                                                {
                                                    new float[] {0.3f, 0.3f, 0.3f, 0, 0},
                                                    new float[] {0.59f, 0.59f, 0.59f, 0, 0},
                                                    new float[] {0.11f, 0.11f, 0.11f, 0, 0},
                                                    new float[] {0, 0, 0, 1, 0, 0},
                                                    new float[] {0, 0, 0, 0, 1, 0},
                                                    new float[] {0, 0, 0, 0, 0, 1}
                                                });
    Bitmap BogusBackground = new Bitmap(this.Width, this.Height);
    ImageAttributes imageAttributes = new ImageAttributes();
    imageAttributes.SetColorMatrix(cm);
    Graphics g = Graphics.FromImage(BogusBackground);
    g.DrawImage(bg, new Rectangle(0, 0, BogusBackground.Width, BogusBackground.Height),
                0,0,
                bg.Width,
                bg.Height,
                GraphicsUnit.Pixel, imageAttributes);
    g.Dispose();
    
    Run Code Online (Sandbox Code Playgroud)
  3. 您可以在这里找到优秀的表单推子:http://www.codeproject.com/KB/cs/notanotherformfader.aspx ?msg=1980689 。现在,如果您创建一个名为 SplashForm 的派生表单(来自 FormFader),您可以执行以下操作:

    SplashForm sp = new SplashForm();
    sp.BackgroundImage = BogusBackground;
    sp.BackgroundImageLayout = ImageLayout.Stretch;
    sp.FadeOnLoad = false;
    sp.FadeOnClose = true;
    sp.FadeOpacity = 1;
    sp.Location = this.Location;
    sp.Height = this.Height;
    sp.Width = this.Width;
    sp.StartPosition = FormStartPosition.Manual;
    sp.Show();
    sp.Close();
    
    Run Code Online (Sandbox Code Playgroud)