控制调整数学大小
好吧...所以我已经有了这个非常杀手级的屏幕截图系统,我已经使用了一段时间了...它几乎涉及创建一个有点透明的表单,可以自动调整大小以适合所有显示器...这给出了屏幕( s)“暗出”效果...然后,我有一个隐藏的“按钮”控件,其位置是在鼠标按下时设置的...然后,直到鼠标向上,按钮将实时调整大小以创建一个某种“选择”区域...按钮被授予完全透明以实现此效果。
源示例: http://db.tt/LWxfDB6 [也在下面发布]
我遇到了两个问题我相信,直接相关。
1.)多显示器的坐标关闭,它正确返回单击(突出显示)的坐标,但突出显示框(效果)通常位于错误的显示器上。
2.) 您只能从左上角选择--->右下角且不通用。
抱歉,如果我没有解释清楚,来源应该解释得更好。 预先感谢您收到的所有帮助。 :)
:MarkRect.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
命名空间 TW_Media_Chat_
{
公共部分类 MarkRect :表单
{
点点1;
点2;
公共马克矩形()
{
初始化组件();
// 以编程方式最大化所有监视器
Screen[] Screens = Screen.AllScreens;
int 全部宽度 = 0;
int 全部高度 = 0;
for (int index = 0;index < Screens.Length;index++)
{
AllWidth += Screens[index].Bounds.Width;
AllHeight += Screens[index].Bounds.Height;
}
this.Width = AllWidth;
this.Height = AllHeight;
}
private void Transparency_MouseDown(object sender, MouseEventArgs e)
{
button1.Visible = true;
button1.Location = Cursor.Position;
Point1 = Cursor.Position;
}
private void Transparency_MouseUp(object sender, MouseEventArgs e)
{
this.Visible = false;
Point2 = Cursor.Position;
AjaxChatBridge.AjaxVars.Point1 = Point1;
AjaxChatBridge.AjaxVars.Point2 = Point2;
this.Close();
}
private void MarkRect_MouseMove(object sender, MouseEventArgs e)
{
this.button1.Width = Cursor.Position.X - this.button1.Left;
this.button1.Height = Cursor.Position.Y - this.button1.Top;
}
}
}
:MarkRect.Designer.cs:
namespace TW_Media_Chat_
{
partial class MarkRect
{
///
/// Required designer variable.
///
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.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.Color.Lime;
this.button1.ForeColor = System.Drawing.Color.Lime;
this.button1.Location = new System.Drawing.Point(220, 172);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(19, 18);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = false;
this.button1.Visible = false;
//
// MarkRect
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(490, 406);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "MarkRect";
this.Opacity = 0.5D;
this.Text = "Transparency";
this.TopMost = true;
this.TransparencyKey = System.Drawing.Color.Lime;
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Transparency_MouseDown);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MarkRect_MouseMove);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Transparency_MouseUp);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
}
}
Ok... So I've got this pretty killer Screenshot system I've been using for a while... It pretty much involves creating a somewhat transparent Form that auto-sizes to fit all monitors... Which gives the screen(s) a "dark-out" effect... I then have a hidden "button" control whos position is set upon mouse-down... Then, until mouse-up, the button will resize in real-time to create a sort of "selection" area... The Button is granted full transparency to implement this effect.
Source Example: http://db.tt/LWxfDB6 [Also posted below]
I'm having two issues that are directly related, I believe.
1.) The coordinates are off for multimonitors, it properly returns the coordinates that are clicked upon (highlighted), but the highlight box (effect) is often on the wrong monitor.
2.) You can only select from top-left ---> bottom-right and not universal.
Sorry if I didn't explain it well, the source should explain better.
Thanks, in advance, for any and all help received. :)
:MarkRect.cs:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing.Imaging; using System.IO;
namespace TW_Media_Chat_ { public partial class MarkRect : Form { Point Point1; Point Point2; public MarkRect() { InitializeComponent(); // Programatically maximize to all monitors Screen[] Screens = Screen.AllScreens; int AllWidth = 0; int AllHeight = 0; for (int index = 0; index < Screens.Length; index++) { AllWidth += Screens[index].Bounds.Width; AllHeight += Screens[index].Bounds.Height; } this.Width = AllWidth; this.Height = AllHeight;
} private void Transparency_MouseDown(object sender, MouseEventArgs e) { button1.Visible = true; button1.Location = Cursor.Position; Point1 = Cursor.Position; } private void Transparency_MouseUp(object sender, MouseEventArgs e) { this.Visible = false; Point2 = Cursor.Position; AjaxChatBridge.AjaxVars.Point1 = Point1; AjaxChatBridge.AjaxVars.Point2 = Point2; this.Close(); } private void MarkRect_MouseMove(object sender, MouseEventArgs e) { this.button1.Width = Cursor.Position.X - this.button1.Left; this.button1.Height = Cursor.Position.Y - this.button1.Top; } }
}
:MarkRect.Designer.cs:
namespace TW_Media_Chat_ { partial class MarkRect { /// /// Required designer variable. /// 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.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.BackColor = System.Drawing.Color.Lime; this.button1.ForeColor = System.Drawing.Color.Lime; this.button1.Location = new System.Drawing.Point(220, 172); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(19, 18); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = false; this.button1.Visible = false; // // MarkRect // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Black; this.ClientSize = new System.Drawing.Size(490, 406); this.Controls.Add(this.button1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "MarkRect"; this.Opacity = 0.5D; this.Text = "Transparency"; this.TopMost = true; this.TransparencyKey = System.Drawing.Color.Lime; this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Transparency_MouseDown); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MarkRect_MouseMove); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Transparency_MouseUp); this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该更容易地实现控件调整大小逻辑:
void MarkRect_MouseMove(...)
{
var mouseX = Cursor.Position.X;
var OriginalMouseX = Point1.X;
}
You should implement control resizing logic easier:
void MarkRect_MouseMove(...)
{
var mouseX = Cursor.Position.X;
var originalMouseX = Point1.X;
}
You should post that code here. We are to lazy to go to your dropbox to see the code. There are easier questions to answer here.