日期:2014-05-18 浏览次数:20955 次
#region 定义全局变量 //定义全局变量width,用来存放当前活动窗体的width static int width = 0; static int height = 0; static int count = 0; //分别声明四条虚线的起点与终点 static Point p1 = new Point(0, 10); static Point p2; static Point p3; static Point p4; static Point p5 = new Point(10, 0); static Point p6; static Point p7; static Point p8; //是否选中 static bool isClick = false; //设置字体颜色 Font font = new Font("宋体", 8); #endregion public Frm_Report() { InitializeComponent(); } private void Frm_Report_Load(object sender, EventArgs e) { //避免闪烁,使用辅助缓冲区 this.DoubleBuffered = true; //设置窗体最大化 this.WindowState = FormWindowState.Maximized; //实例化一个用户选择的打印机 PrintDialog _Dialog = new PrintDialog(); width = _Dialog.PrinterSettings.DefaultPageSettings.PaperSize.Width; //827 height = _Dialog.PrinterSettings.DefaultPageSettings.PaperSize.Height; //1169 p2 = new Point(width, 10); p3 = new Point(0, height - 100); p4 = new Point(width, height - 100); p6 = new Point(10, height); p7 = new Point(width - 10, 0); p8 = new Point(width - 10, height); } /// <summary> /// 鼠标左键按下 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Frm_Report_MouseDown(object sender, MouseEventArgs e) { //判断用户按下时,鼠标所在的区域在不在四条虚线上 if ((e.X - p1.X >= 0) && (e.X - p2.X <= 0)) { if (e.Y <= p1.Y + 5 && e.Y >= p1.Y - 5) { isClick = true; count = 1; Cursor.Current = Cursors.SizeNS; } if (e.Y <= p3.Y + 5 && e.Y >= p3.Y - 5) { isClick = true; count = 2; Cursor.Current = Cursors.SizeNS; } } if ((e.Y - p5.Y >= 0) && (e.Y - p6.Y <= 0)) { if (e.X <= p5.X + 5 && e.X >= p5.X - 5) { isClick = true; count = 3; Cursor.Current = Cursors.SizeWE; } if (e.X <= p7.X + 5 && e.X >= p7.X - 5) { isClick = true; count = 4; Cursor.Current = Cursors.SizeWE; } } } /// <summary> /// 鼠标左键按下且在按下的状态下拖动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Frm_Report_MouseMove(object sender, MouseEventArgs e) { this.Invalidate(); } /// <summary> /// 鼠标左键松开 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Frm_Report_MouseUp(object sender, MouseEventArgs e) { if (isClick) { //判断选中的是那条直线 if (count == 1) { if (e.Y >= 10 && e.Y <= height / 2 - 40) { p1.Y = e.Y; p2.Y = e.Y; } else if (e.Y < 10)