控制调整数学的大小

时间:2011-03-26 08:48:03

标签: c# multiple-monitors

好的...所以我有一个漂亮的杀手截屏系统我已经使用了一段时间......它几乎涉及创建一个有点透明的表格,自动调整尺寸以适合所有显示器......这给出了屏幕出现“暗影”效果......然后我有一个隐藏的“按钮”控件,当鼠标按下时设置位置......然后,直到鼠标按下,按钮将实时调整大小创建一种“选择”区域......授予Button完全透明以实现此效果。

来源示例: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;

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:

    }

    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;
    }
}

1 个答案:

答案 0 :(得分:1)

  1. 您应该更容易实现控件调整大小逻辑:

    void MarkRect_MouseMove(...) {     var mouseX = Cursor.Position.X;     var originalMouseX = Point1.X;

    button1.Left = Math.Min(mouseX, originalMouseX);
    button1.Width = Math.Abs(mouseX - originalMouseX);
    
    // the same for Y
    

    }

  2. 您应该在此处发布该代码。我们懒得去你的Dropbox看代码。这里有更容易回答的问题。