/// <summary> /// 绘制栏目框 /// </summary> /// <param name="width">宽度</param> /// <param name="height">高度</param> /// <param name="_flag">栏目类型</param> /// <returns></returns> public static Bitmap LinBand(int width, int height, int _flag, int ly, int _num) { string[] band_text = new string[3] { "页头", "内容", "页脚" }; Pen blockPen = new Pen(Color.FromArgb(95, 166, 210), 1); blockPen.DashStyle = DashStyle.Dot; Bitmap _bmp = new Bitmap(width, height); Graphics g = Graphics.FromImage(_bmp); g.DrawLine(blockPen, 0, 20, width, 20); g.DrawLine(blockPen, 0, height - 20 - 1, width, height - 20 - 1); g.FillRectangle(new SolidBrush(Color.FromArgb(115, 246, 246, 246)), new Rectangle(new Point(0, 21), new Size(width, height - 42))); g.DrawImage(page_flag[_flag], 0, 0, 20, 20); g.DrawImage(EzRBuild.EzResource.band_move, width - 20, 1, 20, 20); g.DrawImage(EzRBuild.EzResource.band_size, width - 20, height - 20 - 1, 20, 20); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.DrawString( band_text[_flag] + "-区域:" + width + "," + (height - 42) + " 位置:0," + (ly - (_flag * 43) + _flag), system_Font, new SolidBrush(Color.FromArgb(150, 150, 150)), 22, 2); g.DrawString( "组件数:" + DraggableObjects.Where(count => count.Belong_Band == _num).Count(), system_Font, new SolidBrush(Color.FromArgb(150, 150, 150)), width - 120, height - 19); g.Dispose(); return(_bmp); }
/// <summary> /// 生成报表 /// </summary> /// <param name="_pageType">页面类型</param> public static void Report_generation(int _pageType) { Bitmap pgImage; report_Pages.Clear(); if (DraggableObjects.Count > 0) { Total_Page = 1; report_Pages.Clear(); var hasData = DraggableObjects.FindAll(data => data.ControlType == 4).Count(); if ((hasData > 0) && (data_Pool.data_Type != 0)) { OpenLink(data_Pool.data_Type); Set_DataTable(data_Pool.data_Type); int recordCount = dt.Rows.Count; bandHeight = DraggableBandObjects[1].Region.Height - 42 - 5; drawHeight = (DraggableBandObjects[2].Region.Bottom + 20 - 1 - DraggableBandObjects[2].Region.Height - 126) - (DraggableBandObjects[0].Region.Bottom - 60); listRecord = drawHeight / bandHeight; Total_Page = (int)Math.Ceiling((double)recordCount / listRecord); _pTotal_Page = Total_Page; } for (int i = 0; i < Total_Page; i++) { pgImage = new Bitmap((int)(PreViewPage_Area.Width * zoomScale), (int)(PreViewPage_Area.Height * zoomScale)); pgImage.SetResolution(96, 96); // 设置图像dpi为96 // 页头 var ReportHead = DraggableObjects.FindAll(head => head.Belong_Band == 0).ToList(); Draw_Control(pgImage, 0, i, ReportHead); //内容 var ReportContent = DraggableObjects.FindAll(content => content.Belong_Band == 1).ToList(); var HasData = ReportContent.FindAll(hd => hd.ControlType == 4).Count(); if (HasData > 0) { Draw_DataControl(pgImage, i, ReportContent); } else { Draw_Control(pgImage, 1, i, ReportContent); } // 页脚 var ReportFooter = DraggableObjects.FindAll(footer => footer.Belong_Band == 2).ToList(); Draw_Control(pgImage, 2, i, ReportFooter); report_Pages.Add(new Report_Page(i, pgImage)); } if (data_Pool.data_Type != -1) { CloseLink(data_Pool.data_Type); } } }
/// <summary> /// 输出到打印机 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void PrintDocument_PrintPage(object sender, PrintPageEventArgs e) { var hasData = DraggableObjects.FindAll(content => content.Belong_Band == 1 && content.ControlType == 4).Count(); if (hasData < 1) // 没有数据库打印 { noData_Pring(e); } else // 包含数据库打印 { hasData_Pring(e); } }
/// <summary> /// 设置右键菜单显示项 /// </summary> /// <param name="obj">在哪个控件内</param> /// <param name="_num">当前对象序号</param> public static void Set_ControlMenuItem(Control obj, int _num) { var _controls = DraggableObjects.Where(band => band.Belong_Band == band_Num).ToList(); if (_controls.Count < 2) { control_Menu.Items[10].Enabled = false; control_Menu.Items[11].Enabled = false; } else { control_Menu.Items[10].Enabled = true; control_Menu.Items[11].Enabled = true; } if (DraggableObjects[_num].Id == _controls[0].Id) { control_Menu.Items[11].Enabled = false; } else { control_Menu.Items[11].Enabled = true; } if (DraggableObjects[_num].Id == _controls[_controls.Count - 1].Id) { control_Menu.Items[10].Enabled = false; } else { control_Menu.Items[10].Enabled = true; } if (operationObject.Id != null) { control_Menu.Items[2].Enabled = true; } else { control_Menu.Items[2].Enabled = false; } }
// 数据库打印 private static void hasData_Pring(PrintPageEventArgs e) { var objects = DraggableObjects.FindAll(head => head.isContent != false).ToList(); for (int p = 0; p < listRecord; p++) { for (int i = 0; i < objects.Count; i++) { if (objects[i].isContent) { string _txt = ""; int _record = ((page_Scope[_pnum] - 1) * listRecord) + p; if (_record > dt.Rows.Count - 1) { break; } Size contrl_Size = new Size(objects[i].Region.Width - 6, objects[i].Region.Height - 6); int _top = 0; if (objects[i].Belong_Band == 0) { _top = objects[i].Region.Top - 20 + 7; //_top += 4; } if (objects[i].Belong_Band == 1) { _top = (DraggableBandObjects[0].Region.Bottom - 60) + (objects[i].Region.Top - DraggableBandObjects[1].Region.Top); } if (objects[i].Belong_Band == 2) { _top = (DraggableBandObjects[2].Region.Bottom + 20 - 1 - DraggableBandObjects[2].Region.Height - 126) + (objects[i].Region.Top - DraggableBandObjects[2].Region.Top); } _top += p * bandHeight; e.Graphics.FillRectangle(new SolidBrush(objects[i].Field_BackColor), new Rectangle(objects[i].Region.Left + 3, _top, contrl_Size.Width, contrl_Size.Height)); if ((objects[i].ControlType == 1) || (objects[i].ControlType == 4) || (objects[i].ControlType == 5) || (objects[i].ControlType == 6)) { if (objects[i].ControlType == 1) { _txt = objects[i].Field_Text; } if (objects[i].ControlType == 4) { _txt = dt.Rows[_record][objects[i].Field_Text].ToString(); } if (objects[i].ControlType == 5) { _txt = objects[i].Field_Text.Replace("xx", Total_Page.ToString()); _txt = _txt.Replace("x", page_Scope[_pnum].ToString()); } if (objects[i].ControlType == 6) { _txt = objects[i].Field_Calculate; _txt = _txt.Replace("[", "").Replace("\"]", ""); string[] splitString = _txt.Split(new string[] { "\"" }, StringSplitOptions.None); _txt = Field_Calculate(splitString[0], splitString[1]); } Font fnt_Text = new Font(objects[i].Field_TextFont, objects[i].Field_TextFontSize, objects[i].Field_TextFontStyle, GraphicsUnit.Pixel); Point point_text = Text_point(objects[i].Field_Align, contrl_Size.Width - 1, contrl_Size.Height - 1, e.Graphics, _txt, fnt_Text); DrawText.printDrawString(e.Graphics, _txt, fnt_Text, objects[i].Field_ControlColor, new Rectangle(point_text.X + objects[i].Region.Left + 3, point_text.Y + _top, contrl_Size.Width - 1, contrl_Size.Height - 1)); } if (objects[i].ControlType == 2) { if (objects[i].Field_ImgZoom == 1) { e.Graphics.DrawImage(objects[i].Field_Img, objects[i].Region.Left + 3, _top, objects[i].Region.Width - 7, objects[i].Region.Height - 7); } else { Point point_img = Image_point(objects[i], objects[i].Region.Width - 7, objects[i].Region.Height - 7); var Img_desRect = new Rectangle(point_img.X + objects[i].Region.Left + 3, point_img.Y + _top, objects[i].Region.Width - 7, objects[i].Region.Height - 7); var Img_srcRect = new Rectangle(0, 0, objects[i].Region.Width - 7, objects[i].Region.Height - 7); e.Graphics.DrawImage(objects[i].Field_Img, Img_desRect, Img_srcRect, GraphicsUnit.Pixel); } } if (objects[i].ControlType == 3) { int _size = 1, _sizeX = 0, _sizeY = 0; if (objects[i].Region.Width > objects[i].Region.Height) { _size = objects[i].Region.Height; _sizeX = (objects[i].Region.Width - _size) / 2; _sizeY = 0; } else { _size = objects[i].Region.Width; _sizeX = 0; _sizeY = (objects[i].Region.Height - _size) / 2; } Bitmap _bmp = new Bitmap(_size * 2, _size * 2); DrawText.DrawFontAwesome(_bmp, shaps_type[objects[i].Field_Shape], _size - 3, objects[i].Field_ControlColor, new Point(_sizeX, _sizeY), false); e.Graphics.DrawImage(_bmp, new Point(objects[i].Region.Left + 3, _top)); _bmp.Dispose(); } Pen pen = new Pen(objects[i].Field_LineColor, objects[i].Field_LineThickness); pen.DashStyle = objects[i].Field_LineType; if (objects[i].Field_BoxLine[5]) { for (int t = 0; t < 4; t++) { objects[i].Field_BoxLine[t] = true; } } if (objects[i].Field_BoxLine[0]) { e.Graphics.DrawLine(pen, objects[i].Region.Left + 3, _top + contrl_Size.Height, objects[i].Region.Left + 3 + contrl_Size.Width, _top + contrl_Size.Height); } if (objects[i].Field_BoxLine[1]) { e.Graphics.DrawLine(pen, objects[i].Region.Left + 3, _top, objects[i].Region.Left + 3 + contrl_Size.Width, _top); } if (objects[i].Field_BoxLine[2]) { e.Graphics.DrawLine(pen, objects[i].Region.Left + 3, _top, objects[i].Region.Left + 3, _top + contrl_Size.Height); } if (objects[i].Field_BoxLine[3]) { e.Graphics.DrawLine(pen, objects[i].Region.Left + 3 + contrl_Size.Width, _top, objects[i].Region.Left + 3 + contrl_Size.Width, _top + contrl_Size.Height); } if (objects[i].Field_BoxLine[6]) { e.Graphics.DrawLine(pen, objects[i].Region.Left + 3, _top, objects[i].Region.Left + 3 + contrl_Size.Width - 1, _top + contrl_Size.Height - 1); } if (objects[i].Field_BoxLine[7]) { e.Graphics.DrawLine(pen, objects[i].Region.Left + 3 + contrl_Size.Width - 1, _top, objects[i].Region.Left + 3, _top + contrl_Size.Height - 1); } } } } _pnum += 1; if (_pnum > page_Scope.Count - 1) { e.HasMorePages = false; } else { e.HasMorePages = true; } }
/// <summary> /// 查找文本 /// </summary> /// <param name="_search">包含文字</param> public static void search_Text(string _search) { setSearchs.Clear(); var objects = DraggableObjects.FindAll(head => head.Belong_Band == 1).ToList(); var HasData = objects.FindAll(hd => hd.ControlType == 4).Count(); if (HasData > 0) { for (int _num = 0; _num < Total_Page; _num++) //////第几页? { for (int p = 0; p < listRecord; p++) { for (int i = 0; i < objects.Count; i++) { if (objects[i].isContent) { string _txt = ""; int _record = (_num * listRecord) + p; if (_record > dt.Rows.Count - 1) { break; } if ((objects[i].ControlType == 1) || (objects[i].ControlType == 4) || (objects[i].ControlType == 5)) { if (objects[i].ControlType == 1) { _txt = objects[i].Field_Text; } if (objects[i].ControlType == 4) { _txt = dt.Rows[_record][objects[i].Field_Text].ToString(); } if (objects[i].ControlType == 5) { _txt = objects[i].Field_Text.Replace("xx", Total_Page.ToString()); _txt = _txt.Replace("x", (_num + 1).ToString()); } } // 找到文字,颜色覆盖 if (_txt.IndexOf(_search) > -1) { RbControls_TransparentRect _SearchRect = new RbControls_TransparentRect(); _SearchRect.BackColor = Color.Red; //颜色 _SearchRect.Radius = 1; //圆角 角度 _SearchRect.ShapeBorderStyle = RbControls_TransparentRect.ShapeBorderStyles.ShapeBSNone; //边框 _SearchRect.Size = new Size((int)Math.Ceiling((objects[i].Region.Width - 6) * zoomScale), (int)Math.Ceiling((objects[i].Region.Height - 6) * zoomScale)); //大小 int _top = (DraggableBandObjects[0].Region.Bottom - 60) + (objects[i].Region.Top - DraggableBandObjects[1].Region.Top); _SearchRect.Location = new Point((int)((objects[i].Region.Left + 3) * zoomScale), (int)((_top + p * bandHeight) * zoomScale)); //位置 _SearchRect.Opacity = 120; //透明度 RBuild_Preview.panel_Page[_num].Controls.Add(_SearchRect); setSearchs.Add(new Searchs(_SearchRect)); } } } } } } else { for (int i = 0; i < objects.Count; i++) { if (objects[i].isContent) { string _txt = ""; if (objects[i].ControlType == 1) { if (objects[i].ControlType == 1) { _txt = objects[i].Field_Text; } } // 找到文字,颜色覆盖 if (_txt.IndexOf(_search) > -1) { RbControls_TransparentRect _SearchRect = new RbControls_TransparentRect(); _SearchRect.BackColor = Color.Red; //颜色 _SearchRect.Radius = 1; //圆角 角度 _SearchRect.ShapeBorderStyle = RbControls_TransparentRect.ShapeBorderStyles.ShapeBSNone; //边框 _SearchRect.Size = new Size((int)Math.Ceiling((objects[i].Region.Width - 6) * zoomScale), (int)Math.Ceiling((objects[i].Region.Height - 6) * zoomScale)); //大小 int _top = (DraggableBandObjects[0].Region.Bottom - 60) + (objects[i].Region.Top - DraggableBandObjects[1].Region.Top); _SearchRect.Location = new Point((int)((objects[i].Region.Left + 3) * zoomScale), (int)(_top * zoomScale)); //位置 _SearchRect.Opacity = 120; //透明度 RBuild_Preview.panel_Page[0].Controls.Add(_SearchRect); setSearchs.Add(new Searchs(_SearchRect)); } } } } }
private void acceptSet_Click(object sender, EventArgs e) { Label pL = (Label)sender; if ((int)pL.Tag == 1) { setBand_Form._formObject.Close(); } else { for (int i = 0; i < 3; i++) { for (int t = 0; t < 2; t++) { if (select_label[i, t].select) { if (t == 0) { int _maxHeight = 43; var DraggableMaxBottom = DraggableObjects.Where(bottom => bottom.Belong_Band == i).OrderByDescending(sort => sort.Region.Bottom).ToList(); if (DraggableMaxBottom.Count > 0) { _maxHeight = (DraggableMaxBottom[0].Region.Bottom - DraggableBandObjects[i].Region.Top) + 20; } DraggableBandObjects[i].Region = new Rectangle(0, DraggableBandObjects[i].Region.Top, DraggableBandObjects[i].Region.Width, _maxHeight); Print_PageType.Invalidate(); ReportChange_Flag = true; setBand_Form._formObject.Close(); } if (t == 1) { int _top = 0, _height = 43; if (i == 0) { _top = 0; _height = DraggableBandObjects[1].Region.Top - DraggableBandObjects[0].Region.Bottom + DraggableBandObjects[0].Region.Height; } if (i == 1) { _top = DraggableBandObjects[0].Region.Bottom; _height = DraggableBandObjects[2].Region.Top - DraggableBandObjects[1].Region.Bottom + DraggableBandObjects[1].Region.Height + DraggableBandObjects[1].Region.Top - DraggableBandObjects[0].Region.Bottom; } if (i == 2) { _top = DraggableBandObjects[1].Region.Bottom; _height = Print_PageType.Height - DraggableBandObjects[2].Region.Bottom + DraggableBandObjects[2].Region.Height + DraggableBandObjects[2].Region.Top - DraggableBandObjects[1].Region.Bottom; } DraggableBandObjects[i].Region = new Rectangle(0, _top, DraggableBandObjects[i].Region.Width, _height); Print_PageType.Invalidate(); ReportChange_Flag = true; setBand_Form._formObject.Close(); } } } if ((attribute_Input[i].textBox.Text != null) && (attribute_Input[i].textBox.Text != "")) { int _maxHeight = int.Parse(attribute_Input[i].textBox.Text) + 42; if (_maxHeight < 43) { _maxHeight = 43; } var DraggableMaxBottom = DraggableObjects.Where(bottom => bottom.Belong_Band == i).OrderByDescending(sort => sort.Region.Bottom).ToList(); if (DraggableMaxBottom.Count > 0) { _maxHeight = (DraggableMaxBottom[0].Region.Bottom - DraggableBandObjects[i].Region.Top) + 20; } DraggableBandObjects[i].Region = new Rectangle(0, DraggableBandObjects[i].Region.Top, DraggableBandObjects[i].Region.Width, _maxHeight); Print_PageType.Invalidate(); ReportChange_Flag = true; setBand_Form._formObject.Close(); } } } }
// 打开文件 public static void Open_File() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "报表文件(*.rpt)|*.rpt"; ofd.FilterIndex = 1; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { if (ReportChange_Flag) { DialogResult _save = MessageBox.Show("是否保存报表文件?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (_save.ToString().Equals("Yes")) { Save_File(); } if (_save.ToString().Equals("Cancel")) { return; } } SerializerObject.Clear(); string localFilePath = ofd.FileName.ToString(); ReportFile_Name.Text = localFilePath; try { SerializerObject = Serializer.FileToObject <List <OperationObject> >(localFilePath); DraggableObjects.Clear(); recordObjects.Clear(); control_Num = -1; int _select = 0; for (int i = 0; i < SerializerObject.Count; i++) { Draggable draggableBlock = new Draggable(SerializerObject[i].Region.Left, SerializerObject[i].Region.Top, SerializerObject[i].ControlType); draggableBlock.Id = SerializerObject[i].Id; draggableBlock.Belong_Band = SerializerObject[i].Belong_Band; draggableBlock.Region = SerializerObject[i].Region; draggableBlock.isContent = SerializerObject[i].isContent; if (SerializerObject[i].ControlType == 2) { draggableBlock.Field_Img = Base64StringToImage(SerializerObject[i].Field_ImgBase64); } draggableBlock.Field_Text = SerializerObject[i].Field_Text; draggableBlock.Field_Calculate = SerializerObject[i].Field_Calculate; draggableBlock.Field_TextFont = SerializerObject[i].Field_TextFont; draggableBlock.Field_TextFontSize = SerializerObject[i].Field_TextFontSize; draggableBlock.Field_TextFontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), SerializerObject[i].Field_TextFontStyleString); draggableBlock.Field_Align = SerializerObject[i].Field_Align; draggableBlock.Field_ImgZoom = SerializerObject[i].Field_ImgZoom; for (int t = 0; t < 8; t++) { draggableBlock.Field_BoxLine[t] = SerializerObject[i].Field_BoxLine[t]; } draggableBlock.Field_LineColor = ColorTranslator.FromHtml(SerializerObject[i].Field_LineColorString); draggableBlock.Field_LineThickness = SerializerObject[i].Field_LineThickness; draggableBlock.Field_LineType = SerializerObject[i].Field_LineType; draggableBlock.Field_Shape = SerializerObject[i].Field_Shape; draggableBlock.Field_ControlColor = ColorTranslator.FromHtml(SerializerObject[i].Field_ControlColorString); draggableBlock.Field_BackColor = ColorTranslator.FromHtml(SerializerObject[i].Field_BackColorString); DraggableObjects.Add(draggableBlock); control_Num = i; if (i == SerializerObject.Count - 1) { _select = 1; } DraggableObjects[i].Setimage = LinBox(SerializerObject[i].Region.Width, SerializerObject[i].Region.Height, _select, SerializerObject[i].ControlType, i); } page_TypeFace = SerializerObject[0].page_Type; _pgselect = page_TypeFace.Page_Type; for (int i = 0; i < 3; i++) { DraggableBandObjects[i].Region = SerializerObject[0].Band_Region[i]; } Print_PageType.Size = page_TypeFace.Page_Area; int _iLeft = (page_Container.Width / 2) - (page_TypeFace.Page_Area.Width / 2); if (_iLeft < 0) { _iLeft = 0; } page_Install.Size = new Size(page_TypeFace.Page_Area.Width + 20, page_TypeFace.Page_Area.Height + 20); page_Install.Location = new Point(_iLeft, 0); // 设置预览页面大小 PreViewPage_Area = new Size(page_TypeFace.Page_Area.Width, page_TypeFace.Page_Area.Height - 126); Print_PageType.Invalidate(); RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType); ReportChange_Flag = false; } catch { MessageBox.Show("报表打开错误!"); } } }
// 保存文件 public static void New_File() { if (ReportChange_Flag) { DialogResult _save = MessageBox.Show("是否保存报表文件?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (_save.ToString().Equals("Yes")) { Save_File(); } if (_save.ToString().Equals("Cancel")) { return; } } ReportFile_Name.Text = "MyReport.rpt"; SerializerObject.Clear(); DraggableObjects.Clear(); recordObjects.Clear(); control_Num = -1; page_Container.VerticalScroll.Value = 0; page_Container.HorizontalScroll.Value = 0; page_TypeFace.Page_Type = 4; page_TypeFace.Page_Direction = 0; Set_PrintPageType(4, page_TypeFace.Page_Direction); int height = 120; int ly = 0; for (int i = 0; i < 3; i++) { if (i == 0) { height = 120; ly = 0; } else if (i == 1) { height = 250; ly = 128; } else if (i == 2) { height = 120; ly = page_TypeFace.Page_Area.Height - height; } DraggableBandObjects[i].Region = new Rectangle(0, ly, page_TypeFace.Page_Area.Width, height); } page_Install.Size = new Size(page_TypeFace.Page_Area.Width + 20, page_TypeFace.Page_Area.Height + 20); int _iLeft = (page_Container.Width / 2) - (page_TypeFace.Page_Area.Width / 2); if (_iLeft < 0) { _iLeft = 0; } page_Install.Location = new Point(_iLeft, 0); page_Install.Invalidate(); Print_PageType.Size = page_TypeFace.Page_Area; Print_PageType.Invalidate(); ReportChange_Flag = false; }
public static void PageType_MouseMove(object sender, MouseEventArgs e) { PanelEx pL = (PanelEx)sender; A4location_XY = e.Location; for (int i = 0; i < 3; i++) { if (DraggableBandObjects[i].Region.Contains(e.Location)) { band_Num = i; break; } } if (control_Type != -1) { if ((e.X >= 0) && (e.X <= Print_PageType.Width) && (e.Y >= DraggableBandObjects[band_Num].Region.Y + 20) && (e.Y <= DraggableBandObjects[band_Num].Region.Bottom - 23)) { pL.Cursor = custom_MouseCursor(control_icon[control_Type - 1], 5, 5); } } else { if ((control_Num > -1) && (band_state == -1)) { if (DraggableObjects[control_Num].IsDragging) { if (CursorFlag == 9) { int set_x = DraggableObjects[control_Num].Region.Left + e.X - DraggableObjects[control_Num].DraggingPoint.X; int set_y = DraggableObjects[control_Num].Region.Top + e.Y - DraggableObjects[control_Num].DraggingPoint.Y; if (set_x < 0) { set_x = 0; } if ((set_x + DraggableObjects[control_Num].Region.Width) > Print_PageType.Width) { set_x = Print_PageType.Width - DraggableObjects[control_Num].Region.Width; } if (set_y < primary_BandTop + 20) { set_y = primary_BandTop + 20; } if ((set_y + DraggableObjects[control_Num].Region.Height) > (primary_BandBottom - 20)) { set_y = (primary_BandBottom - 20) - DraggableObjects[control_Num].Region.Height; } DraggableObjects[control_Num].Region = new Rectangle(set_x, set_y, DraggableObjects[control_Num].Region.Width, DraggableObjects[control_Num].Region.Height); DraggableObjects[control_Num].DraggingPoint = e.Location; } else { switch (CursorFlag) { case 0: if (sizeWidth > 14) { sizeX = e.Location.X; } if (sizeHeight > 14) { sizeY = e.Location.Y; } if (sizeX >= 0) { sizeWidth = periX - e.Location.X; } if (sizeY >= (primary_BandTop + 20)) { sizeHeight = periY - e.Location.Y; } break; case 1: if (sizeWidth > 14) { sizeX = e.Location.X; } sizeY = DraggableObjects[control_Num].Region.Top; if (sizeX >= 0) { sizeWidth = periX - e.Location.X; } sizeHeight = e.Location.Y - DraggableObjects[control_Num].Region.Top; break; case 2: sizeX = DraggableObjects[control_Num].Region.Left; if (sizeHeight > 14) { sizeY = e.Location.Y; } sizeWidth = e.Location.X - DraggableObjects[control_Num].Region.Left; if (sizeY >= (primary_BandTop + 20)) { sizeHeight = periY - e.Location.Y; } break; case 3: sizeX = DraggableObjects[control_Num].Region.Left; sizeY = DraggableObjects[control_Num].Region.Top; sizeWidth = e.Location.X - DraggableObjects[control_Num].Region.Left; sizeHeight = e.Location.Y - DraggableObjects[control_Num].Region.Top; break; case 4: if (sizeWidth > 14) { sizeX = e.Location.X; } sizeY = DraggableObjects[control_Num].Region.Top; if (sizeX >= 0) { sizeWidth = periX - e.Location.X; } sizeHeight = DraggableObjects[control_Num].Region.Height; break; case 5: sizeX = DraggableObjects[control_Num].Region.Left; sizeY = DraggableObjects[control_Num].Region.Top; sizeWidth = e.Location.X - DraggableObjects[control_Num].Region.Left; sizeHeight = DraggableObjects[control_Num].Region.Height; break; case 6: sizeX = DraggableObjects[control_Num].Region.Left; if (sizeHeight > 14) { sizeY = e.Location.Y; } sizeWidth = DraggableObjects[control_Num].Region.Width; if (sizeY >= (primary_BandTop + 20)) { sizeHeight = periY - e.Location.Y; } break; case 7: sizeX = DraggableObjects[control_Num].Region.Left; sizeY = DraggableObjects[control_Num].Region.Top; sizeWidth = DraggableObjects[control_Num].Region.Width; sizeHeight = e.Location.Y - DraggableObjects[control_Num].Region.Top; break; default: break; } if (sizeWidth < 14) { sizeWidth = 14; } if (sizeHeight < 14) { sizeHeight = 14; } if (sizeX < 0) { sizeX = 0; } if ((sizeX + sizeWidth) > Print_PageType.Width) { sizeWidth = Print_PageType.Width - sizeX; sizeX = Print_PageType.Width - sizeWidth; } if (sizeY < (primary_BandTop + 20)) { sizeY = primary_BandTop + 20; } if ((sizeHeight + DraggableObjects[control_Num].Region.Top) > (primary_BandBottom - 20)) { sizeHeight = (primary_BandBottom - 20) - DraggableObjects[control_Num].Region.Top; } DraggableObjects[control_Num].Setimage = LinBox(sizeWidth, sizeHeight, 1, DraggableObjects[control_Num].ControlType, control_Num); DraggableObjects[control_Num].Region = new Rectangle(sizeX, sizeY, sizeWidth, sizeHeight); } pL.Invalidate(); View_Info = true; } else { if (DraggableObjects[control_Num].Region.Contains(e.Location)) { SetCursorArea(control_Num); for (int i = 0; i < 8; i++) { if ((e.X >= DraggableObjects[control_Num].Region.Left + CursorArea[i].X) && (e.X <= DraggableObjects[control_Num].Region.Left + CursorArea[i].X + 7) && (e.Y >= DraggableObjects[control_Num].Region.Top + CursorArea[i].Y) && (e.Y <= DraggableObjects[control_Num].Region.Top + CursorArea[i].Y + 7)) { periX = DraggableObjects[control_Num].Region.Left + DraggableObjects[control_Num].Region.Width; // 记录原始位置 periY = DraggableObjects[control_Num].Region.Top + DraggableObjects[control_Num].Region.Height; // 记录原始位置 CursorFlag = i; if ((i == 6) || (i == 7)) // 上下中 { pL.Cursor = Cursors.SizeNS; break; } if ((i == 0) || (i == 3)) // 左上右下 { pL.Cursor = Cursors.SizeNWSE; break; } if ((i == 1) || (i == 2)) // 左下右上 { pL.Cursor = Cursors.SizeNESW; break; } if ((i == 4) || (i == 5)) // 左右中 { pL.Cursor = Cursors.SizeWE; break; } } pL.Cursor = Cursors.SizeAll; CursorFlag = 9; } } else { pL.Cursor = Cursors.Default; CursorFlag = -1; } } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bool is_Draggin = true; if (CursorFlag == -1) { for (int i = 0; i < 3; i++) { is_Draggin = true; if ((DraggableBandObjects[i].IsDragging) || (DraggableBandObjects[i].IsSize)) { is_Draggin = false; break; } } if (is_Draggin) { band_state = -1; if ((e.X >= Print_PageType.Width - 20) && (e.X <= Print_PageType.Width)) { if ((e.Y >= DraggableBandObjects[band_Num].Region.Top) && (e.Y <= DraggableBandObjects[band_Num].Region.Top + 20)) { band_state = 0; DraggableBandObjects[band_Num].DraggingPoint = e.Location; pL.Cursor = Cursors.SizeAll; } else if ((e.Y <= DraggableBandObjects[band_Num].Region.Bottom) && (e.Y >= DraggableBandObjects[band_Num].Region.Bottom - 20)) { band_state = 1; DraggableBandObjects[band_Num].DraggingPoint = e.Location; pL.Cursor = Cursors.SizeNS; } } } } if ((control_Num < 0) && (band_state == -1)) { pL.Cursor = Cursors.Default; } if (DraggableBandObjects[band_Num].IsDragging) { int set_y = DraggableBandObjects[band_Num].Region.Top + e.Y - DraggableBandObjects[band_Num].DraggingPoint.Y; if (band_Num == 0) { if (set_y < 0) { set_y = 0; } if (set_y + DraggableBandObjects[0].Region.Height > DraggableBandObjects[1].Region.Top) { set_y = DraggableBandObjects[1].Region.Top - DraggableBandObjects[0].Region.Height; } } else if (band_Num == 1) { if (set_y < DraggableBandObjects[0].Region.Bottom) { set_y = DraggableBandObjects[0].Region.Bottom; } if (set_y + DraggableBandObjects[1].Region.Height > DraggableBandObjects[2].Region.Top) { set_y = DraggableBandObjects[2].Region.Top - DraggableBandObjects[1].Region.Height; } } else if (band_Num == 2) { if (set_y < DraggableBandObjects[1].Region.Bottom) { set_y = DraggableBandObjects[1].Region.Bottom; } if (set_y + DraggableBandObjects[2].Region.Height > Print_PageType.Height) { set_y = Print_PageType.Height - DraggableBandObjects[2].Region.Height; } } DraggableBandObjects[band_Num].Region = new Rectangle( 0, set_y, DraggableBandObjects[band_Num].Region.Width, DraggableBandObjects[band_Num].Region.Height ); DraggableBandObjects[band_Num].DraggingPoint = e.Location; int sync_y = (DraggableBandObjects[band_Num].Region.Top - primary_BandTop); if (control_Num > -1) { var DraggableSync = DraggableObjects.Where(sync => sync.Belong_Band == band_Num).ToList(); for (int i = 0; i < DraggableSync.Count; i++) { DraggableSync[i].Region = new Rectangle( DraggableSync[i].Region.Left, DraggableSync[i].Primary + sync_y, DraggableSync[i].Region.Width, DraggableSync[i].Region.Height ); } View_Info = true; } pL.Invalidate(); } else if (DraggableBandObjects[band_Num].IsSize) { int set_height = e.Location.Y - DraggableBandObjects[band_Num].Region.Top; if (set_height < 43) { set_height = 43; } DraggableBandObjects[band_Num].Region = new Rectangle( 0, DraggableBandObjects[band_Num].Region.Top, DraggableBandObjects[band_Num].Region.Width, set_height ); pL.Invalidate(); } } }
public static void PageType_Click(object sender, EventArgs e) { PanelEx pL = (PanelEx)sender; bool is_band = false; for (int i = 0; i < 3; i++) { is_band = false; if ((A4location_XY.X >= 0) && (A4location_XY.X <= Print_PageType.Width) && (A4location_XY.Y >= DraggableBandObjects[i].Region.Top + 20) && (A4location_XY.Y <= DraggableBandObjects[i].Region.Bottom - 20)) { is_band = true; break; } } if ((control_Type != -1) && (is_band)) { if (control_Num > -1) { DraggableObjects[control_Num].Setimage = LinBox( DraggableObjects[control_Num].Region.Width, DraggableObjects[control_Num].Region.Height, 0, DraggableObjects[control_Num].ControlType, control_Num ); } Point _Location = A4location_XY; control_Num = DraggableObjects.Count; if ((_Location.X + 51) > Print_PageType.Width) { _Location.X = Print_PageType.Width - 51; } if ((_Location.Y + 51) > DraggableBandObjects[band_Num].Region.Bottom - 20) { _Location.Y = DraggableBandObjects[band_Num].Region.Bottom - 20 - 51; } Draggable draggableBlock = new Draggable(_Location.X, _Location.Y, control_Type); DraggableObjects.Add(draggableBlock); int _width = 51; int _height = 51; DraggableObjects[control_Num].Belong_Band = band_Num; DraggableObjects[control_Num].Field_Align = "Left,Top"; DraggableObjects[control_Num].Field_TextFont = "微软雅黑"; DraggableObjects[control_Num].Field_ControlColor = Color.FromArgb(0, 0, 0); DraggableObjects[control_Num].Field_TextFontSize = 9; DraggableObjects[control_Num].Field_ImgZoom = 1; for (int i = 0; i < 8; i++) { DraggableObjects[control_Num].Field_BoxLine[i] = false; } DraggableObjects[control_Num].Setimage = LinBox(_width, _height, 1, control_Type, control_Num); control_Type = -1; Print_PageType.Invalidate(); RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType); Object_Record(); ReportChange_Flag = true; } }
public static void PageType_MouseUp(object sender, MouseEventArgs e) { PanelEx pL = (PanelEx)sender; for (int i = 0; i < 3; i++) // 鼠标有可能超出范围延伸到其他band,所以判断全部,停止拖拽。 { if ((DraggableBandObjects[i].IsDragging) || (DraggableBandObjects[i].IsSize)) { DraggableBandObjects[i].IsDragging = false; DraggableBandObjects[i].IsSize = false; DraggableBandObjects[i].DraggingPoint = Point.Empty; var DraggableSync = DraggableObjects.Where(sync => sync.Belong_Band == i).ToList(); for (int t = 0; t < DraggableSync.Count; t++) { DraggableSync[t].Primary = DraggableSync[t].Region.Top; } break; } } if (band_state == 1) // 设置band高度,强制为内部组件靠下的组件的高度 { if (DraggableBandObjects[0].Region.Bottom > DraggableBandObjects[1].Region.Top) { DraggableBandObjects[0].Region = new Rectangle( 0, DraggableBandObjects[0].Region.Top, DraggableBandObjects[0].Region.Width, DraggableBandObjects[1].Region.Top - DraggableBandObjects[0].Region.Top ); pL.Invalidate(); } if (DraggableBandObjects[1].Region.Bottom > DraggableBandObjects[2].Region.Top) { DraggableBandObjects[1].Region = new Rectangle( 0, DraggableBandObjects[1].Region.Top, DraggableBandObjects[1].Region.Width, DraggableBandObjects[2].Region.Top - DraggableBandObjects[1].Region.Top ); pL.Invalidate(); } if (DraggableBandObjects[2].Region.Bottom > Print_PageType.Bottom - 10) { DraggableBandObjects[2].Region = new Rectangle( 0, DraggableBandObjects[2].Region.Top, DraggableBandObjects[2].Region.Width, Print_PageType.Bottom - 10 - DraggableBandObjects[2].Region.Top ); pL.Invalidate(); } var DraggableMaxBottom = DraggableObjects.Where(bottom => bottom.Belong_Band == band_Num).OrderByDescending(sort => sort.Region.Bottom).ToList(); if (DraggableMaxBottom.Count > 0) { int _maxHeight = 43; if (DraggableBandObjects[band_Num].Region.Bottom - DraggableMaxBottom[0].Region.Bottom < 20) { _maxHeight = (DraggableMaxBottom[0].Region.Bottom - DraggableBandObjects[band_Num].Region.Top) + 20; DraggableBandObjects[band_Num].Region = new Rectangle( 0, DraggableBandObjects[band_Num].Region.Top, DraggableBandObjects[band_Num].Region.Width, _maxHeight ); pL.Invalidate(); } } } if (control_Num > -1) { if (DraggableObjects[control_Num].IsDragging) { DraggableObjects[control_Num].IsDragging = false; DraggableObjects[control_Num].DraggingPoint = Point.Empty; DraggableObjects[control_Num].Primary = DraggableObjects[control_Num].Region.Top; Object_Record(); ReportChange_Flag = true; } } }
private void acceptSet_Click(object sender, EventArgs e) { Label pL = (Label)sender; if ((int)pL.Tag == 1) { _pgselect = _record; setPage_Form._formObject.Close(); } else { for (int i = 0; i < 4; i++) { page_TypeFace.Page_Margin[i] = int.Parse(input_Margin[i].textBox.Text.Trim()); } page_TypeFace.Page_Type = _pgselect; if ((_record != _pgselect) || (input_def[0].textBox.Text != page_TypeFace.Rect_mm[0]) || (input_def[1].textBox.Text != page_TypeFace.Rect_mm[1]) || (page_TypeFace.Page_Direction != _pgdirect)) { RBuild_Info.Set_DefaultInfo(); DraggableObjects.Clear(); control_Num = -1; page_Container.VerticalScroll.Value = 0; page_Container.HorizontalScroll.Value = 0; if (_pgselect == -1) { page_TypeFace.Page_Area.Width = (int)Math.Floor(int.Parse(input_def[0].textBox.Text) * 3.779527559055118); page_TypeFace.Page_Area.Height = (int)Math.Floor(int.Parse(input_def[1].textBox.Text) * 3.779527559055118) + 13 + 126; page_TypeFace.Rect_mm[0] = input_def[0].textBox.Text; page_TypeFace.Rect_mm[1] = input_def[1].textBox.Text; } else { Set_PrintPageType(_pgselect, _pgdirect); page_TypeFace.Rect_mm[0] = ""; page_TypeFace.Rect_mm[1] = ""; } // 设置预览页面大小 PreViewPage_Area = new Size(page_TypeFace.Page_Area.Width, page_TypeFace.Page_Area.Height - 126);// 去掉-126 int height = 120; int ly = 0; for (int i = 0; i < 3; i++) { if (i == 0) { height = 120; ly = 0; } else if (i == 1) { height = 250; ly = 128; } else if (i == 2) { height = 120; ly = page_TypeFace.Page_Area.Height - height; } DraggableBandObjects[i].Region = new Rectangle(0, ly, page_TypeFace.Page_Area.Width, height); } page_Install.Size = new Size(page_TypeFace.Page_Area.Width + 20, page_TypeFace.Page_Area.Height + 20); int _iLeft = (page_Container.Width / 2) - (page_TypeFace.Page_Area.Width / 2); if (_iLeft < 0) { _iLeft = 0; } page_Install.Location = new Point(_iLeft, 0); page_Install.Invalidate(); Print_PageType.Size = page_TypeFace.Page_Area; } RBuild_Info.Set_CompositeLocation(); setPage_Form._formObject.Close(); } Print_PageType.Invalidate(); }