private void btnAutoLine_Click(object sender, RoutedEventArgs e) { if (checkActive()) { MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (initFile("line")) { try { Size s = new Size(app.ActiveSelection.SizeWidth, app.ActiveSelection.SizeHeight); Size position = new Size(app.ActiveSelectionRange.PositionX, app.ActiveSelectionRange.PositionY); Size size = new Size(s.x * numCol.Value, s.y * numRow.Value); Shape orSh = CreateBe(); Shape mark1 = app.ActiveLayer.CreateRectangle(orSh.LeftX, orSh.TopY, orSh.RightX, orSh.BottomY); mark1.CreateSelection(); createMark(); orSh.Outline.SetNoOutline(); ShapeRange be = CrLine(s, position, size); be.Move(be.SizeWidth + 15, 0); Shape mark2 = app.ActiveLayer.CreateRectangle(be.LeftX, be.TopY, be.RightX, be.BottomY); mark2.CreateSelection(); createMark(); app.ActiveWindow.ActiveView.ToFitAllObjects(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); } } else { MessageBox.Show("Chưa thỏa điều kiện tạo file bế thẳng!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnCreInsert_Click(object sender, RoutedEventArgs e) { if (checkActive()) { MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { app.ActiveDocument.Unit = cdrUnit.cdrCentimeter; Size s = new Size(app.ActiveSelection.SizeWidth, app.ActiveSelection.SizeHeight); ShapeRange orSh = app.ActiveSelectionRange; if (orSh.Shapes[1].Type == cdrShapeType.cdrBitmapShape && orSh.Count == 1) { Shape ell = app.ActiveLayer.CreateEllipse2(orSh.CenterX, orSh.CenterY, orSh.SizeWidth / 2, orSh.SizeHeight / 2); Shape newell = ell.Intersect(orSh.Shapes[1], true, true); orSh.Delete(); orSh.Add(newell); orSh.Add(ell); orSh.CreateSelection(); } double size = numInsert.Value; if (size == 0) { return; } double space = 0; spaceCal(); ShapeRange insert = app.ActiveSelectionRange.Duplicate(0, 0); app.ActiveDocument.ReferencePoint = cdrReferencePoint.cdrBottomRight; insert.SizeHeight = size; insert.SizeWidth = size; app.ActiveDocument.ReferencePoint = cdrReferencePoint.cdrTopLeft; double move = (size / 2) + (_space / 2); insert.Move(move, -move); for (int i = 1; i < numRow.Value; i++) { space += s.y + _space; orSh.AddRange(app.ActiveSelectionRange.Duplicate(0, -space)); } orSh.CreateSelection(); space = 0; for (int j = 1; j < numCol.Value; j++) { space += s.x + _space; orSh.AddRange(app.ActiveSelectionRange.Duplicate(space, 0)); } space = 0; insert.CreateSelection(); ShapeRange insertRange = insert; for (int ii = 1; ii < numRow.Value - 1; ii++) { space += s.y + _space; insertRange.AddRange(app.ActiveSelectionRange.Duplicate(0, -space)); } space = 0; insertRange.CreateSelection(); for (int jj = 1; jj < numCol.Value - 1; jj++) { space += s.x + _space; insertRange.AddRange(app.ActiveSelectionRange.Duplicate(space, 0)); } orSh.AddRange(insertRange); orSh.Group(); app.ActiveLayer.CreateRectangle(orSh.LeftX, orSh.TopY, orSh.RightX, orSh.BottomY).CreateSelection(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); } }