Exemple #1
0
 private void btnAutoText_Click(object sender, RoutedEventArgs e)
 {
     if (checkActive())
     {
         MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     try
     {
         ShapeRange orSh = app.ActiveSelectionRange;
         double     x = 0, y = 0;
         bool       flag = false;
         if (orSh.Shapes.Count == 1 && orSh.Shapes.First.Type == cdrShapeType.cdrGroupShape)
         {
             orSh.Ungroup();
         }
         foreach (Shape s in orSh.Shapes)
         {
             if (s.Type == cdrShapeType.cdrTextShape)
             {
                 txtTextName.Text = s.Text.Contents;
                 x = s.PositionX;
                 y = s.PositionY;
                 s.Text.AlignProperties.Alignment = cdrAlignment.cdrCenterAlignment;
                 s.PositionX = x;
                 s.PositionY = y;
                 flag        = true;
                 break;
             }
         }
         if (!flag)
         {
             MessageBox.Show("Không tìm thấy đối tượng dạng Text!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi");
     }
 }
Exemple #2
0
 private void btnCreaNum_Click(object sender, RoutedEventArgs e)
 {
     if (checkActive())
     {
         MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     try
     {
         if (string.IsNullOrWhiteSpace(txtTextName.Text))
         {
             txtTextName.SetResourceReference(System.Windows.Controls.Control.BorderBrushProperty, "ErrorColor");
             MessageBox.Show("Không được để trống phần số gốc đang chọn!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
         ShapeRange orSh = app.ActiveSelectionRange;
         bool       flag = false, outline = false, find = false;
         double     x = 0, y = 0;
         Color      black = new Color();
         black.CMYKAssign(0, 0, 0, 100);
         if (orSh.Shapes.Count == 1 && orSh.Shapes.First.Type == cdrShapeType.cdrGroupShape)
         {
             orSh.Ungroup();
         }
         foreach (Shape ss in orSh.Shapes)
         {
             if (ss.Type == cdrShapeType.cdrTextShape)
             {
                 if (ss.Text.Contents == txtTextName.Text)
                 {
                     x = ss.PositionX;
                     y = ss.PositionY;
                     ss.Text.AlignProperties.Alignment = cdrAlignment.cdrCenterAlignment;
                     ss.PositionX = x;
                     ss.PositionY = y;
                     flag         = true;
                     ss.Name      = "txtName";
                 }
             }
             if (!outline)
             {
                 if (ss.Type == cdrShapeType.cdrCurveShape || ss.Type == cdrShapeType.cdrEllipseShape || ss.Type == cdrShapeType.cdrPolygonShape ||
                     ss.Type == cdrShapeType.cdrRectangleShape || ss.Type == cdrShapeType.cdrPerfectShape || ss.Type == cdrShapeType.cdrCustomShape)
                 {
                     if (ss.Fill.Type == cdrFillType.cdrNoFill && ss.Outline.Type != cdrOutlineType.cdrNoOutline)
                     {
                         if (!find)
                         {
                             ss.Name = "txtOutline";
                             find    = true;
                         }
                         if (ss.Outline.Color.IsSame(black))
                         {
                             ss.Name = "txtOutline";
                             outline = true;
                         }
                     }
                 }
             }
         }
         if (!flag)
         {
             MessageBox.Show("Không tìm thấy Text có nội dung '" + txtTextName.Text + "'!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
         orSh.Group().CreateSelection();
         Size   s     = new Size(orSh.SizeWidth, orSh.SizeHeight);
         double space = 0;
         double p     = spaceCalNum();
         orSh = app.ActiveSelectionRange;
         for (int j = 1; j < numColNum.Value; j++)
         {
             space += s.x + p;
             orSh.AddRange(app.ActiveSelectionRange.Duplicate(space, 0));
         }
         orSh.CreateSelection();
         space = 0;
         for (int i = 1; i < Convert.ToInt32(lblRowNum.Content); i++)
         {
             space += s.y + p;
             orSh.AddRange(app.ActiveSelectionRange.Duplicate(0, -space));
         }
         if (Convert.ToInt32(lblTotalNum.Content) < Convert.ToInt32(lblRowNum.Content) * numColNum.Value)
         {
             ShapeRange remove = new ShapeRange();
             for (int i = Convert.ToInt32(lblTotalNum.Content) + 1; i <= Convert.ToInt32(lblRowNum.Content) * numColNum.Value; i++)
             {
                 remove.Add(orSh.Shapes[i]);
             }
             remove.Delete();
         }
         orSh.CreateSelection();
         orSh = app.ActiveSelectionRange;
         int count  = numFirstNum.Value;
         int lenght = numLastNum.Value.ToString().Length;
         foreach (Shape sp in orSh)
         {
             if (chk00.IsChecked.Value)
             {
                 if (chkAuto.IsChecked.Value)
                 {
                     sp.Shapes["txtName"].Text.Contents = txtTextFirst.Text + count.ToString().PadLeft(lenght, '0') + txtTextLast.Text;
                 }
                 else
                 {
                     string num0String = new string('0', num0.Value);
                     sp.Shapes["txtName"].Text.Contents = txtTextFirst.Text + num0String + count.ToString() + txtTextLast.Text;
                 }
             }
             else
             {
                 sp.Shapes["txtName"].Text.Contents = txtTextFirst.Text + count.ToString() + txtTextLast.Text;
             }
             count++;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi");
     }
 }
Exemple #3
0
        private void doPage(Page page)
        {
            page.Activate();
            double w = page.SizeWidth;
            double h = page.SizeHeight;

            page.SelectShapesFromRectangle(0, 0, w, h, true).Group();
            ShapeRange shapeRange  = app.ActiveSelectionRange;
            ShapeRange shapeRangeD = shapeRange.Duplicate();

            Shape rec = null, recD = null;

            if (comboBox1.SelectedIndex == 0)
            {
                rec  = app.ActiveLayer.CreateRectangle2(0, h / 2, w, h / 2);
                recD = app.ActiveLayer.CreateRectangle2(0, 0, w, h / 2);
            }
            if (comboBox1.SelectedIndex == 1)
            {
                rec  = app.ActiveLayer.CreateRectangle2(0, 0, w / 2, h);
                recD = app.ActiveLayer.CreateRectangle2(w / 2, 0, w / 2, h);
            }
            rec.Fill.ApplyNoFill();
            rec.Outline.Width = 0;
            recD.Fill.ApplyNoFill();
            recD.Outline.Width = 0;
            shapeRange.AddToPowerClip(rec, cdrTriState.cdrFalse);
            shapeRangeD.AddToPowerClip(recD, cdrTriState.cdrFalse);
            rec.OrderToBack();
            recD.OrderToBack();

            double newW, newH;

            if (comboBox1.SelectedIndex == 0)
            {
                newW = w;
                newH = h / 2;
            }
            else
            {
                newW = w / 2;
                newH = h;
            }

            page.SizeWidth  = newW;
            page.SizeHeight = newH;
            rec.LeftX       = 0;
            rec.BottomY     = 0;

            Page newPage = app.ActiveDocument.AddPagesEx(1, newW, newH);

            newPage.Activate();
            recD.MoveToLayer(app.ActiveLayer);
            recD.LeftX   = 0;
            recD.BottomY = 0;

            newPage.MoveTo(page.Index + 1);


            shapeRange.Ungroup();
            shapeRangeD.Ungroup();
        }