澳门微尼斯人手机版 1

原文:

对窗体加越界限制后,鼠标拖动窗体越界时,窗体不能动,鼠标位置可动,但窗体不再越界时,鼠标位置还能回到鼠标按下时相对窗体的坐标:
1、首先创建一个窗体Form1,然后在窗体上拖一个button1按钮(主要通过这个按钮来拖动窗体)

[简介]

越来越多的软件,开始采用云服务。

2、然后对按钮添加鼠标按下事件、鼠标移动事件和鼠标抬起事件,事件里面是对窗体和鼠标坐标的操作,整体代码如下:
using System.Drawing;
using System.Windows.Forms;
namespace 窗体越界鼠标还能回到初始坐标
{
    public partial class Form1 : System.Windows.Forms.Form
    {
        #region 变量定义
        public Point mainFormPosition;//主窗口左上角位置
        int workingAreaHeight = SystemInformation.WorkingArea.Height;
        int workingAreaWidth = SystemInformation.WorkingArea.Width;
        private Point relativetMousePosition;//鼠标相对窗体的相对坐标
        bool FirstLeft = false;//是否左边第一次按下时坐标
        bool FirstRight = false;//是否右边第一次按下时坐标
        bool FirstUp = false;//是否上边第一次按下时坐标
        bool FirstDown = false;//是否下边第一次按下时坐标
        bool isFirstDown =
true;//是否第一次按下,鼠标越界纠正时判断是否是第一次按下,不是按下后又拖动了
        bool isMoveOut = false;//是否拖出
        //这两个变量做差,差值为拖出的距离时软件弹出侧边
        int oldMove_X = 0;//侧边停靠拖出时起始坐标
        //上一个时刻、鼠标的位置
        private Point oldMousePosition;
        //当前时刻、鼠标的位置
        private Point currentMousePosition;
        //鼠标事件
        [System.Runtime.InteropServices.DllImport(“user32”)]
        private static extern int mouse_event(int dwFlags, int dx, int
dy, int cButtons, int dwExtraInfo);
        //移动鼠标
        const int MOUSEEVENTF_MOVE = 0x0001;
        //模拟鼠标左键按下
        const int MOUSEEVENTF_LEFTDOWN = 0x0002;
        //模拟鼠标左键抬起
        const int MOUSEEVENTF_LEFTUP = 0x0004;
        //模拟鼠标右键按下
        const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
        //模拟鼠标右键抬起
        const int MOUSEEVENTF_RIGHTUP = 0x0010;
        //模拟鼠标中键按下
        const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
        //模拟鼠标中键抬起
        const int MOUSEEVENTF_MIDDLEUP = 0x0040;
        //标示是否采用绝对坐标
        const int MOUSEEVENTF_ABSOLUTE = 0x8000;
        #endregion

作为一名专业程序化交易者,编程是一个程序员的基本功,本文是作者在做的一个期货CTP项目中有关K线绘图的一部分,偿试类MT4中图表
设计而写,在编写绘图时,查阅了相关资料,感觉还是用NPlot的这个图表控件比较好,特点是:免费,可以用于winform程序,而且速度比较快,可以实时动态显示图表数据,下面就进入主题.

云服务只是一个统称,可以分成三大类。

        #region 窗体初始化
        public Form1()
        {
            InitializeComponent();
        }
        #endregion

[内容]

澳门微尼斯人手机版 2

       
//————————-按钮button1鼠标事件—————————————————————
        #region 鼠标左键按下Button1按钮事件
        private void Button1_MouseDown(object sender, MouseEventArgs
e)
        {
            if (e.Button == MouseButtons.Left)
            {
                currentMousePosition = Control.MousePosition;
                oldMousePosition = currentMousePosition;  
//鼠标按下时、两个时刻的坐标变成一样,防止错误移动            
                mainFormPosition = Location;
                if
(isFirstDown)//鼠标按下时,记录第一次鼠标按下相对主窗体的坐标
                {
                    relativetMousePosition.X = currentMousePosition.X –
Location.X;
                    relativetMousePosition.Y = currentMousePosition.Y –
Location.Y;
                    isFirstDown = false;
                }
                if (isMoveOut)//鼠标按下时,记录拖出时的初始坐标
                {
                    oldMove_X = currentMousePosition.X;
                }
            }
        }
        #endregion

一,NPlot控件相关知识简介:

