/// <summary>
        /// 设置表格单元格的边框和背景样式
        /// </summary>
        /// <param name="parameter">参数</param>
        /// <param name="args">参数</param>
        private void SetElementBorderBackgroundFormat(
            BorderBackgroundCommandParameter parameter,
            WriterCommandEventArgs args,
            DomElement element)
        {
            DocumentContentStyle rs = (DocumentContentStyle)element.Style.Clone();
            bool modified           = false;
            bool globalModified     = false;

            if (rs.BorderLeft != parameter.LeftBorder)
            {
                rs.BorderLeft = parameter.LeftBorder;
                modified      = true;
            }
            if (rs.BorderTop != parameter.TopBorder)
            {
                rs.BorderTop = parameter.TopBorder;
                modified     = true;
            }
            if (rs.BorderRight != parameter.RightBorder)
            {
                rs.BorderRight = parameter.RightBorder;
                modified       = true;
            }
            if (rs.BorderBottom != parameter.BottomBorder)
            {
                rs.BorderBottom = parameter.BottomBorder;
                modified        = true;
            }
            if (rs.BorderColor != parameter.BorderColor)
            {
                rs.BorderColor = parameter.BorderColor;
                modified       = true;
            }
            if (rs.BorderStyle != parameter.BorderStyle)
            {
                rs.BorderStyle = parameter.BorderStyle;
                modified       = true;
            }
            if (rs.BorderWidth != parameter.BorderWidth)
            {
                rs.BorderWidth = parameter.BorderWidth;
                modified       = true;
            }
            if (rs.BackgroundColor != parameter.BackgroundColor)
            {
                rs.BackgroundColor = parameter.BackgroundColor;
                modified           = true;
            }
            args.Document.BeginLogUndo();
            if (modified)
            {
                globalModified = true;
                int newStyleIndex = args.Document.ContentStyles.GetStyleIndex(rs);
                if (newStyleIndex != element.StyleIndex)
                {
                    if (args.Document.CanLogUndo)
                    {
                        args.Document.UndoList.AddStyleIndex(element, element.StyleIndex, newStyleIndex);
                    }
                    element.StyleIndex = newStyleIndex;
                    if (element.ShadowElement != null)
                    {
                        if (args.Document.CanLogUndo)
                        {
                            args.Document.UndoList.AddStyleIndex(element.ShadowElement, element.ShadowElement.StyleIndex, newStyleIndex);
                        }
                        element.ShadowElement.StyleIndex = newStyleIndex;
                        element.ShadowElement.InvalidateView();
                    }
                    element.InvalidateView();
                    element.UpdateContentVersion();
                }
            }
            args.Document.EndLogUndo();
            if (globalModified)
            {
                args.Result            = true;
                args.Document.Modified = true;
                //args.Document.UpdateContentVersion();
                args.Document.OnDocumentContentChanged();
            }
        }
        protected void BorderBackgroundFormat(object sender, WriterCommandEventArgs args)
        {
            if (args.Mode == WriterCommandEventMode.QueryState)
            {
                args.Enabled = false;
                if (args.DocumentControler.Snapshot.CanModifySelection)
                {
                    if (Math.Abs(args.Document.Selection.Length) == 1)
                    {
                        DomElement element = args.Document.Selection.ContentElements[0];
                        if (element is DomObjectElement)
                        {
                            args.Enabled = true;
                            return;
                        }
                    }
                    if (args.Document.Selection.Mode == ContentRangeMode.Cell)
                    {
                        args.Enabled = true;
                    }
                }
            }
            else if (args.Mode == WriterCommandEventMode.Invoke)
            {
                DomElement simpleElement = null;
                if (Math.Abs(args.Document.Selection.Length) == 1)
                {
                    if (args.Document.Selection.ContentElements[0] is DomObjectElement)
                    {
                        simpleElement = args.Document.Selection.ContentElements[0];
                    }
                }
                BorderBackgroundCommandParameter parameter = args.Parameter
                                                             as BorderBackgroundCommandParameter;
                if (parameter == null && args.ShowUI == false)
                {
                    // 操作无意义
                    return;
                }

                if (args.ShowUI)
                {
                    using (dlgDocumentBorderBackground dlg = new dlgDocumentBorderBackground())
                    {
                        dlg.CommandParameter = parameter;
                        if (simpleElement != null)
                        {
                            dlg.CompleMode = false;
                        }
                        if (dlg.ShowDialog(args.EditorControl) == DialogResult.OK)
                        {
                        }
                        else
                        {
                            // 用户取消操作
                            return;
                        }
                    }
                }
                args.Result = false;

                SetElementBorderBackgroundFormat(parameter, args, simpleElement);
            }
        }
        private void dlgBorderBackground_Load(object sender, EventArgs e)
        {
            if (this.CompleMode == false)
            {
                chkMiddleHorizontalBorder.Visible = false;
                chkCenterVerticalBorder.Visible   = false;
                lblBorderApplyRange.Visible       = false;
                cboBorderApplyRange.Visible       = false;
            }
            _PreviewImage          = ( Bitmap )picBorderPreview.Image;
            picBorderPreview.Image = null;
            _PreviewImage.MakeTransparent(Color.White);

            if (_CommandParameter == null)
            {
                _CommandParameter = new BorderBackgroundCommandParameter();
            }
            _HandingEvent = true;
            lstBorderSettings.SelectedIndex = (int )_CommandParameter.BorderSettingsStyle;
            switch (_CommandParameter.BorderStyle)
            {
            case DashStyle.Dash:
                lstBorderStyle.SelectedIndex = 0;
                break;

            case DashStyle.DashDot:
                lstBorderStyle.SelectedIndex = 1;
                break;

            case DashStyle.DashDotDot:
                lstBorderStyle.SelectedIndex = 2;
                break;

            case DashStyle.Dot:
                lstBorderStyle.SelectedIndex = 3;
                break;

            case DashStyle.Solid:
                lstBorderStyle.SelectedIndex = 4;
                break;
            }

            chkBottomBorder.Checked           = _CommandParameter.BottomBorder;
            chkCenterVerticalBorder.Checked   = _CommandParameter.CenterVerticalBorder;
            chkLeftBorder.Checked             = _CommandParameter.LeftBorder;
            chkMiddleHorizontalBorder.Checked = _CommandParameter.MiddleHorizontalBorder;
            chkRightBorder.Checked            = _CommandParameter.RightBorder;
            chkTopBorder.Checked = _CommandParameter.TopBorder;

            if (_CommandParameter.ForTable)
            {
                cboBorderApplyRange.Items.Add(WriterStrings.BorderApplyRangeCell);
                cboBorderApplyRange.Items.Add(WriterStrings.BorderApplyRangeTable);
                if (_CommandParameter.ApplyRange == BorderCommandApplyRange.Cell)
                {
                    cboBorderApplyRange.SelectedIndex = 0;
                }
                else
                {
                    cboBorderApplyRange.SelectedIndex = 1;
                }
            }
            else
            {
                cboBorderApplyRange.Items.Add(WriterStrings.BorderApplyRangeText);
                cboBorderApplyRange.Items.Add(WriterStrings.BorderApplyRangeParagraph);
                if (_CommandParameter.ApplyRange == BorderCommandApplyRange.Text)
                {
                    cboBorderApplyRange.SelectedIndex = 0;
                }
                else
                {
                    cboBorderApplyRange.SelectedIndex = 1;
                }
            }

            btnBorderColor.CenterColor     = _CommandParameter.BorderColor;
            btnBackgroundColor.CenterColor = _CommandParameter.BackgroundColor;
            txtBorderWidth.Value           = (decimal)_CommandParameter.BorderWidth;
            _HandingEvent      = false;
            this.ValueModified = false;
        }