Hi!
I=B4m developing a screen-capture application.
My Idea is to cover the whole screen with a semi-transparent
clickt-hrough layer, solely the Area that will be captured should
appear without this layer.
What I did:
I use two forms.
The first form works as the background-layer. It has no border and
covers the whole screen. Opacity is set and the ex.Style ist
WS_EX_TRANSPARENT to make it click-through. On this Form I have a panel
wich backcolor is set to the forms transparency-key, hence we can look
through the panels area.
Second form is not click-through, because i need controls on it. There
is also an transparent panel on it, which refers to the area to be
captured. When moving and resizing this form I map position and size
of both forms transparent panels.
The way it works is exactly what I had in mind, but there is one
problem: When moving the front-form I update the location of the
transparent panel on the back-form. This update takes to much time, i.
e=2E the second panel moves two slow.
Does anyone can give me an hint how I can move my front-form and the
transparent-panel on the back-form in exactly the same time. I read
about the DeferWindowPos Win32 Methods, but I didn=B4t get it work.
Since I think nobody understood what I=B4m talking about I=B4ll provide
some code:
----------------------------------------------BACK-FORM--------------------=
------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace transp
{
public class Back : Form
{
private System.ComponentModel.IContainer components =3D null;
private Panel transparentArea;
public const int WS_EX_TRANSPARENT =3D 32;
protected override void Dispose(bool disposing)
{
if (disposing && (components !=3D null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.transparentArea =3D new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// transparentArea
//
this.transparentArea.BackColor =3D
System.Drawing.Color.Fuchsia;
this.transparentArea.Location =3D new
System.Drawing.Point(40, 73);
this.transparentArea.Name =3D "transparentArea";
this.transparentArea.Size =3D new System.Drawing.Size(200,
100);
this.transparentArea.TabIndex =3D 0;
//
// Back
//
this.AutoScaleDimensions =3D new System.Drawing.SizeF(6F,
13F);
this.AutoScaleMode =3D
System.Windows.Forms.AutoScaleMode.Font;
this.BackColor =3D System.Drawing.Color.LightSlateGray;
this.ClientSize =3D new System.Drawing.Size(292, 266);
this.Controls.Add(this.transparentArea);
this.FormBorderStyle =3D
System.Windows.Forms.FormBorderStyle.None;
this.Name =3D "Back";
this.Opacity =3D 0.8;
this.Text =3D "Form1";
this.TopMost =3D true;
this.TransparencyKey =3D System.Drawing.Color.Fuchsia;
this.ResumeLayout(false);
}
public Back()
{
InitializeComponent();
this.Bounds =3D SystemInformation.VirtualScreen;
}
public Rectangle TransparentAreaBounds
{
get { return this.transparentArea.Bounds; }
set { this.transparentArea.Bounds =3D value; }
}
protected override CreateParams CreateParams
{
get
{
//make it click-through
CreateParams cp =3D base.CreateParams;
cp.ExStyle |=3D WS_EX_TRANSPARENT;
return cp;
}
}
}
}
---------------------------------------------------------------------------=
-----------------------------------------------
----------------------------------------------FRONT-FORM-------------------=
------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace transp
{
public class Front : Form
{
private System.ComponentModel.IContainer components =3D null;
private Back backGroundForm =3D null;
protected override void Dispose(bool disposing)
{
if (disposing && (components !=3D null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.SuspendLayout();
this.AutoScaleDimensions =3D new System.Drawing.SizeF(6F,
13F);
this.AutoScaleMode =3D
System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize =3D new System.Drawing.Size(292, 266);
this.FormBorderStyle =3D
System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.Name =3D "Front";
this.Text =3D "Front";
this.ResumeLayout(false);
}
public Front()
{
InitializeComponent();
this.TopMost =3D true;
this.BackColor =3D Color.Fuchsia;
this.TransparencyKey =3D Color.Fuchsia;
this.Move +=3D new EventHandler(UpdateBackGround);
this.Resize +=3D new EventHandler(UpdateBackGround);
backGroundForm =3D new Back();
this.Show();
backGroundForm.Show();
backGroundForm.TransparentAreaBounds =3D this.Bounds;
}
void UpdateBackGround(object sender, EventArgs e)
{
backGroundForm.TransparentAreaBounds =3D this.Bounds;
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Front());
}
}
}
---------------------------------------------------------------------------=
-----------------------------------------------
I would appreciate any hints. I=B4m struggling for days now !!!!!
Thanks!