  • IaaS:基础设施服务,Infrastructure-as-a-service
  • PaaS:平台服务,Platform-as-a-service
  • SaaS:软件服务,Software-as-a-service

        #region 鼠标左键按住Button1按钮移动事件
        private void Button1_MouseMove(object sender, MouseEventArgs
e)
        {
            if (e.Button == MouseButtons.Left)
            {
                currentMousePosition = Control.MousePosition;
                if (currentMousePosition.X < relativetMousePosition.X
&& currentMousePosition.Y > relativetMousePosition.Y &&
currentMousePosition.Y < workingAreaHeight – this.ClientSize.Height +
relativetMousePosition.Y)//左边窗体越界坐标纠正
                {
                    mainFormPosition.X = 0;
                    mainFormPosition.Y += currentMousePosition.Y –
oldMousePosition.Y;
                    //保存上一个时刻的鼠标位置
                    oldMousePosition.Y = currentMousePosition.Y;
                    FirstLeft = true;
                }
                else if (currentMousePosition.X > workingAreaWidth –
this.ClientSize.Width + relativetMousePosition.X &&
currentMousePosition.Y > relativetMousePosition.Y &&
currentMousePosition.Y < workingAreaHeight – this.ClientSize.Height +
relativetMousePosition.Y)//右边窗体越界坐标纠正
                {
                    mainFormPosition.X = workingAreaWidth –
this.ClientSize.Width;
                    mainFormPosition.Y += currentMousePosition.Y –
oldMousePosition.Y;
                    //保存上一个时刻的鼠标位置
                    oldMousePosition.Y = currentMousePosition.Y;
                    FirstRight = true;
                }
                else if (currentMousePosition.Y <
relativetMousePosition.Y && currentMousePosition.X >
relativetMousePosition.X && currentMousePosition.X < workingAreaWidth

图表控件一直是很难找的,特别是免费又强大的。NPlot是一款非常难得的.Net平台下的图表控件,能做各种曲线图,柱状图,饼图,散点图,股票图等,而且它免费又开源,使用起来也非常符合程序员的习惯。唯一的缺点就是文档特别难找,难读。通过对其文档的阅读和对示例程序源代码的分析,现在将NPlot的基本概念整理如下:

它们有什么区别呢?

  • this.ClientSize.Width +
    relativetMousePosition.X)//上边窗体越界坐标纠正
                    {
                        mainFormPosition.Y = 0;
                        mainFormPosition.X += currentMousePosition.X –
    oldMousePosition.X;
                        //保存上一个时刻的鼠标位置
                        oldMousePosition.X = currentMousePosition.X;
                        FirstUp = true;
                    }
                    else if (currentMousePosition.Y > workingAreaHeight –
    this.ClientSize.Height + relativetMousePosition.Y &&
    currentMousePosition.X > relativetMousePosition.X &&
    currentMousePosition.X < workingAreaWidth – this.ClientSize.Width +
    relativetMousePosition.X)//下边窗体越界坐标纠正
                    {
                        mainFormPosition.Y = workingAreaHeight –
    this.ClientSize.Height;
                        mainFormPosition.X += currentMousePosition.X –
    oldMousePosition.X;
                        //保存上一个时刻的鼠标位置
                        oldMousePosition.X = currentMousePosition.X;
                        FirstDown = true;
                    }
                    else if (currentMousePosition.X <
    relativetMousePosition.X && currentMousePosition.Y <
    relativetMousePosition.Y)//左上角窗体越界坐标纠正
                    {
                        mainFormPosition.X = 0;
                        mainFormPosition.Y = 0;
                        mainFormPosition.X += currentMousePosition.X –
    oldMousePosition.X;
                        mainFormPosition.Y += currentMousePosition.Y –
    oldMousePosition.Y;
                        //保存上一个时刻的鼠标位置
                        oldMousePosition.X = currentMousePosition.X;
                        oldMousePosition.Y = currentMousePosition.Y;
                        FirstLeft = true;
                        FirstUp = true;
                    }
                    else if (currentMousePosition.X > workingAreaWidth –
    this.ClientSize.Width + relativetMousePosition.X &&
    currentMousePosition.Y <
    relativetMousePosition.Y)//右上角窗体越界坐标纠正
                    {
                        mainFormPosition.X = workingAreaWidth –
    this.ClientSize.Width;
                        mainFormPosition.Y = 0;
                        mainFormPosition.X += currentMousePosition.X –
    oldMousePosition.X;
                        mainFormPosition.Y += currentMousePosition.Y –
    oldMousePosition.Y;
                        //保存上一个时刻的鼠标位置
                        oldMousePosition.X = currentMousePosition.X;
                        oldMousePosition.Y = currentMousePosition.Y;
                        FirstRight = true;
                        FirstUp = true;
                    }
                    else if (currentMousePosition.X <
    relativetMousePosition.X && currentMousePosition.Y >
    workingAreaHeight – this.ClientSize.Height +
    relativetMousePosition.Y)//左下角窗体越界坐标纠正
                    {
                        mainFormPosition.X = 0;
                        mainFormPosition.Y = workingAreaHeight –
    this.ClientSize.Height;
                        mainFormPosition.X += currentMousePosition.X –
    oldMousePosition.X;
                        mainFormPosition.Y += currentMousePosition.Y –
    oldMousePosition.Y;
                        //保存上一个时刻的鼠标位置
                        oldMousePosition.X = currentMousePosition.X;
                        oldMousePosition.Y = currentMousePosition.Y;
                        FirstLeft = true;
                        FirstDown = true;
                    }
                    else if (currentMousePosition.X > workingAreaWidth –
    this.ClientSize.Width + relativetMousePosition.X &&
    currentMousePosition.Y > workingAreaHeight – this.ClientSize.Height +
    relativetMousePosition.Y)//右下角窗体越界坐标纠正
                    {
                        mainFormPosition.Y = workingAreaHeight –
    this.ClientSize.Height;
                        mainFormPosition.X = workingAreaWidth –
    this.ClientSize.Width;
                        mainFormPosition.X += currentMousePosition.X –
    oldMousePosition.X;
                        mainFormPosition.Y += currentMousePosition.Y –
    oldMousePosition.Y;
                        //保存上一个时刻的鼠标位置
                        oldMousePosition.X = currentMousePosition.X;
                        oldMousePosition.Y = currentMousePosition.Y;
                        FirstRight = true;
                        FirstDown = true;
                    }
                    if (FirstLeft)
                    {
                        currentMousePosition.X = relativetMousePosition.X;
                        FirstLeft = false;
    澳门微尼斯人手机版,                }
                    if (FirstRight)
                    {
                        currentMousePosition.X = workingAreaWidth –
    this.ClientSize.Width + relativetMousePosition.X;
                        FirstRight = false;
                    }
                    if (FirstUp)
                    {
                        currentMousePosition.Y = relativetMousePosition.Y;
                        FirstUp = false;
                    }
                    if (FirstDown)
                    {
                        currentMousePosition.Y = workingAreaHeight –
    this.ClientSize.Height + relativetMousePosition.Y;
                        FirstDown = false;
                    }
                    if (FirstLeft && FirstUp)
                    {
                        currentMousePosition.X = relativetMousePosition.X;
                        currentMousePosition.Y = relativetMousePosition.Y;
                        FirstLeft = false;
                        FirstUp = false;

 

IBM 的软件架构师 Albert Barron
曾经使用披萨作为比喻,解释这个问题。David
Ng
进一步引申,让它变得更准确易懂。

                }
                if (FirstRight && FirstUp)
                {
                    currentMousePosition.X = workingAreaWidth –
this.ClientSize.Width + relativetMousePosition.X;
                    currentMousePosition.Y = relativetMousePosition.Y;
                    FirstUp = false;
                    FirstRight = false;
                }
                if (FirstLeft && FirstDown)
                {
                    currentMousePosition.X = relativetMousePosition.X;
                    currentMousePosition.Y = workingAreaHeight –
this.ClientSize.Height + relativetMousePosition.Y;
                    FirstLeft = false;
                    FirstDown = false;
                }
                if (FirstRight && FirstDown)
                {
                    currentMousePosition.X = workingAreaWidth –
this.ClientSize.Width + relativetMousePosition.X;
                    currentMousePosition.Y = workingAreaHeight –
this.ClientSize.Height + relativetMousePosition.Y;
                    FirstRight = false;
                    FirstDown = false;
                }
                //对窗体进行移动
                mainFormPosition.X += currentMousePosition.X –
oldMousePosition.X;
                mainFormPosition.Y += currentMousePosition.Y –
oldMousePosition.Y;
                //保存上一个时刻的鼠标位置
                oldMousePosition = currentMousePosition;

   
NPlot的命名空间包括NPlot,NPlot.Bitmap,NPlot.Web,NPlot.Web.Design,NPlot.Windows等,其中最核心的,管理各种图表的类都属于NPlot命名空间,NPlot.Bitmap针对位图的管理,NPlot.Web,NPlot.Web.Design和NPlot.Windows则可视为NPlot图表在Web
Form和Windows
Form上的容器(PlotSurface2D)。这些容器可以拖到Form上,也可以位于其他容器之中。

请设想你是一个餐饮业者,打算做披萨生意。

                #region 越界处理
                if (mainFormPosition.X < 0)//左边越界
                {
                    mainFormPosition.X = 0;
                }
                else if (mainFormPosition.Y < 0)//上边越界
                {
                    mainFormPosition.Y = 0;
                }
                else if (mainFormPosition.X > workingAreaWidth –
this.ClientSize.Width)//右边越界
                {
                    mainFormPosition.X = workingAreaWidth –
this.ClientSize.Width;
                }
                else if (mainFormPosition.Y > workingAreaHeight –
this.ClientSize.Height)//下边越界
                {
                    mainFormPosition.Y = workingAreaHeight –
this.ClientSize.Height;
                }
                //更新主窗口位置
                Location = mainFormPosition;
                #endregion
            }
        }
        #endregion

 

澳门微尼斯人手机版 3

