Removed PictureBox to reduce the complexity.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1991 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-08-15 12:10:36 +00:00
parent 61f92926de
commit 1c4957db59
2 changed files with 25 additions and 35 deletions

View file

@ -23,7 +23,6 @@ namespace Greenshot.Forms {
/// <summary> /// <summary>
/// Designer variable used to keep track of non-visual components. /// Designer variable used to keep track of non-visual components.
/// </summary> /// </summary>
private System.Windows.Forms.PictureBox pictureBox;
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
@ -45,29 +44,20 @@ namespace Greenshot.Forms {
/// not be able to load this method if it was changed manually. /// not be able to load this method if it was changed manually.
/// </summary> /// </summary>
private void InitializeComponent() { private void InitializeComponent() {
this.pictureBox = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// pictureBox // pictureBox
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove);
this.pictureBox.Location = new System.Drawing.Point(0, 0); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
this.pictureBox.Name = "pictureBox"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.OnPaint);
this.pictureBox.Size = new System.Drawing.Size(0, 0); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnMouseUp);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
this.pictureBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PictureBoxMouseMove);
this.pictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PictureBoxMouseDown);
this.pictureBox.Paint += new System.Windows.Forms.PaintEventHandler(this.PictureBoxPaint);
this.pictureBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PictureBoxMouseUp);
// //
// CaptureForm // CaptureForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(0, 0); this.ClientSize = new System.Drawing.Size(0, 0);
this.Controls.Add(this.pictureBox);
this.Cursor = System.Windows.Forms.Cursors.Cross; this.Cursor = System.Windows.Forms.Cursors.Cross;
this.DoubleBuffered = true; this.DoubleBuffered = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
@ -77,7 +67,6 @@ namespace Greenshot.Forms {
this.TopMost = true; this.TopMost = true;
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CaptureFormKeyDown); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CaptureFormKeyDown);
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.CaptureFormKeyUp); this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.CaptureFormKeyUp);
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.Visible = false; this.Visible = false;
this.ResumeLayout(false); this.ResumeLayout(false);
} }

View file

