{"id":1267,"date":"2024-07-08T08:00:00","date_gmt":"2024-07-08T00:00:00","guid":{"rendered":"http:\/\/www.wyrcad.com\/?p=1267"},"modified":"2024-07-15T17:02:33","modified_gmt":"2024-07-15T09:02:33","slug":"%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e7%bc%96%e7%a8%8boop","status":"publish","type":"post","link":"https:\/\/www.wyrcad.com\/?p=1267","title":{"rendered":"\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b(OOP)"},"content":{"rendered":"\n<p><strong>\u5bf9\u8c61<\/strong>(Object)<\/p>\n\n\n\n<p>\u5bf9\u8c61\u4ee3\u8868\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u5143\u7d20\uff0c\u7c7b\u4f3c\u4e8e\u6c7d\u8f66\u4e2d\u7684\u8f6e\u5b50\u3001\u53d1\u52a8\u673a\u7b49\uff0c\u6291\u6216\u6c7d\u8f66\u672c\u8eab\u3002AutoCAD\u4e2d\u6709\u8bb8\u591a\u5bf9\u8c61\uff0c\u4f8b\u5982\uff1a\u6587\u6863\u3001\u6a21\u578b\u7a7a\u95f4\u3001\u76f4\u7ebf\u3001\u56fe\u5c42\u3001\u5b57\u5178\u7b49\u3002Excel\u4e2d\u4e5f\u6709\u8bb8\u591a\u5bf9\u8c61\uff0c\u4f8b\u5982\uff1a\u5de5\u4f5c\u7c3f\u3001\u5de5\u4f5c\u8868\u3001\u5355\u5143\u683c\u3001\u56fe\u8868\u3001\u7a97\u4f53\uff0c\u6216\u662f\u4e00\u4efd\u62a5\u544a\u3002\u7a0b\u5e8f\u4e2d\u8c03\u7528\u5bf9\u8c61\u7684\u4efb\u4e00\u65b9\u6cd5\u6216\u6539\u53d8\u5b83\u7684\u5c5e\u6027\u4e4b\u524d\uff0c\u5fc5\u987b\u5148\u58f0\u660e\u5bf9\u8c61\u5982\uff0cDim oDraw As Object\u6216Dim Workbooks As Object\u3002<\/p>\n\n\n\n<p><strong>\u5bf9\u8c61\u96c6\u5408<\/strong>(Collection)<\/p>\n\n\n\n<p>\u5bf9\u8c61\u96c6\u5408\u662f\u4e00\u4e2a\u5305\u542b\u51e0\u4e2a\u76f8\u540c\u6027\u8d28\u7684\u5bf9\u8c61\u7684\u96c6\u5408\u3002\u4f8b\u5982\uff0c\u5728AutoCAD\u4e2d\u7684Documents \u5bf9\u8c61\u5305\u542b\u4e86\u6240\u6709\u5df2\u6253\u5f00\u7684Document\uff08\u6587\u6863\uff09\u5bf9\u8c61\uff0c\u8fd9\u5f53\u7136\u6307\u591a\u6587\u6863\u73af\u5883(MDI)\u3002\u5728Excel\u4e2d\u7684Workbooks \u5bf9\u8c61\u5305\u542b\u4e86\u6240\u6709\u5df2\u6253\u5f00\u7684Workbook\uff08\u5de5\u4f5c\u7c3f\uff09\u5bf9\u8c61\uff0cWorksheets\u5bf9\u8c61\u96c6\u5408\u5305\u542b\u4e86\u67d0\u4e2a\u5de5\u4f5c\u7c3f\u4e2d\u7684\u6240\u6709\u5de5\u4f5c\u8868Worksheet\u3002<\/p>\n\n\n\n<p>\u96c6\u5408\u4e2d\u7684\u9879\u76ee\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u53f7\u6216\u540d\u79f0\u6765\u505a\u8bc6\u522b\u3002\u4f8b\u5982\uff0cDocuments(1) \u6307\u7684\u662f\u7d22\u5f15\u53f7\u662f1\u7684\u6587\u6863\u5bf9\u8c61\u3002Workbooks(1) \u6307\u7684\u662f\u7d22\u5f15\u53f7\u662f1\u7684\u5de5\u4f5c\u7c3f\u5bf9\u8c61\u3002\u9700\u8981\u6ce8\u610f\u7684\u662fAutoDesk\u662f\u4ece0\u5f00\u59cb\uff0c\u800cMicroSoft\u5219\u662f\u4ece1\u5f00\u59cb\u3002<\/p>\n\n\n\n<p><strong>\u7236\u5bf9\u8c61\u4e0e\u5b50\u5bf9\u8c61<\/strong>(Parent Object And Subobject)<\/p>\n\n\n\n<p>\u6c7d\u8f66\u53ef\u4ee5\u5305\u542b\u8f6e\u5b50\u548c\u53d1\u52a8\u673a\uff0c\u8fd9\u5c31\u662f\u5178\u578b\u7684\u7236\u5bf9\u8c61\u4e0e\u5b50\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p>\u5728AutoCAD\u4e2d\uff0c\u6587\u6863\u5bf9\u8c61\u53ef\u4ee5\u5305\u542b\u76f4\u7ebf\u5bf9\u8c61\u3001\u5706\u5f27\u5bf9\u8c61\u7b49\u3002\u5728Excel\u4e2d\uff0cWorksheet\u5bf9\u8c61\u53ef\u4ee5\u5305\u542b\u5355\u5143\u683c\u5bf9\u8c61\u548c\u56fe\u8868\u5bf9\u8c61\u7b49\u3002<\/p>\n\n\n\n<p><strong>\u65b9\u6cd5<\/strong>(Method)<\/p>\n\n\n\n<p>\u65b9\u6cd5\u6307\u7684\u662f\u5bf9\u8c61\u80fd\u6267\u884c\u7684\u52a8\u4f5c\u3002\u4f8b\u5982\uff0cAdd\u662f\u4e0b\u62c9\u5217\u8868\u63a7\u4ef6ComboBox\u5bf9\u8c61\u7684\u4e00\u4e2a\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u4f1a\u589e\u52a0\u4e00\u4e2a\u65b0\u9879\u76ee\u5230\u4e0b\u62c9\u5f0f\u5217\u8868\u6846\u4e2d\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u7684\u7a0b\u5e8f\u8c03\u7528 Add \u65b9\u6cd5\uff0c\u589e\u52a0\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\u5230\u4e0b\u62c9\u5217\u8868\u63a7\u4ef6\u201cCombo1\u201d\u9879\u76ee\u4e2d\u3002<\/p>\n\n\n\n<p>Sub AddEntry(newEntry as String)&nbsp;&#8216; newEntry\u4f5c\u4e3a\u8fc7\u7a0b\u7684\u53c2\u6570\u88ab\u4f20\u5165\u8fc7\u7a0bAddEntry<\/p>\n\n\n\n<p>Combo1.Add newEntry &#8216; newEntry\u4f5c\u4e3a\u4e00\u4e2a\u9879\u76ee\u589e\u52a0\u5230\u4e0b\u62c9\u5217\u8868\u6846\u4e2d<\/p>\n\n\n\n<p>End Sub<\/p>\n\n\n\n<p>\u67d0\u6587\u6863oDraw\u53e6\u5b58\u4e3aAutoCAD 2000\u7248\uff0cSaveAs\u5c31\u662f\u6587\u6863\u7684\u4e00\u4e2a\u65b9\u6cd5\u3002oDraw.SaveAs sFullName, 12 &#8216;ac2000_dwg = 12, AutoCAD 2000 DWG (*.dwg)<\/p>\n\n\n\n<p>\u5982\u679c\u5bf9\u8c61\u5171\u4eab\u5171\u540c\u7684\u65b9\u6cd5\uff0c\u5219\u53ef\u4ee5\u64cd\u4f5c\u6574\u4e2a\u5bf9\u8c61\u96c6\u5408\u3002\u4f8b\u5982\uff0c\u4e0b\u5217\u7684\u8fc7\u7a0b\u4f1a\u9884\u89c8\u672c\u5de5\u4f5c\u7c3f\u6240\u6709\u7684\u5de5\u4f5c\u8868\u3002oWorkbook.Worksheets.PrintPreview<\/p>\n\n\n\n<p><strong>\u4e8b\u4ef6<\/strong>(Event)<\/p>\n\n\n\n<p>\u4e8b\u4ef6\u662f\u4e00\u4e2a\u5bf9\u8c61\u53ef\u4ee5\u8bc6\u522b\u7684\u52a8\u4f5c\uff0c\u50cf\u5355\u51fb\u9f20\u6807\u6216\u6309\u67d0\u952e\u7b49\uff0c\u5728\u7cfb\u7edf\u6355\u6349\u5230\u5bf9\u8c61\u7684\u4e8b\u4ef6\u540e\uff0c\u6267\u884c\u8be5\u4e8b\u4ef6\u5bf9\u5e94\u7684\u7a0b\u5e8f\u4ee3\u7801\uff0c\u4ece\u800c\u5b9e\u73b0\u76f8\u5e94\u63a7\u5236\u3002<\/p>\n\n\n\n<p>\u4e0d\u540c\u7684\u5bf9\u8c61\u5177\u6709\u4e0d\u540c\u7684\u4e8b\u4ef6\u3002\u4f8b\u5982\uff0c\u6587\u6863\u62e5\u6709\u7684\u4e8b\u4ef6\uff1aActivate\u3001Deactivate\u3001ObjectModified\u3001Save\u7b49\u3002\u5de5\u4f5c\u7c3f\u62e5\u6709\u7684\u4e8b\u4ef6\uff1aOpen\u3001Activate\u3001BeforeClose\u3001BeforePrint\u3001BeforeSave\u3001NewSheet\u3001SheetChange\u7b49\uff0c\u5de5\u4f5c\u8868\u62e5\u6709\u7684\u4e8b\u4ef6\uff1aSelectionChange\u3001Change\u3001Activate\u7b49\u3002<\/p>\n\n\n\n<p>\u5728\u4e8b\u4ef6\u6a21\u5757\u4e2d\u5199\u5165\u9700\u8981\u7684\u4ee3\u7801\uff0c\u5f53\u5bf9\u8c61\u53ef\u8bc6\u522b\u7684\u4e8b\u4ef6\u53d1\u751f\u65f6\uff0c\u8fd9\u4e9b\u4ee3\u7801\u5c06\u88ab\u6267\u884c\u3002<\/p>\n\n\n\n<p>\u7b80\u8981\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>Private Sub oWorkbook_Open()<\/p>\n\n\n\n<p>MsgBox &#8220;\u60a8\u6253\u5f00\u4e86\u5f53\u524d\u7684\u5de5\u4f5c\u7c3f\uff01&#8221;<\/p>\n\n\n\n<p>End Sub<\/p>\n\n\n\n<p><strong>\u5c5e\u6027<\/strong>(Property)<\/p>\n\n\n\n<p>\u4e00\u4e2a\u5bf9\u8c61\u7684\u5c5e\u6027\u5b9a\u4e49\u4e86\u5bf9\u8c61\u7684\u7279\u5f81\uff0c\u8bf8\u5982\u5927\u5c0f\u3001\u989c\u8272\u6216\u5c4f\u5e55\u4f4d\u7f6e\uff0c\u6216\u67d0\u4e00\u65b9\u9762\u7684\u884c\u4e3a\uff0c\u8bf8\u5982\u5bf9\u8c61\u662f\u5426\u6fc0\u6d3b\u6216\u662f\u5426\u53ef\u89c1\u3002\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u5bf9\u8c61\u7684\u5c5e\u6027\u503c\u6765\u6539\u53d8\u5bf9\u8c61\u7684\u7279\u6027\u3002<\/p>\n\n\n\n<p>\u82e5\u8981\u8bbe\u7f6e\u5c5e\u6027\u503c\uff0c\u5219\u5728\u5bf9\u8c61\u7684\u5f15\u7528\u540e\u9762\u52a0\u4e0a\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u5b83\u662f\u7531\u5c5e\u6027\u540d\u52a0\u4e0a\u7b49\u53f7\uff08\uff1d\uff09 \u4ee5\u53ca\u5c5e\u6027\u503c\u6240\u7ec4\u6210\u7684\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0coDraw(0).Name = &#8220;test11&#8243;\u8bbe\u7f6e\u4e860\u53f7\u6587\u6863\u540d\u4e3atest11\u3002\u4e0b\u9762\u7684\u8bed\u53e5\u8bbe\u7f6e\u201ctest\u201d\u5de5\u4f5c\u8868\u7684\u540d\u79f0\u800c\u6539\u53d8\u5de5\u4f5c\u8868\u7684\u6807\u7b7e\u540d\u79f0\u3002oWorkbook.Worksheets(&#8220;test&#8221;).Name = &#8220;test11&#8221;<\/p>\n\n\n\n<p>\u6709\u4e9b\u5c5e\u6027\u5e76\u4e0d\u80fd\u8bbe\u7f6e\uff0c\u53ea\u80fd\u8bfb\u53d6\u3002\u901a\u8fc7\u68c0\u7d22\u6bcf\u5c5e\u6027\u7684\u5e2e\u52a9\u4e3b\u9898\uff0c\u53ef\u4ee5\u770b\u5230\u662f\u5426\u53ef\u4ee5\u8bbe\u7f6e\u6b64\u5c5e\u6027\uff08\u8bfb\u4e0e\u5199\uff09\uff0c\u6216\u53ea\u80fd\u8bfb\u53d6\u6b64\u5c5e\u6027\uff08\u53ea\u8bfb\uff09\uff0c\u8fd8\u662f\u53ea\u80fd\u5199\u5165\u6b64\u5c5e\u6027\uff08\u53ea\u5199\uff09\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u901a\u8fc7\u5c5e\u6027\u7684\u8fd4\u56de\u503c\uff0c\u6765\u68c0\u7d22\u5bf9\u8c61\u7684\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>Debug.Print oDraw(0).FullName<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9\u8c61(Object) \u5bf9\u8c61\u4ee3\u8868\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u5143\u7d20\uff0c\u7c7b\u4f3c\u4e8e\u6c7d\u8f66\u4e2d\u7684\u8f6e\u5b50\u3001\u53d1\u52a8\u673a\u7b49\uff0c\u6291\u6216\u6c7d\u8f66\u672c\u8eab\u3002AutoCAD\u4e2d\u6709 &hellip; <a href=\"https:\/\/www.wyrcad.com\/?p=1267\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b(OOP)\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[24,17],"class_list":["post-1267","post","type-post","status-publish","format-standard","hentry","category-bianchengyuandi","tag-vb","tag-biancheng"],"_links":{"self":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1267"}],"version-history":[{"count":8,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1267\/revisions"}],"predecessor-version":[{"id":1283,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1267\/revisions\/1283"}],"wp:attachment":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}