{"id":1419,"date":"2023-08-07T09:02:38","date_gmt":"2023-08-07T01:02:38","guid":{"rendered":"https:\/\/lyvba.com\/?p=1419"},"modified":"2023-08-07T09:04:55","modified_gmt":"2023-08-07T01:04:55","slug":"vbabox-02","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2023\/08\/07\/vbabox-02\/","title":{"rendered":"CorelDRAW VBA \u7b80\u5355\u4ee3\u7801\u5b9e\u73b0\u7ed8\u5236\u76d2\u5b50-\u4e0b\u7bc7"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/08\/box3.png\" alt=\"\" \/><\/p>\n<h2>\u5706\u89d2\u63d2\u53e3\u548c\u7fc5\u8180\u7684\u4ee3\u7801<\/h2>\n<ul>\n<li>\u5efa\u7acb\u5706\u89d2\u77e9\u5f62\u51fd\u6570 <code>CreateRectangle(0, 0, l, b, 50, 50)<\/code> \uff0c\u7b2c5-6\u53c2\u6570\uff0c\u6307\u5b9a\u4e0a2\u5706\u89d2\u7684\u7cfb\u6570<\/li>\n<li>\u7fc5\u8180\u662f\u4e2a\u81ea\u5b9a\u4e49\u591a\u8282\u70b9\u66f2\u7ebf\uff0c\u5148\u7528\u77e9\u5f62\u51fd\u6570\uff0c\u7ed8\u5236\u4e00\u4e2a\u4e34\u65f6\u7269\u4ef6 <code>s<\/code> \u786e\u5b9a\u8303\u56f4\u5927\u5c0f<\/li>\n<li>\u7136\u540e\u5b9a\u4e49 <code>DrawWing(s As Shape)<\/code> \u51fd\u6570\u6765\u624b\u5de5\u7ed8\u5236\uff0c\u5982\u56fe<\/li>\n<li><code>sp.AppendLineSegment 4, y - 2.5<\/code>  '\/\/ \u7ed8\u5236\u76f4\u7ebf<\/li>\n<li><code>sp.AppendCurveSegment2 6.5, y, 4.1, y - 1.25, 5.1, y<\/code>  '\/\/ \u7ed8\u5236\u66f2\u7ebf<\/li>\n<\/ul>\n<h2>\u4e0b\u9762\u662f\u7ed8\u5236\u6574\u4e2a\u76d2\u5b50\u5b8c\u6574\u7684\u4ee3\u7801<\/h2>\n<pre><code class=\"language-vbs\">Public Function Simple_box_three()\n  ActiveDocument.Unit = cdrMillimeter\n  Dim sr As New ShapeRange, wing As New ShapeRange\n  Dim sh As Shape\n  l = 100: w = 50: h = 70: b = 15\n  boxL = 2 * l + 2 * w + b: boxH = h\n  l1x = w: l2x = w + l: l3x = 2 * w + l: l4x = 2 * (w + l)\n\n  &#039;\/\/ \u7ed8\u5236\u4e3b\u4f53\u4e0a\u4e0b\u76d6\u77e9\u5f62\n  Set mainRect = ActiveLayer.CreateRectangle(0, 0, boxL, boxH)\n  Set topRect = ActiveLayer.CreateRectangle(0, 0, l, w)\n  topRect.Move l1x, h\n  Set bottomRect = ActiveLayer.CreateRectangle(0, 0, l, w)\n  bottomRect.Move l3x, -w\n\n  &#039;\/\/ \u7ed8\u5236Box \u5706\u89d2\u77e9\u5f62\u63d2\u53e3\n  Set top_RoundRect = ActiveLayer.CreateRectangle(0, 0, l, b, 50, 50)\n  top_RoundRect.Move l1x, h + w\n  Set bottom_RoundRect = ActiveLayer.CreateRectangle(0, 0, l, b, 0, 0, 50, 50)\n  bottom_RoundRect.Move l3x, -w - b\n\n  &#039;\/\/ \u7ed8\u5236box \u56db\u4e2a\u7fc5\u8180\n  Set sh = DrawWing(ActiveLayer.CreateRectangle(0, 0, w, (w + b) \/ 2 - 2))\n  wing.Add sh.Duplicate(0, h)\n  wing.Add sh.Duplicate(l2x, h)\n  wing.Add sh.Duplicate(0, -sh.SizeHeight)\n  wing.Add sh.Duplicate(l2x, -sh.SizeHeight)\n  wing(2).Flip cdrFlipHorizontal\n  wing(3).Flip cdrFlipVertical\n  wing(4).Rotate 180\n\n  &#039;\/\/ \u6dfb\u52a0\u5230\u7269\u4ef6\u7ec4\uff0c\u8bbe\u7f6e\u8f6e\u5ed3\u8272 C100\n  sr.Add mainRect: sr.Add topRect: sr.Add bottomRect\n  sr.Add top_RoundRect: sr.Add bottom_RoundRect\n  sr.AddRange wing: sh.Delete\n  sr.SetOutlineProperties Color:=CreateCMYKColor(100, 0, 0, 0)\n\n  &#039;\/\/ \u7ed8\u5236\u5c3a\u5bf8\u5200\u75d5\u7ebf\n  Set sl1 = DrawLine(l1x, 0, l1x, h)\n  Set sl2 = DrawLine(l2x, 0, l2x, h)\n  Set sl3 = DrawLine(l3x, 0, l3x, h)\n  Set sl4 = DrawLine(l4x, 0, l4x, h)\n\n  &#039;\/\/ \u76d2\u5b50box \u7fa4\u7ec4\n  sr.Add sl1: sr.Add sl2: sr.Add sl3: sr.Add sl4\n  sr.CreateSelection: sr.Group\n\nEnd Function\n\n&#039;\/\/ \u753b\u4e00\u6761\u7ebf\uff0c\u8bbe\u7f6e\u8f6e\u5ed3\u8272 M100\nPrivate Function DrawLine(X1, Y1, X2, Y2) As Shape\n  Set DrawLine = ActiveLayer.CreateLineSegment(X1, Y1, X2, Y2)\n  DrawLine.Outline.SetProperties Color:=CreateCMYKColor(0, 100, 0, 0)\nEnd Function\n\nPrivate Function DrawWing(s As Shape) As Shape\n    Dim sp As SubPath, crv As Curve\n    Dim x As Double, y As Double\n    x = s.SizeWidth: y = s.SizeHeight\n    s.Delete\n\n    &#039;\/\/ \u7ed8\u5236 Box \u7fc5\u8180 Wing\n    Set crv = Application.CreateCurve(ActiveDocument)\n    Set sp = crv.CreateSubPath(0, 0)\n    sp.AppendLineSegment 0, 4\n    sp.AppendLineSegment 2, 6\n    sp.AppendLineSegment 4, y - 2.5\n    sp.AppendCurveSegment2 6.5, y, 4.1, y - 1.25, 5.1, y\n    sp.AppendLineSegment x - 2, y\n    sp.AppendLineSegment x - 2, 3\n    sp.AppendLineSegment x, 0\n\n    sp.Closed = True\n    Set DrawWing = ActiveLayer.CreateCurve(crv)\nEnd Function<\/code><\/pre>\n<h3>\u6700\u540e\u5728\u7a97\u53e3\u63a7\u95f4\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u56fe\u7247\u5f53\u6309\u94ae<\/h3>\n<pre><code class=\"language-vbs\">Private Sub MakeBox_Click()\n  box.Simple_box_three\nEnd Sub<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/08\/tool.png\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5706\u89d2\u63d2\u53e3\u548c\u7fc5\u8180\u7684\u4ee3\u7801 \u5efa\u7acb\u5706\u89d2\u77e9\u5f62\u51fd\u6570 CreateRectangle(0, 0, l, b, 50 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1420,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[74,67],"class_list":["post-1419","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn","tag-coreldraw","tag-vba"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=1419"}],"version-history":[{"count":3,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1419\/revisions"}],"predecessor-version":[{"id":1423,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1419\/revisions\/1423"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media\/1420"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=1419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=1419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=1419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}