/// <summary>
 /// 删除组件
 /// </summary>
 /// <param name="_mode">是否记录</param>
 public static void Delete_Control(bool _record)
 {
     if (DraggableObjects.Count > 0)
     {
         DraggableObjects.Remove(DraggableObjects[control_Num]);
         if (DraggableObjects.Count < 1)
         {
             control_Num = -1;
             RBuild_Info.Set_DefaultInfo();
         }
         else
         {
             control_Num -= 1;
             if (control_Num < 0)
             {
                 control_Num = 0;
             }
             DraggableObjects[control_Num].Setimage = LinBox(DraggableObjects[control_Num].Region.Width, DraggableObjects[control_Num].Region.Height, 1, DraggableObjects[control_Num].ControlType, control_Num);
             RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType);
             DraggableObjects[control_Num].IsDragging = false;
             if (_record)
             {
                 Object_Record();
             }
         }
         page_Install.Invalidate();
         page_Container.Invalidate();
         Print_PageType.Invalidate();
         RBuild_MouseEvent.CursorFlag = -1;
         ReportChange_Flag            = true;
     }
 }
    /// <summary>
    ///  初始化栏目
    /// </summary>
    public static void Initialize_Band()
    {
        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;
            }
            DraggableBand draggableBandBlock = new DraggableBand(0, ly, Print_PageType.Width, height, i);
            draggableBandBlock.Id = i;
            DraggableBandObjects.Add(draggableBandBlock);
        }
        Print_PageType.Invalidate();
    }
 public static void PageType_MouseClick(object sender, MouseEventArgs e)
 {
     for (int i = DraggableObjects.Count - 1; i >= 0; i--)
     {
         if (DraggableObjects[i].Region.Contains(e.Location))
         {
             if (i != control_Num)
             {
                 DraggableObjects[control_Num].Setimage = LinBox(
                     DraggableObjects[control_Num].Region.Width,
                     DraggableObjects[control_Num].Region.Height,
                     0,
                     DraggableObjects[control_Num].ControlType, control_Num
                     );
                 control_Num = i;
                 DraggableObjects[i].Setimage = LinBox(
                     DraggableObjects[i].Region.Width,
                     DraggableObjects[i].Region.Height,
                     1,
                     DraggableObjects[i].ControlType, i
                     );
                 Print_PageType.Invalidate();
                 RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType);
                 break;
             }
             else
             {
                 break;
             }
         }
     }
 }
    /// <summary>
    /// 元素位移底层,其他依次后移
    /// </summary>
    public static void ListSwap_Bottom()
    {
        var swap = DraggableObjects[control_Num];

        DraggableObjects.RemoveAt(control_Num);
        DraggableObjects.Insert(0, swap);
        control_Num = 0;
        Print_PageType.Invalidate();
        ReportChange_Flag = true;
    }
    /// <summary>
    /// 元素位移顶层,其他依次后移
    /// </summary>
    public static void ListSwap_Top()
    {
        var swap = DraggableObjects[control_Num];

        DraggableObjects.RemoveAt(control_Num);
        DraggableObjects.Add(swap);
        control_Num = DraggableObjects.Count - 1;
        Print_PageType.Invalidate();
        ReportChange_Flag = true;
    }
    /// <summary>
    /// 粘贴组件
    /// </summary>
    /// <param name="lx">粘贴位置 x</param>
    /// <param name="ly">粘贴位置 y</param>
    public static void Object_OperationPast(int lx, int ly)
    {
        if ((operationObject.Id != null) && (band_Num != -1))
        {
            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
                    );
            }
            operationObject.Region = new Rectangle(
                DraggableBandObjects[band_Num].Region.Left + lx,
                DraggableBandObjects[band_Num].Region.Top + ly,
                operationObject.Region.Width,
                operationObject.Region.Height
                );
            Draggable draggableBlock = new Draggable(operationObject.Region.Left, operationObject.Region.Top, operationObject.ControlType);

            draggableBlock.Id                  = GetMd5Str16(DateTime.Now.ToString());
            draggableBlock.Belong_Band         = band_Num;
            draggableBlock.Region              = operationObject.Region;
            draggableBlock.Setimage            = operationObject.Setimage;
            draggableBlock.isContent           = operationObject.isContent;
            draggableBlock.Field_Img           = operationObject.Field_Img;
            draggableBlock.Field_Text          = operationObject.Field_Text;
            draggableBlock.Field_Calculate     = operationObject.Field_Calculate;
            draggableBlock.Field_TextFont      = operationObject.Field_TextFont;
            draggableBlock.Field_TextFontSize  = operationObject.Field_TextFontSize;
            draggableBlock.Field_TextFontStyle = operationObject.Field_TextFontStyle;
            draggableBlock.Field_Align         = operationObject.Field_Align;
            draggableBlock.Field_ImgZoom       = operationObject.Field_ImgZoom;
            for (int i = 0; i < 8; i++)
            {
                draggableBlock.Field_BoxLine[i] = operationObject.Field_BoxLine[i];
            }
            draggableBlock.Field_LineColor     = operationObject.Field_LineColor;
            draggableBlock.Field_LineThickness = operationObject.Field_LineThickness;
            draggableBlock.Field_LineType      = operationObject.Field_LineType;
            draggableBlock.Field_Shape         = operationObject.Field_Shape;
            draggableBlock.Field_ControlColor  = operationObject.Field_ControlColor;
            draggableBlock.Field_BackColor     = operationObject.Field_BackColor;

            control_Num = DraggableObjects.Count;
            DraggableObjects.Add(draggableBlock);
            Print_PageType.Invalidate();
            Object_Record();
            RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType);
            ReportChange_Flag = true;
        }
    }
    // 设置位置
    public static void Set_BoxPoint(int _type)
    {
        if (control_Num > -1)
        {
            switch (_type)
            {
            case 0:     // 左
                DraggableObjects[control_Num].Region = new Rectangle(
                    0,
                    DraggableObjects[control_Num].Region.Top,
                    DraggableObjects[control_Num].Region.Width,
                    DraggableObjects[control_Num].Region.Height
                    );
                break;

            case 1:     // 右
                DraggableObjects[control_Num].Region = new Rectangle(
                    Print_PageType.Width - DraggableObjects[control_Num].Region.Width,
                    DraggableObjects[control_Num].Region.Top,
                    DraggableObjects[control_Num].Region.Width,
                    DraggableObjects[control_Num].Region.Height
                    );
                break;

            case 2:     // 顶
                DraggableObjects[control_Num].Region = new Rectangle(
                    DraggableObjects[control_Num].Region.Left,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Top + 20,
                    DraggableObjects[control_Num].Region.Width,
                    DraggableObjects[control_Num].Region.Height
                    );
                break;

            case 3:     // 底
                DraggableObjects[control_Num].Region = new Rectangle(
                    DraggableObjects[control_Num].Region.Left,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Bottom - 20 - DraggableObjects[control_Num].Region.Height,
                    DraggableObjects[control_Num].Region.Width,
                    DraggableObjects[control_Num].Region.Height
                    );
                break;

            default:
                break;
            }
            Print_PageType.Invalidate();
            Object_Record();
            View_Info         = true;
            ReportChange_Flag = true;
        }
    }
    private void SetLineType_Click(object sender, EventArgs e)
    {
        PanelEx pL = (PanelEx)sender;

        if (control_Num > -1)
        {
            if (Array.IndexOf(DraggableObjects[control_Num].Field_BoxLine, true) != -1)
            {
                DraggableObjects[control_Num].Field_LineType = dashStyles[(int)pL.Tag];
                DraggableObjects[control_Num].Setimage       = LinBox(
                    DraggableObjects[control_Num].Region.Width,
                    DraggableObjects[control_Num].Region.Height,
                    1,
                    DraggableObjects[control_Num].ControlType,
                    control_Num
                    );
                Print_PageType.Invalidate();
                ReportChange_Flag = true;
            }
        }
    }
    // 画边框线
    public static void Set_LineBorder(int _type)
    {
        if (control_Num > -1)
        {
            DraggableObjects[control_Num].Field_BoxLine[_type] = !DraggableObjects[control_Num].Field_BoxLine[_type];

            if (_type == 5)
            {
                if (!DraggableObjects[control_Num].Field_BoxLine[_type])
                {
                    for (int i = 0; i < 8; i++)
                    {
                        DraggableObjects[control_Num].Field_BoxLine[i] = false;
                    }
                }
            }

            DraggableObjects[control_Num].Setimage = LinBox(DraggableObjects[control_Num].Region.Width, DraggableObjects[control_Num].Region.Height, 1, DraggableObjects[control_Num].ControlType, control_Num);
            Print_PageType.Invalidate();
            Object_Record();
            ReportChange_Flag = true;
        }
    }
    // 打开文件
    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;
    }
    protected override void WndProc(ref Message m)
    {
        convert = false;
        int sizeX      = 0;
        int sizeY      = 0;
        int sizeWidth  = 0;
        int sizeHeight = 0;

        if (DraggableObjects.Count > 0)
        {
            convert    = true;
            sizeX      = DraggableObjects[control_Num].Region.Left;
            sizeY      = DraggableObjects[control_Num].Region.Top;
            sizeWidth  = DraggableObjects[control_Num].Region.Width;
            sizeHeight = DraggableObjects[control_Num].Region.Height;
        }
        base.WndProc(ref m);

        switch (m.Msg)
        {
        case WM_NCPAINT:
            if (m_aeroEnabled)
            {
                var v = 2;
                DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                MARGINS margins = new MARGINS()
                {
                    bottomHeight = 1,
                    leftWidth    = 1,
                    rightWidth   = 1,
                    topHeight    = 1
                };
                DwmExtendFrameIntoClientArea(this.Handle, ref margins);
            }
            break;

        case 0x0084:
            if (Sizeable)
            {
                base.WndProc(ref m);
                Point vPoint = new Point((int)m.LParam & 0xFFFF,
                                         (int)m.LParam >> 16 & 0xFFFF);
                vPoint = PointToClient(vPoint);
                if (vPoint.X <= 5)
                {
                    if (vPoint.Y <= 5)
                    {
                        m.Result = (IntPtr)Guying_HTTOPLEFT;
                    }
                    else if (vPoint.Y >= ClientSize.Height - 5)
                    {
                        m.Result = (IntPtr)Guying_HTBOTTOMLEFT;
                    }
                    else
                    {
                        m.Result = (IntPtr)Guying_HTLEFT;
                    }
                }
                else if (vPoint.X >= ClientSize.Width - 5)
                {
                    if (vPoint.Y <= 5)
                    {
                        m.Result = (IntPtr)Guying_HTTOPRIGHT;
                    }
                    else if (vPoint.Y >= ClientSize.Height - 5)
                    {
                        m.Result = (IntPtr)Guying_HTBOTTOMRIGHT;
                    }
                    else
                    {
                        m.Result = (IntPtr)Guying_HTRIGHT;
                    }
                }
                else if (vPoint.Y <= 5)
                {
                    m.Result = (IntPtr)Guying_HTTOP;
                }
                else if (vPoint.Y >= ClientSize.Height - 5)
                {
                    m.Result = (IntPtr)Guying_HTBOTTOM;
                }
            }
            break;

        case WM_HOTKEY:
            if (Use_HotKey)
            {
                switch (m.WParam.ToInt32())
                {
                case 0x1000:         // Ctrl_Up:
                    sizeY -= 1;
                    break;

                case 0x1001:         // Ctrl_Down:
                    sizeY += 1;
                    break;

                case 0x1002:         // Ctrl_Left:
                    sizeX -= 1;
                    break;

                case 0x1003:         // Ctrl_Right:
                    sizeX += 1;
                    break;

                case 0x1004:         // Shift_Up:
                    sizeHeight -= 1;
                    break;

                case 0x1005:         // Shift_Down:
                    sizeHeight += 1;
                    break;

                case 0x1006:         // Shift_Left:
                    sizeWidth -= 1;
                    break;

                case 0x1007:         // Shift_Right:
                    sizeWidth += 1;
                    break;

                case 0x1008:         // Alt_Delete
                    Delete_Control(true);
                    convert = false;
                    break;

                case 0x1009:         // Alt_X
                    Object_OperationCopy();
                    Delete_Control(true);
                    convert = false;
                    break;

                case 0x1010:         // Alt_C
                    Object_OperationCopy();
                    convert = false;
                    break;

                case 0x1011:         // Alt_V
                    Object_OperationPast(0, 21);
                    convert = false;
                    break;

                case 0x1012:         // Alt_Z
                    Object_Operation(0);
                    convert = false;
                    break;

                case 0x1013:         // Alt_R
                    Object_Operation(1);
                    convert = false;
                    break;

                case 0x1014:         // Alt_T
                    ListSwap_Top();
                    convert = false;
                    break;

                case 0x1015:         // Alt_B
                    ListSwap_Bottom();
                    convert = false;
                    break;

                case 0x1016:         // Alt_P
                    new RBuild_Preview().View();
                    convert = false;
                    break;

                default:
                    break;
                }
                if (convert)
                {
                    if (sizeWidth < 14)
                    {
                        sizeWidth = 14;
                    }
                    if (sizeHeight < 14)
                    {
                        sizeHeight = 14;
                    }
                    if (sizeX < 0)
                    {
                        sizeX     = 0;
                        sizeWidth = DraggableObjects[control_Num].Region.Width;
                    }
                    if ((sizeX + sizeWidth) > Print_PageType.Width)
                    {
                        sizeWidth = DraggableObjects[control_Num].Region.Width;
                        sizeX     = DraggableObjects[control_Num].Region.Left;
                    }
                    if (sizeY < 0)
                    {
                        sizeY      = 0;
                        sizeHeight = DraggableObjects[control_Num].Region.Height;
                    }
                    if ((sizeY + sizeHeight) > DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Bottom - 20)
                    {
                        sizeHeight = DraggableObjects[control_Num].Region.Height;
                        sizeY      = DraggableObjects[control_Num].Region.Top;
                    }
                    if (sizeY < (DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Top + 20))
                    {
                        sizeY = 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);
                    Print_PageType.Invalidate();
                    View_Info = true;
                }
            }
            break;

        case WM_CREATE:     // 创建窗口消息
            if (Use_HotKey)
            {
                for (int i = 0; i < 4; i++)
                {
                    AppHotKey.RegKey(Handle, hot_Keys[i], AppHotKey.KeyModifiers.Ctrl, keys[i]);
                    AppHotKey.RegKey(Handle, hot_Keys[i + 4], AppHotKey.KeyModifiers.Shift, keys[i]);
                }
                for (int i = 4; i < 13; i++)
                {
                    AppHotKey.RegKey(Handle, hot_Keys[i + 4], AppHotKey.KeyModifiers.Alt, keys[i]);
                }
            }
            break;

        case WM_DESTROY:     // 销毁窗口消息
            if (Use_HotKey)
            {
                for (int i = 0; i < 16; i++)
                {
                    AppHotKey.UnRegKey(Handle, hot_Keys[i]);
                }
            }
            break;

        default:
            break;
        }
    }
    /// 点击工具栏图标
    private static void toolControl_Click(object sender, EventArgs e)
    {
        PictureBoxEx pL = (PictureBoxEx)sender;

        switch (pL.Tag)
        {
        case "FILE_NWE":
            RBuild_File.New_File();
            break;

        case "FILE_OPEN":
            RBuild_File.Open_File();
            break;

        case "FILE_SAVE":
            RBuild_File.Save_File();
            break;

        case "FILE_SETPAGE":
            DialogUse_HotKey = true;
            new RBuild_SetPageType().Set_Type();
            break;

        case "FILE_SETDATABASE":
            DialogUse_HotKey = true;
            new RBuild_SetDataBase().Set_Data();
            break;

        case "SYSTEM_CLOSE":
            RBuild_Design.designForm_Close(null, null);
            break;

        case "EDIT_CUT":
            Object_OperationCopy();
            Delete_Control(true);
            break;

        case "EDIT_COPY":
            Object_OperationCopy();
            break;

        case "EDIT_PAST":
            Object_OperationPast(0, 21);
            break;

        case "EDIT_DELETE":
            Delete_Control(true);
            break;

        case "EDIT_CANCEL":
            Object_Operation(0);
            break;

        case "EDIT_REDO":
            Object_Operation(1);
            break;

        case "EDIT_DELALL":
            Object_Record();
            for (int i = 0; i < DraggableObjects.Count; i++)
            {
                Delete_Control(false);
            }
            break;

        case "EDIT_PREVIEW":
            new RBuild_Preview().View();
            break;

        case "EDIT_PRINT":
            break;

        case "DESIGN_PONINTER":
            RBuild_Design.design_Form._formObject.Cursor = Cursors.Default;
            control_Type = -1;
            break;

        case "DESIGN_SHOWLINE":
            Show_Line = !Show_Line;
            page_Install.Invalidate();
            page_Container.Invalidate();
            Print_PageType.Invalidate();
            break;

        case "DESIGN_BAND":
            DialogUse_HotKey = true;
            new RBuild_SetBandRect().Set_Band(0);
            break;

        case "DESIGN_TEXTBOX":
            pL.Cursor    = custom_MouseCursor(control_icon[0], 5, 5);
            control_Type = 1;
            break;

        case "DESIGN_IMGBOX":
            pL.Cursor    = custom_MouseCursor(control_icon[1], 5, 5);
            control_Type = 2;
            break;

        case "DESIGN_SHAPEBOX":
            pL.Cursor    = custom_MouseCursor(control_icon[2], 5, 5);
            control_Type = 3;
            break;

        case "DESIGN_DATAFIELD":
            pL.Cursor    = custom_MouseCursor(control_icon[3], 5, 5);
            control_Type = 4;
            break;

        case "DESIGN_PAGECODE":
            pL.Cursor    = custom_MouseCursor(control_icon[4], 5, 5);
            control_Type = 5;
            break;

        case "DESIGN_FUNCTION":
            pL.Cursor    = custom_MouseCursor(control_icon[5], 5, 5);
            control_Type = 6;
            break;

        case "DESIGN_SETCOLOR":
            DialogUse_HotKey = true;
            new RBuild_SetColor().Set_Colors();
            break;

        case "DESIGN_TOPMOSE":
            ListSwap_Top();
            break;

        case "DESIGN_BOTMOST":
            ListSwap_Bottom();
            break;

        case "DESIGN_SETLEFT":
            Set_BoxPoint(0);
            break;

        case "DESIGN_SETRIGHT":
            Set_BoxPoint(1);
            break;

        case "DESIGN_SETTOP":
            Set_BoxPoint(2);
            break;

        case "DESIGN_SETBOT":
            Set_BoxPoint(3);
            break;

        case "DESIGN_ALEFT":
            Set_FillAlign(0);
            break;

        case "DESIGN_ACENTER":
            Set_FillAlign(1);
            break;

        case "DESIGN_ARIGHT":
            Set_FillAlign(2);
            break;

        case "DESIGN_ATOP":
            Set_FillAlign(3);
            break;

        case "DESIGN_ABOTTOM":
            Set_FillAlign(4);
            break;

        case "DESIGN_LINEBOT":
            Set_LineBorder(0);
            break;

        case "DESIGN_LINETOP":
            Set_LineBorder(1);
            break;

        case "DESIGN_LINELEFT":
            Set_LineBorder(2);
            break;

        case "DESIGN_LINERIGHT":
            Set_LineBorder(3);
            break;

        case "DESIGN_LINENO":
            Set_LineBorder(4);
            break;

        case "DESIGN_LINEEXTER":
            Set_LineBorder(5);
            break;

        case "DESIGN_LINEBIASDOWN":
            Set_LineBorder(6);
            break;

        case "DESIGN_LINE_BIASUP":
            Set_LineBorder(7);
            break;

        case "DESIGN_LINETHICK":
            DialogUse_HotKey = true;
            new RBuild_SetLineThick().Set_Thick();
            break;

        default:
            break;
        }
    }
    // 设置对齐方式
    public static void Set_FillAlign(int _type)
    {
        if (control_Num > -1)
        {
            switch (_type)
            {
            case 0:     // 左对齐
                DraggableObjects[control_Num].Region = new Rectangle(
                    0,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Top + 20,
                    DraggableObjects[control_Num].Region.Width,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Height - 40
                    );
                break;

            case 1:     // 垂直对齐
                DraggableObjects[control_Num].Region = new Rectangle(
                    0,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Top + 20 +
                    (DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Height - 40 - DraggableObjects[control_Num].Region.Height) / 2,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Width,
                    DraggableObjects[control_Num].Region.Height
                    );
                break;

            case 2:     // 右对齐
                DraggableObjects[control_Num].Region = new Rectangle(
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Width - DraggableObjects[control_Num].Region.Width,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Top + 20,
                    DraggableObjects[control_Num].Region.Width,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Height - 40
                    );
                break;

            case 3:     // 顶对齐
                DraggableObjects[control_Num].Region = new Rectangle(
                    0,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Top + 20,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Width,
                    DraggableObjects[control_Num].Region.Height
                    );
                break;

            case 4:     // 底对齐
                DraggableObjects[control_Num].Region = new Rectangle(
                    0,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Bottom - 20 - DraggableObjects[control_Num].Region.Height,
                    DraggableBandObjects[DraggableObjects[control_Num].Belong_Band].Region.Width,
                    DraggableObjects[control_Num].Region.Height
                    );
                break;

            default:
                break;
            }

            DraggableObjects[control_Num].Setimage = LinBox(
                DraggableObjects[control_Num].Region.Width,
                DraggableObjects[control_Num].Region.Height,
                1,
                DraggableObjects[control_Num].ControlType,
                control_Num
                );
            Print_PageType.Invalidate();
            Object_Record();
            View_Info         = true;
            ReportChange_Flag = true;
        }
    }