        #region 鼠标在按钮Button1抬起事件
        private void Button1_MouseUp(object sender, MouseEventArgs e)
        {
            isFirstDown = true;
           
//如果主窗体在这个位置,就判断允许主窗体在鼠标抬起后执行移动事件
            if (mainFormPosition.X == workingAreaWidth –
this.ClientSize.Width)
            {
                isMoveOut = false;
            }
            if (mainFormPosition.X == 0)
            {
                isMoveOut = false;
            }
        }
        #endregion
    }
}

   
要在应用程序中应用NPlot控件,首先要把所下载的NPlot.dll添加到.Net工程中。并将其添加到工具箱托盘中。添加方式为:在工具箱上单击右键,选择“选择项”,会出现“选择工具箱项”对话框,在“.Net
Frameworks组件”属性页,选择浏览,找到NPlot.dll添加到工具箱项。这时工具箱中会出现NPlot控件。在设计应用程序界面时,可以将其拖入应用程序界面,系统会在代码中自动创建一个PlotSurface2D对象。

你可以从头到尾,自己生产披萨,但是这样比较麻烦,需要准备的东西多,因此你决定外包一部分工作,采用他人的服务。你有三个方案。

动画效果如下:

 

(1)方案一:IaaS

 澳门微尼斯人手机版 4

发表评论

电子邮件地址不会被公开。 必填项已用*标注