@ -97,7 +97,7 @@ namespace Greenshot.Forms {
this.capture = capture; this.capture = capture;
this.windows = windows; this.windows = windows;
captureMode = capture.CaptureDetails.CaptureMode; this.captureMode = capture.CaptureDetails.CaptureMode;
// //
// The InitializeComponent() call is required for Windows Forms designer support. // The InitializeComponent() call is required for Windows Forms designer support.
@ -109,6 +109,7 @@ namespace Greenshot.Forms {
WindowDetails.RegisterIgnoreHandle(this.Handle); WindowDetails.RegisterIgnoreHandle(this.Handle);
// Unregister at close // Unregister at close
this.FormClosing += delegate { this.FormClosing += delegate {
LOG.Debug("Closing captureform");
WindowDetails.UnregisterIgnoreHandle(this.Handle); WindowDetails.UnregisterIgnoreHandle(this.Handle);
}; };
@ -118,7 +119,6 @@ namespace Greenshot.Forms {
cursorPos.Offset(-capture.ScreenBounds.X, -capture.ScreenBounds.Y); cursorPos.Offset(-capture.ScreenBounds.X, -capture.ScreenBounds.Y);
this.SuspendLayout(); this.SuspendLayout();
pictureBox.Image = capture.Image;
this.Bounds = capture.ScreenBounds; this.Bounds = capture.ScreenBounds;
this.ResumeLayout(); this.ResumeLayout();
@ -147,7 +147,7 @@ namespace Greenshot.Forms {
} else if (e.KeyCode == Keys.M) { } else if (e.KeyCode == Keys.M) {
// Toggle mouse cursor // Toggle mouse cursor
capture.CursorVisible = !capture.CursorVisible; capture.CursorVisible = !capture.CursorVisible;
pictureBox.Invalidate(); Invalidate();
} else if (e.KeyCode == Keys.Space) { } else if (e.KeyCode == Keys.Space) {
switch (captureMode) { switch (captureMode) {
case CaptureMode.Region: case CaptureMode.Region:
@ -157,17 +157,17 @@ namespace Greenshot.Forms {
captureMode = CaptureMode.Region; captureMode = CaptureMode.Region;
break; break;
} }
pictureBox.Invalidate(); Invalidate();
selectedCaptureWindow = null; selectedCaptureWindow = null;
PictureBoxMouseMove(this, new MouseEventArgs(MouseButtons.None, 0, Cursor.Position.X, Cursor.Position.Y, 0)); OnMouseMove(this, new MouseEventArgs(MouseButtons.None, 0, Cursor.Position.X, Cursor.Position.Y, 0));
} else if (e.KeyCode == Keys.Return && captureMode == CaptureMode.Window) { } else if (e.KeyCode == Keys.Return && captureMode == CaptureMode.Window) {
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }
} }
#endregion #endregion
#region pictureBox events #region events
void PictureBoxMouseDown(object sender, MouseEventArgs e) { void OnMouseDown(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Left) { if (e.Button == MouseButtons.Left) {
Point tmpCursorLocation = WindowCapture.GetCursorLocation(); Point tmpCursorLocation = WindowCapture.GetCursorLocation();
// As the cursorPos is not in Bitmap coordinates, we need to correct. // As the cursorPos is not in Bitmap coordinates, we need to correct.
@ -176,12 +176,12 @@ namespace Greenshot.Forms {
mX = tmpCursorLocation.X; mX = tmpCursorLocation.X;
mY = tmpCursorLocation.Y; mY = tmpCursorLocation.Y;
mouseDown = true; mouseDown = true;
PictureBoxMouseMove(this, e); OnMouseMove(this, e);
pictureBox.Invalidate(); Invalidate();
} }
} }
void PictureBoxMouseUp(object sender, MouseEventArgs e) { void OnMouseUp(object sender, MouseEventArgs e) {
if (mouseDown) { if (mouseDown) {
// If the mouse goes up we set down to false (nice logic!) // If the mouse goes up we set down to false (nice logic!)
mouseDown = false; mouseDown = false;
@ -198,7 +198,7 @@ namespace Greenshot.Forms {
// Go and process the capture // Go and process the capture
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} else { } else {
pictureBox.Invalidate(); Invalidate();
} }
} }
} }
@ -219,7 +219,7 @@ namespace Greenshot.Forms {
return currentMouse; return currentMouse;
} }
void PictureBoxMouseMove(object sender, MouseEventArgs e) { void OnMouseMove(object sender, MouseEventArgs e) {
Point lastPos = new Point(cursorPos.X, cursorPos.Y); Point lastPos = new Point(cursorPos.X, cursorPos.Y);
cursorPos = WindowCapture.GetCursorLocation(); cursorPos = WindowCapture.GetCursorLocation();
// Make sure the mouse coordinates are fixed, when pressing shift // Make sure the mouse coordinates are fixed, when pressing shift
@ -296,7 +296,7 @@ namespace Greenshot.Forms {
y1 -= measureWidth.Height + 10; y1 -= measureWidth.Height + 10;
} }
Rectangle invalidateRectangle = new Rectangle(x1,y1, x2-x1, y2-y1); Rectangle invalidateRectangle = new Rectangle(x1,y1, x2-x1, y2-y1);
pictureBox.Invalidate(invalidateRectangle); Invalidate(invalidateRectangle);
} else { } else {
if (captureMode == CaptureMode.Window) { if (captureMode == CaptureMode.Window) {
if (selectedCaptureWindow != null && !selectedCaptureWindow.Equals(lastWindow)) { if (selectedCaptureWindow != null && !selectedCaptureWindow.Equals(lastWindow)) {
@ -307,36 +307,37 @@ namespace Greenshot.Forms {
invalidateRectangle.Y -= SAFETY_SIZE/2; invalidateRectangle.Y -= SAFETY_SIZE/2;
invalidateRectangle.Width += SAFETY_SIZE; invalidateRectangle.Width += SAFETY_SIZE;
invalidateRectangle.Height += SAFETY_SIZE; invalidateRectangle.Height += SAFETY_SIZE;
pictureBox.Invalidate(invalidateRectangle); Invalidate(invalidateRectangle);
invalidateRectangle = new Rectangle(captureRect.Location, captureRect.Size); invalidateRectangle = new Rectangle(captureRect.Location, captureRect.Size);
invalidateRectangle.X -= SAFETY_SIZE/2; invalidateRectangle.X -= SAFETY_SIZE/2;
invalidateRectangle.Y -= SAFETY_SIZE/2; invalidateRectangle.Y -= SAFETY_SIZE/2;
invalidateRectangle.Width += SAFETY_SIZE; invalidateRectangle.Width += SAFETY_SIZE;
invalidateRectangle.Height += SAFETY_SIZE; invalidateRectangle.Height += SAFETY_SIZE;
pictureBox.Invalidate(invalidateRectangle); Invalidate(invalidateRectangle);
} }
} else { } else {
if (!conf.OptimizeForRDP) { if (!conf.OptimizeForRDP) {
if (verticalMove) { if (verticalMove) {
Rectangle before = GuiRectangle.GetGuiRectangle(0, lastPos.Y - 2, this.Width+2, 45); Rectangle before = GuiRectangle.GetGuiRectangle(0, lastPos.Y - 2, this.Width+2, 45);
Rectangle after = GuiRectangle.GetGuiRectangle(0, cursorPos.Y - 2, this.Width+2, 45); Rectangle after = GuiRectangle.GetGuiRectangle(0, cursorPos.Y - 2, this.Width+2, 45);
pictureBox.Invalidate(before); Invalidate(before);
pictureBox.Invalidate(after); Invalidate(after);
} }
if (horizontalMove) { if (horizontalMove) {
Rectangle before = GuiRectangle.GetGuiRectangle(lastPos.X - 2, 0, 75, this.Height+2); Rectangle before = GuiRectangle.GetGuiRectangle(lastPos.X - 2, 0, 75, this.Height+2);
Rectangle after = GuiRectangle.GetGuiRectangle(cursorPos.X -2, 0, 75, this.Height+2); Rectangle after = GuiRectangle.GetGuiRectangle(cursorPos.X -2, 0, 75, this.Height+2);
pictureBox.Invalidate(before); Invalidate(before);
pictureBox.Invalidate(after); Invalidate(after);
} }
} }
} }
} }
} }
void PictureBoxPaint(object sender, PaintEventArgs e) { void OnPaint(object sender, PaintEventArgs e) {
Graphics graphics = e.Graphics; Graphics graphics = e.Graphics;
Rectangle clipRectangle = e.ClipRectangle; Rectangle clipRectangle = e.ClipRectangle;
graphics.DrawImageUnscaled(capture.Image, Point.Empty);
// Only draw Cursor if it's (partly) visible // Only draw Cursor if it's (partly) visible
if (capture.Cursor != null && capture.CursorVisible && clipRectangle.IntersectsWith(new Rectangle(capture.CursorLocation, capture.Cursor.Size))) { if (capture.Cursor != null && capture.CursorVisible && clipRectangle.IntersectsWith(new Rectangle(capture.CursorLocation, capture.Cursor.Size))) {
graphics.DrawIcon(capture.Cursor, capture.CursorLocation.X, capture.CursorLocation.Y); graphics.DrawIcon(capture.Cursor, capture.CursorLocation.X, capture.CursorLocation.Y);