/trunk/Widow/DrawOverlayForm.Designer.cs |
@@ -0,0 +1,59 @@ |
 |
namespace Widow |
{ |
partial class DrawOverlayForm |
{ |
/// <summary> |
/// Required designer variable. |
/// </summary> |
private System.ComponentModel.IContainer components = null; |
/// <summary> |
/// Clean up any resources being used. |
/// </summary> |
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
protected override void Dispose(bool disposing) |
{ |
if (disposing && (components != null)) |
{ |
components.Dispose(); |
} |
base.Dispose(disposing); |
} |
#region Windows Form Designer generated code |
|
/// <summary> |
/// Required method for Designer support - do not modify |
/// the contents of this method with the code editor. |
/// </summary> |
private void InitializeComponent() |
{ |
this.SuspendLayout(); |
// |
// DrawOverlayForm |
// |
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
this.BackColor = System.Drawing.Color.White; |
this.ClientSize = new System.Drawing.Size(800, 450); |
this.DoubleBuffered = true; |
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; |
this.MaximizeBox = false; |
this.MinimizeBox = false; |
this.Name = "DrawOverlayForm"; |
this.Opacity = 0.5D; |
this.ShowInTaskbar = false; |
this.Text = "DrawOverlayForm"; |
this.TopMost = true; |
this.TransparencyKey = System.Drawing.Color.Green; |
this.WindowState = System.Windows.Forms.FormWindowState.Maximized; |
this.Paint += new System.Windows.Forms.PaintEventHandler(this.DrawOverlayForm_Paint); |
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.DrawOverlayForm_MouseDown); |
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.DrawOverlayForm_MouseMove); |
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.DrawOverlayForm_MouseUp); |
this.ResumeLayout(false); |
|
} |
|
#endregion |
} |
} |
/trunk/Widow/DrawOverlayForm.cs |
@@ -0,0 +1,112 @@ |
using System; |
using System.Drawing; |
using System.Linq; |
using System.Windows.Forms; |
|
namespace Widow |
{ |
public partial class DrawOverlayForm : Form |
{ |
public event EventHandler<WindowDrawnEventArgs> WindowDrawn; |
#region Public Enums, Properties and Fields |
|
public bool IsMouseDown { get; set; } |
|
public Point StartLocation { get; set; } |
|
public Point StopLocation { get; set; } |
|
public SolidBrush DrawBrush { get; } |
|
public SolidBrush FormBrush { get; } |
|
#endregion |
|
#region Private Delegates, Events, Enums, Properties, Indexers and Fields |
|
private Point CurrentLocation { get; set; } |
|
private volatile Bitmap _bitmap; |
|
#endregion |
|
#region Constructors, Destructors and Finalizers |
|
public DrawOverlayForm() |
{ |
InitializeComponent(); |
|
DrawBrush = new SolidBrush(Color.Green); |
FormBrush = new SolidBrush(Color.White); |
} |
|
#endregion |
|
#region Event Handlers |
|
private void DrawOverlayForm_MouseDown(object sender, MouseEventArgs e) |
{ |
IsMouseDown = true; |
StartLocation = e.Location; |
} |
|
private void DrawOverlayForm_MouseUp(object sender, MouseEventArgs e) |
{ |
IsMouseDown = false; |
StopLocation = e.Location; |
|
var left = Math.Min(StartLocation.X, StopLocation.X); |
var top = Math.Min(StartLocation.Y, StopLocation.Y); |
var width = Math.Abs(StopLocation.X - StartLocation.X); |
var height = Math.Abs(StopLocation.Y - StartLocation.Y); |
|
WindowDrawn?.Invoke(this, new WindowDrawnEventArgs(left, top, width, height)); |
|
Close(); |
} |
|
private void DrawOverlayForm_MouseMove(object sender, MouseEventArgs e) |
{ |
CurrentLocation = e.Location; |
|
if (!IsMouseDown) |
{ |
return; |
} |
|
var selection = new Rectangle( |
Math.Min(StartLocation.X, CurrentLocation.X), |
Math.Min(StartLocation.Y, CurrentLocation.Y), |
Math.Abs(StartLocation.X - CurrentLocation.X), |
Math.Abs(StartLocation.Y - CurrentLocation.Y)); |
|
_bitmap = new Bitmap(Width, Height); |
|
using (var canvas = Graphics.FromImage(_bitmap)) |
{ |
canvas.Clear(Color.White); |
canvas.FillRectangle(DrawBrush, selection); |
} |
|
Invalidate(); |
Update(); |
} |
|
private void DrawOverlayForm_Paint(object sender, PaintEventArgs e) |
{ |
if (_bitmap == null) |
{ |
return; |
} |
|
var graphics = e.Graphics; |
|
graphics.DrawImage(_bitmap, Location.X, Location.Y, Width, Height); |
|
_bitmap?.Dispose(); |
_bitmap = null; |
} |
|
#endregion |
} |
} |
/trunk/Widow/DrawOverlayForm.resx |
@@ -0,0 +1,120 @@ |
<?xml version="1.0" encoding="utf-8"?> |
<root> |
<!-- |
Microsoft ResX Schema |
|
Version 2.0 |
|
The primary goals of this format is to allow a simple XML format |
that is mostly human readable. The generation and parsing of the |
various data types are done through the TypeConverter classes |
associated with the data types. |
|
Example: |
|
... ado.net/XML headers & schema ... |
<resheader name="resmimetype">text/microsoft-resx</resheader> |
<resheader name="version">2.0</resheader> |
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
<value>[base64 mime encoded serialized .NET Framework object]</value> |
</data> |
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
<comment>This is a comment</comment> |
</data> |
|
There are any number of "resheader" rows that contain simple |
name/value pairs. |
|
Each data row contains a name, and value. The row also contains a |
type or mimetype. Type corresponds to a .NET class that support |
text/value conversion through the TypeConverter architecture. |
Classes that don't support this are serialized and stored with the |
mimetype set. |
|
The mimetype is used for serialized objects, and tells the |
ResXResourceReader how to depersist the object. This is currently not |
extensible. For a given mimetype the value must be set accordingly: |
|
Note - application/x-microsoft.net.object.binary.base64 is the format |
that the ResXResourceWriter will generate, however the reader can |
read any of the formats listed below. |
|
mimetype: application/x-microsoft.net.object.binary.base64 |
value : The object must be serialized with |
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
: and then encoded with base64 encoding. |
|
mimetype: application/x-microsoft.net.object.soap.base64 |
value : The object must be serialized with |
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
: and then encoded with base64 encoding. |
|
mimetype: application/x-microsoft.net.object.bytearray.base64 |
value : The object must be serialized into a byte array |
: using a System.ComponentModel.TypeConverter |
: and then encoded with base64 encoding. |
--> |
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
<xsd:element name="root" msdata:IsDataSet="true"> |
<xsd:complexType> |
<xsd:choice maxOccurs="unbounded"> |
<xsd:element name="metadata"> |
<xsd:complexType> |
<xsd:sequence> |
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
</xsd:sequence> |
<xsd:attribute name="name" use="required" type="xsd:string" /> |
<xsd:attribute name="type" type="xsd:string" /> |
<xsd:attribute name="mimetype" type="xsd:string" /> |
<xsd:attribute ref="xml:space" /> |
</xsd:complexType> |
</xsd:element> |
<xsd:element name="assembly"> |
<xsd:complexType> |
<xsd:attribute name="alias" type="xsd:string" /> |
<xsd:attribute name="name" type="xsd:string" /> |
</xsd:complexType> |
</xsd:element> |
<xsd:element name="data"> |
<xsd:complexType> |
<xsd:sequence> |
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
</xsd:sequence> |
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
<xsd:attribute ref="xml:space" /> |
</xsd:complexType> |
</xsd:element> |
<xsd:element name="resheader"> |
<xsd:complexType> |
<xsd:sequence> |
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
</xsd:sequence> |
<xsd:attribute name="name" type="xsd:string" use="required" /> |
</xsd:complexType> |
</xsd:element> |
</xsd:choice> |
</xsd:complexType> |
</xsd:element> |
</xsd:schema> |
<resheader name="resmimetype"> |
<value>text/microsoft-resx</value> |
</resheader> |
<resheader name="version"> |
<value>2.0</value> |
</resheader> |
<resheader name="reader"> |
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
</resheader> |
<resheader name="writer"> |
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
</resheader> |
</root> |
/trunk/Widow/RuleEditForm.Designer.cs |
@@ -21,7 +21,6 @@ |
this.groupBox1 = new System.Windows.Forms.GroupBox(); |
this.removeButton = new System.Windows.Forms.Button(); |
this.groupBox2 = new System.Windows.Forms.GroupBox(); |
this.groupBox7 = new System.Windows.Forms.GroupBox(); |
this.WindowTitle = new System.Windows.Forms.TextBox(); |
this.groupBox6 = new System.Windows.Forms.GroupBox(); |
this.ignoreHeightCheckBox = new System.Windows.Forms.CheckBox(); |
@@ -39,9 +38,9 @@ |
this.refreshButton = new System.Windows.Forms.Button(); |
this.desktopWindowsListBox = new System.Windows.Forms.ListBox(); |
this.addButton = new System.Windows.Forms.Button(); |
this.drawButton = new System.Windows.Forms.Button(); |
this.groupBox1.SuspendLayout(); |
this.groupBox2.SuspendLayout(); |
this.groupBox7.SuspendLayout(); |
this.groupBox6.SuspendLayout(); |
this.groupBox5.SuspendLayout(); |
this.groupBox4.SuspendLayout(); |
@@ -82,7 +81,8 @@ |
// |
// groupBox2 |
// |
this.groupBox2.Controls.Add(this.groupBox7); |
this.groupBox2.Controls.Add(this.drawButton); |
this.groupBox2.Controls.Add(this.WindowTitle); |
this.groupBox2.Controls.Add(this.groupBox6); |
this.groupBox2.Controls.Add(this.groupBox5); |
this.groupBox2.Controls.Add(this.groupBox4); |
@@ -89,24 +89,14 @@ |
this.groupBox2.Controls.Add(this.groupBox3); |
this.groupBox2.Location = new System.Drawing.Point(382, 12); |
this.groupBox2.Name = "groupBox2"; |
this.groupBox2.Size = new System.Drawing.Size(190, 302); |
this.groupBox2.Size = new System.Drawing.Size(190, 331); |
this.groupBox2.TabIndex = 2; |
this.groupBox2.TabStop = false; |
this.groupBox2.Text = "Settings"; |
// |
// groupBox7 |
// WindowTitle |
// |
this.groupBox7.Controls.Add(this.WindowTitle); |
this.groupBox7.Location = new System.Drawing.Point(6, 19); |
this.groupBox7.Name = "groupBox7"; |
this.groupBox7.Size = new System.Drawing.Size(178, 50); |
this.groupBox7.TabIndex = 5; |
this.groupBox7.TabStop = false; |
this.groupBox7.Text = "Title"; |
// |
// WindowName |
// |
this.WindowTitle.Location = new System.Drawing.Point(8, 19); |
this.WindowTitle.Location = new System.Drawing.Point(14, 31); |
this.WindowTitle.Name = "WindowTitle"; |
this.WindowTitle.ReadOnly = true; |
this.WindowTitle.Size = new System.Drawing.Size(162, 20); |
@@ -274,6 +264,16 @@ |
this.addButton.UseVisualStyleBackColor = true; |
this.addButton.Click += new System.EventHandler(this.AddButton_Click); |
// |
// drawButton |
// |
this.drawButton.Location = new System.Drawing.Point(14, 299); |
this.drawButton.Name = "drawButton"; |
this.drawButton.Size = new System.Drawing.Size(75, 23); |
this.drawButton.TabIndex = 5; |
this.drawButton.Text = "Draw"; |
this.drawButton.UseVisualStyleBackColor = true; |
this.drawButton.Click += new System.EventHandler(this.DrawButton_Click); |
// |
// RuleEditForm |
// |
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
@@ -289,8 +289,7 @@ |
this.Text = "Rule Editor"; |
this.groupBox1.ResumeLayout(false); |
this.groupBox2.ResumeLayout(false); |
this.groupBox7.ResumeLayout(false); |
this.groupBox7.PerformLayout(); |
this.groupBox2.PerformLayout(); |
this.groupBox6.ResumeLayout(false); |
this.groupBox6.PerformLayout(); |
this.groupBox5.ResumeLayout(false); |
@@ -317,7 +316,6 @@ |
private System.Windows.Forms.TextBox WindowTop; |
private System.Windows.Forms.GroupBox groupBox3; |
private System.Windows.Forms.TextBox WindowLeft; |
private System.Windows.Forms.GroupBox groupBox7; |
private System.Windows.Forms.TextBox WindowTitle; |
private System.Windows.Forms.GroupBox groupBox8; |
private System.Windows.Forms.ListBox desktopWindowsListBox; |
@@ -328,5 +326,6 @@ |
private System.Windows.Forms.CheckBox ignoreWidthCheckBox; |
private System.Windows.Forms.CheckBox ignoreTopCheckBox; |
private System.Windows.Forms.CheckBox ignoreLeftCheckBox; |
private System.Windows.Forms.Button drawButton; |
} |
} |
/trunk/Widow/RuleEditForm.cs |
@@ -14,6 +14,8 @@ |
|
public MainForm Form { get; set; } |
|
public DrawOverlayForm DrawOverlayForm { get; set; } |
|
#endregion |
|
#region Constructors, Destructors and Finalizers |
@@ -364,5 +366,52 @@ |
} |
|
#endregion |
|
private void DrawButton_Click(object sender, EventArgs e) |
{ |
var selectedWindow = (Window) windowRulesListBox.SelectedItem; |
if (selectedWindow == null) |
{ |
return; |
} |
|
if (DrawOverlayForm != null) |
{ |
return; |
} |
|
DrawOverlayForm = new DrawOverlayForm(); |
DrawOverlayForm.WindowDrawn += DrawOverlayForm_WindowDrawn; |
DrawOverlayForm.Closed += DrawOverlayForm_Closed; |
DrawOverlayForm.Show(); |
|
} |
|
private void DrawOverlayForm_WindowDrawn(object sender, WindowDrawnEventArgs e) |
{ |
var selectedWindow = (Window) windowRulesListBox.SelectedItem; |
if (selectedWindow == null) |
{ |
return; |
} |
|
WindowLeft.Text = e.Left.ToString(); |
WindowTop.Text = e.Top.ToString(); |
WindowWidth.Text = e.Width.ToString(); |
WindowHeight.Text = e.Height.ToString(); |
|
selectedWindow.Left = e.Left; |
selectedWindow.Top = e.Top; |
selectedWindow.Width = e.Width; |
selectedWindow.Height = e.Height; |
} |
|
private void DrawOverlayForm_Closed(object sender, EventArgs e) |
{ |
DrawOverlayForm.Closed -= DrawOverlayForm_Closed; |
DrawOverlayForm.WindowDrawn -= DrawOverlayForm_WindowDrawn; |
DrawOverlayForm.Dispose(); |
DrawOverlayForm = null; |
} |
} |
} |