Example #15
0
    // 应用设置
    private static void accept_Attributes(object sender, EventArgs e)
    {
        if (DraggableObjects[control_Num].ControlType == 1)
        {
            if (content_TextInput.textBox.Text == "")
            {
                return;
            }
        }
        else
        if (DraggableObjects[control_Num].ControlType == 2)
        {
            if (content_ImgInput.textBox.Text == "")
            {
                if (!DraggableObjects[control_Num].isContent)
                {
                    return;
                }
            }
            else
            {
                try
                {
                    DraggableObjects[control_Num].Field_Img = Image.FromFile(content_ImgInput.textBox.Text) as Bitmap;
                }
                catch { return; }
            }
        }
        else
        if (DraggableObjects[control_Num].ControlType == 4)
        {
            if (content_DataInput.textBox.Text == "")
            {
                return;
            }
        }
        else
        if (DraggableObjects[control_Num].ControlType == 5)
        {
            if (content_PcodeInput.textBox.Text == "")
            {
                return;
            }
        }
        else
        if (DraggableObjects[control_Num].ControlType == 6)
        {
            if (content_FunctionInput.textBox.Text == "")
            {
                return;
            }
        }

        RbControls_DrawTextMethod DrawText = new RbControls_DrawTextMethod();
        int _controlType = 1;

        string TextAlign = "";

        if (DraggableObjects[control_Num].ControlType != 3) // 不是形状
        {
            if (align_Check[DraggableObjects[control_Num].ControlType - 1, 0].select)
            {
                TextAlign += "Left,";
            }
            if (align_Check[DraggableObjects[control_Num].ControlType - 1, 1].select)
            {
                TextAlign += "Right,";
            }
            if (align_Check[DraggableObjects[control_Num].ControlType - 1, 2].select)
            {
                TextAlign += "Top,";
            }
            if (align_Check[DraggableObjects[control_Num].ControlType - 1, 3].select)
            {
                TextAlign += "Bottom,";
            }
            if (align_Check[DraggableObjects[control_Num].ControlType - 1, 4].select)
            {
                TextAlign += "Middle,";
            }
            if (align_Check[DraggableObjects[control_Num].ControlType - 1, 5].select)
            {
                TextAlign += "Vertical,";
            }

            DraggableObjects[control_Num].Field_Align = TextAlign;
        }

        if ((DraggableObjects[control_Num].ControlType != 2) && (DraggableObjects[control_Num].ControlType != 3)) // 不是图像和形状
        {
            FontStyle fst = new FontStyle();
            if (font_render[DraggableObjects[control_Num].ControlType - 1, 0].select)
            {
                fst = FontStyle.Bold;
            }
            else
            {
                fst = FontStyle.Regular;
            }
            if (font_render[DraggableObjects[control_Num].ControlType - 1, 1].select)
            {
                fst = fst | FontStyle.Italic;
            }
            if (font_render[DraggableObjects[control_Num].ControlType - 1, 2].select)
            {
                fst = fst | FontStyle.Underline;
            }

            Font fnt = new Font(font_type[DraggableObjects[control_Num].ControlType - 1].labelText.Text, int.Parse(font_size[0].labelText.Text), fst, GraphicsUnit.Pixel);
            DraggableObjects[control_Num].Field_TextFontStyle = fst;

            Bitmap   bmp_Text = new Bitmap(DraggableObjects[control_Num].Region.Width, DraggableObjects[control_Num].Region.Height);
            Graphics gText    = Graphics.FromImage(bmp_Text);

            string _text = "";
            if (DraggableObjects[control_Num].ControlType == 1)
            {
                _text = content_TextInput.textBox.Text;
            }
            if (DraggableObjects[control_Num].ControlType == 4)
            {
                _text = content_DataInput.textBox.Text;
            }
            if (DraggableObjects[control_Num].ControlType == 5)
            {
                _text = content_PcodeInput.textBox.Text;
            }
            if (DraggableObjects[control_Num].ControlType == 6)
            {
                _text = content_FunctionInput.textBox.Text;
            }

            Point point_text = TextPoint(control_Num, bmp_Text.Width - 7, bmp_Text.Height - 7, gText, _text, fnt);

            DrawText.DrawString(bmp_Text, _text, fnt, color_Flag[DraggableObjects[control_Num].ControlType - 1].labelText.ForeColor, new Rectangle(point_text.X, point_text.Y, bmp_Text.Width, bmp_Text.Height));
            DraggableObjects[control_Num].Field_Img           = bmp_Text;
            DraggableObjects[control_Num].Field_Text          = _text;
            DraggableObjects[control_Num].Field_TextFont      = font_type[DraggableObjects[control_Num].ControlType - 1].labelText.Text;
            DraggableObjects[control_Num].Field_TextFontSize  = int.Parse(font_size[DraggableObjects[control_Num].ControlType - 1].labelText.Text);
            DraggableObjects[control_Num].Field_TextFontStyle = fst;
            DraggableObjects[control_Num].Field_Align         = TextAlign;
            DraggableObjects[control_Num].Field_ControlColor  = color_Flag[DraggableObjects[control_Num].ControlType - 1].labelText.ForeColor;

            if (DraggableObjects[control_Num].ControlType == 6)
            {
                DraggableObjects[control_Num].Field_Calculate = content_FunctionInput.textBox.Text;
            }
        }

        if (DraggableObjects[control_Num].ControlType == 2) // 图像
        {
            if (ImgZoom_CheckBox[0].select)
            {
                DraggableObjects[control_Num].Field_ImgZoom = 0;
            }
            else
            {
                DraggableObjects[control_Num].Field_ImgZoom = 1;
            }
            _controlType = 2;
        }

        if (DraggableObjects[control_Num].ControlType == 3) // 形状
        {
            for (int i = 0; i < 20; i++)
            {
                if (shap_select[i].select)
                {
                    DraggableObjects[control_Num].Field_Shape = i;
                    break;
                }
            }
            _controlType = 3;
            DraggableObjects[control_Num].Field_ControlColor = color_Flag[DraggableObjects[control_Num].ControlType - 1].labelText.ForeColor;
        }

        DraggableObjects[control_Num].isContent = true;

        DraggableObjects[control_Num].Region = new Rectangle(
            int.Parse(attribute_Input[DraggableObjects[control_Num].ControlType - 1, 2].textBox.Text),
            int.Parse(attribute_Input[DraggableObjects[control_Num].ControlType - 1, 3].textBox.Text),
            int.Parse(attribute_Input[DraggableObjects[control_Num].ControlType - 1, 0].textBox.Text),
            int.Parse(attribute_Input[DraggableObjects[control_Num].ControlType - 1, 1].textBox.Text)
            );

        DraggableObjects[control_Num].Setimage = LinBox(
            DraggableObjects[control_Num].Region.Width,
            DraggableObjects[control_Num].Region.Height,
            1,
            _controlType,
            control_Num
            );
        Print_PageType.Invalidate();
        Object_Record();
        ReportChange_Flag = true;
    }
    /// <summary>
    /// 撤销、重做
    /// </summary>
    /// <param name="_mode">模式</param>
    public static void Object_Operation(int _mode)
    {
        bool Oper = false;

        if (_mode == 0) // 撤销
        {
            oper_Record -= 1;
            if (oper_Record < 0)
            {
                Oper        = false;
                oper_Record = 0;
            }
            else
            {
                Oper = true;
            }
        }
        else
        if (_mode == 1) // 重做
        {
            oper_Record += 1;
            if (oper_Record >= recordObjects.Count)
            {
                Oper        = false;
                oper_Record = recordObjects.Count - 1;
            }
            else
            {
                Oper = true;
            }
        }

        if (Oper)
        {
            DraggableObjects.Clear();
            for (int i = 0; i < recordObjects[oper_Record].Count; i++)
            {
                Draggable draggableBlock = new Draggable(recordObjects[oper_Record][i].Region.Left, recordObjects[oper_Record][i].Region.Top, recordObjects[oper_Record][i].ControlType);

                draggableBlock.Id                  = recordObjects[oper_Record][i].Id;
                draggableBlock.Belong_Band         = recordObjects[oper_Record][i].Belong_Band;
                draggableBlock.Region              = recordObjects[oper_Record][i].Region;
                draggableBlock.Setimage            = recordObjects[oper_Record][i].Setimage;
                draggableBlock.isContent           = recordObjects[oper_Record][i].isContent;
                draggableBlock.Field_Img           = recordObjects[oper_Record][i].Field_Img;
                draggableBlock.Field_Text          = recordObjects[oper_Record][i].Field_Text;
                draggableBlock.Field_Calculate     = recordObjects[oper_Record][i].Field_Calculate;
                draggableBlock.Field_TextFont      = recordObjects[oper_Record][i].Field_TextFont;
                draggableBlock.Field_TextFontSize  = recordObjects[oper_Record][i].Field_TextFontSize;
                draggableBlock.Field_TextFontStyle = recordObjects[oper_Record][i].Field_TextFontStyle;
                draggableBlock.Field_Align         = recordObjects[oper_Record][i].Field_Align;
                draggableBlock.Field_ImgZoom       = recordObjects[oper_Record][i].Field_ImgZoom;
                for (int t = 0; t < 8; t++)
                {
                    draggableBlock.Field_BoxLine[t] = recordObjects[oper_Record][i].Field_BoxLine[t];
                }
                draggableBlock.Field_LineColor     = recordObjects[oper_Record][i].Field_LineColor;
                draggableBlock.Field_LineThickness = recordObjects[oper_Record][i].Field_LineThickness;
                draggableBlock.Field_LineType      = recordObjects[oper_Record][i].Field_LineType;
                draggableBlock.Field_Shape         = recordObjects[oper_Record][i].Field_Shape;
                draggableBlock.Field_ControlColor  = recordObjects[oper_Record][i].Field_ControlColor;
                draggableBlock.Field_BackColor     = recordObjects[oper_Record][i].Field_BackColor;

                DraggableObjects.Add(draggableBlock);
            }
            control_Num = recordObjects[oper_Record][0].Num;
            for (int i = 0; i < 3; i++)
            {
                DraggableBandObjects[i].Region = recordObjects[oper_Record][0].Band_Region[i];
            }

            Print_PageType.Invalidate();
            RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType);
            ReportChange_Flag = true;
        }
    }
    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;
        }
    }
Example #18
0
    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();
                }
            }
        }
    }
    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();
    }