{"id":235214,"date":"2022-02-10T08:38:07","date_gmt":"2022-02-10T00:38:07","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=235214"},"modified":"2022-01-30T13:39:12","modified_gmt":"2022-01-30T05:39:12","slug":"linux-object-system","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-object-system.html","title":{"rendered":"\u7b80\u5355\u63a2\u8ba8C#\u4e2dGUI\u7f16\u7a0b\u7684\u6807\u51c6\u4e8b\u4ef6\u95ee\u9898"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86C#\u4e2dGUI\u7f16\u7a0b\u7684\u6807\u51c6\u4e8b\u4ef6,\u672c\u6587\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u5de5\u4f5c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u501f\u9274\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b
\n<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u524d\u8a00<\/strong><\/div>\n

\u6628\u5929\u7684\u6587\u7ae0\uff0c\u5e26\u5927\u5bb6\u7b80\u5355\u5b66\u4e60C#\u4e2d\u7684\u4e8b\u4ef6\uff0c\u4e86\u89e3\u8ba2\u9605\u8005\u548c\u53d1\u5e03\u8005\u4e4b\u95f4\u7684\u903b\u8f91\u5173\u8054\uff0c\u4e5f\u901a\u8fc7\u5c0f\u6848\u4f8b\u8fdb\u884c\u5b9e\u9645\u64cd\u4f5c\uff0c\u53ef\u4ee5\u770b\u5230\u5177\u4f53\u7684\u8f93\u51fa\u7ed3\u679c\u3002<\/p>\n

\u76ee\u524d\u5728\u5de5\u4f5c\u4e2d\uff0c\u4f7f\u7528Winform\u684c\u9762\u5f00\u53d1\u6bd4\u8f83\u591a\uff0c\u5f88\u591a\u65f6\u5019\u5c31\u4f1a\u7528\u5230\u4e8b\u4ef6\uff0c\u6b64\u65f6\u8fd9\u91cc\u7684\u4e8b\u4ef6\u7528\u6cd5\u6709\u4e00\u4e2a\u4fd7\u79f0\u53ebGUI\u7f16\u7a0b\u3002<\/p>\n

\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u5b83\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u5019\u88ab\u6253\u65ad\uff0c\u6bd4\u5982\u6309\u94ae\u70b9\u51fb\uff0c\u6309\u4e0b\u6309\u952e\u6216\u7cfb\u7edf\u5b9a\u65f6\u5668\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u53d1\u751f\u65f6\uff0c\u7a0b\u5e8f\u9700\u8981\u5904\u7406\u4e8b\u4ef6\u7136\u540e\u7ee7\u7eed\u5176\u4ed6\u4e8b\u60c5\u3002<\/p>\n

\u5728Windows GUI\u7f16\u7a0b\u4e2d\u7ecf\u5e38\u4f1a\u7528\u5230\u7a0b\u5e8f\u4e8b\u4ef6\u7684\u5f02\u6b65\u5904\u7406\u3002<\/p>\n

\u4ec0\u4e48\u662fGUI\u4e2d\u7684\u6807\u51c6\u4e8b\u4ef6<\/strong><\/div>\n

\u8fd9\u79cd\u7a0b\u5e8f\u4e8b\u4ef6.NET\u6846\u67b6\u63d0\u4f9b\u4e00\u4e2a\u6807\u51c6\u6a21\u5f0f\u3002\u4f7f\u7528System\u547d\u540d\u7a7a\u95f4\u4e0b\u7684EventHandler\u59d4\u6258\u7c7b\u578b\u3002<\/p>\n

public delegate void EventHandler(object sender,EventArgs e)<\/pre>\n

\u5176\u4e2d\u5173\u4e8e\u58f0\u660eEventHandle\u59d4\u6258\u7c7b\u578b\uff0c\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u4e09\u70b9\uff1a<\/p>\n

\u7b2c\u4e00\u4e2a\u53c2\u6570\u7528\u4e8e\u4fdd\u5b58\u89e6\u53d1\u4e8b\u4ef6\u7684\u5bf9\u8c61\u7684\u5f15\u7528<\/p>\n

\u7b2c\u4e8c\u4e2a\u53c2\u6570\u7528\u4e8e\u4fdd\u5b58\u72b6\u6001\u4fe1\u606f\uff0c\u6307\u660e\u4ec0\u4e48\u7c7b\u578b\u9002\u7528\u4e8e\u8be5\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u8fd4\u56de\u7c7b\u578b\u662fvoid<\/p>\n

\u5173\u4e8e\u7b2c\u4e8c\u4e2a\u53c2\u6570\u7c7b\u578bEventArgs\u8fd9\u91cc\u7279\u522b\u9700\u8981\u8bf4\u660e\u4e0b\uff0c\u5b83\u4e0d\u662f\u4e3a\u4e86\u4f20\u9012\u53c2\u6570\u800c\u8bbe\u8ba1\u7684\uff0c\u5f53\u5b83\u7528\u4e8e\u4e0d\u9700\u8981\u4f20\u9012\u53c2\u6570\u7684\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u65f6\u8be5\u5ffd\u7565\uff0c\u5982\u679c\u9700\u8981\u4f20\u9012\u53c2\u6570\u90a3\u4e48\u5c31\u5fc5\u987b\u58f0\u660e\u4e00\u4e2a\u6d3e\u751f\u81eaEventArgs\u7684\u7c7b\uff0c\u4f7f\u7528\u5408\u9002\u7684\u5b57\u6bb5\u6765\u4fdd\u5b58\u9700\u8981\u4f20\u9012\u7684\u6570\u636e<\/p>\n

\u4e0d\u7ba1\u53c2\u6570\u4f7f\u7528\u7684\u5b9e\u9645\u7c7b\u578b\u662f\u4ec0\u4e48\uff0cObject\u7c7b\u548cEventArgs\u7c7b\u90fd\u662f\u57fa\u7c7b\u3002\u8fd9\u6837EventHandler\u5c31\u53ef\u63d0\u4f9b\u4e00\u4e2a\u5bf9\u6240\u6709\u4e8b\u4ef6\u548c\u4e8b\u4ef6\u5904\u7406\u5668\u90fd\u901a\u7528\u7684\u7b7e\u540d\uff0c\u53ea\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u800c\u4e0d\u662f\u5404\u81ea\u90fd\u6709\u4e0d\u540c\u7684\u7b7e\u540d\u3002<\/p>\n

\u6807\u51c6\u4e8b\u4ef6\u7684\u7528\u6cd5<\/strong><\/div>\n

\u8fd9\u91cc\u8fd8\u7ee7\u7eed\u5bf9\u6628\u5929\u6587\u7ae0\u4e2d\u7684\u6848\u4f8b\u8fdb\u884c\u4fee\u6539\uff0c\u963f\u8f89\u8ba2\u9605\u4e86\u62a5\u793e\u7684\u62a5\u7eb8\uff0c\u5f53\u62a5\u793e\u53d1\u62a5\u65f6\uff0c\u963f\u8f89\u5c31\u80fd\u6536\u5230\u62a5\u7eb8\u8fdb\u884c\u9605\u8bfb\u3002
\n\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n

\u58f0\u660e\u7cfb\u7edf\u5b9a\u4e49\u65f6\u4f7f\u7528EventHandler\u66ff\u6362Handler<\/p>\n

\u963f\u8f89\u8ba2\u9605\u8005\u4e2d\u7684\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u7b7e\u540d\u5e94\u548c\u4e8b\u4ef6\u59d4\u6258\u7684\u7b7e\u540d\u5339\u914d(\u4e0d\u4f20\u9012\u6570\u636e\u65f6\u53ef\u5ffd\u7565)<\/p>\n

\u89e6\u53d1\u4e8b\u4ef6\u7684\u4ee3\u7801\u5728\u8c03\u7528\u65f6\u5fc5\u987b\u4f7f\u7528\u9002\u5f53\u7684\u53c2\u6570\u7c7b\u578b\u5bf9\u8c61<\/p>\n

\u62a5\u793e<\/strong><\/span><\/div>\n
\r\n\/\/\/ \r\n   \/\/\/ \u62a5\u793e\r\n   \/\/\/ <\/summary>\r\n   class NewspaperOffice \r\n   {\r\n       public event EventHandler StartPublishPaper;                \/\/1\u3001\u58f0\u660e\u4e8b\u4ef6\r\n \r\n       public void Publish()\r\n       {\r\n           Console.WriteLine(\"\u5df2\u53d1\u5e03\u62a5\u7eb8\uff01\");\r\n           StartPublishPaper(this,null);               \/\/3\u3001\u89e6\u53d1\u4e8b\u4ef6\uff0c\u901a\u77e5\u8ba2\u9605\u8005\u6536\u62a5\u7eb8\u8fdb\u884c\u9605\u8bfb\r\n       }\r\n   }<\/pre>\n
\u963f\u8f89\u8ba2\u9605\u8005<\/strong><\/span><\/div>\n
\r\n\/\/\/ \r\n   \/\/\/ \u963f\u8f89 \u8ba2\u9605\u8005\r\n   \/\/\/ <\/summary>\r\n   class AhuiPeople \r\n   {\r\n       public AhuiPeople(NewspaperOffice npo)\r\n       {\r\n           npo.StartPublishPaper += SubscriptinPaper;            \/\/2\u3001\u8ba2\u9605\u4e8b\u4ef6\r\n       }\r\n        \r\n       void SubscriptinPaper(object sender,EventArgs e)\r\n       {\r\n           Console.WriteLine(\"\u963f\u8f89\u63a5\u6536\u5230\u62a5\u7eb8\uff0c\u5f00\u59cb\u9605\u8bfb\uff01\");\r\n       }\r\n   }<\/pre>\n
\u89e6\u53d1\u4e8b\u4ef6\u5f00\u59cb\u53d1\u62a5<\/strong><\/span><\/div>\n
\r\nstatic void Main(string[] args)\r\n       {\r\n           NewspaperOffice npo = new NewspaperOffice();\r\n           AhuiPeople ahuiPeople = new AhuiPeople(npo);\r\n \r\n           \/\/\u62a5\u793e\u53d1\u62a5\r\n           Console.WriteLine(\"\u62a5\u793e\u8ba1\u5212\u5f00\u59cb\u53d1\u62a5\uff01\");\r\n           npo.Publish();\r\n           Console.ReadKey();\r\n       }<\/pre>\n
\u8f93\u51fa\u7ed3\u679c<\/strong><\/span><\/div>\n

\"\"<\/p>\n

\u8fd9\u91cc\u7b80\u5355\u4ecb\u7ecd\u6807\u51c6\u7684GUI\u7f16\u7a0b\u4e2d\u7684\u4e8b\u4ef6\uff0c\u6ca1\u6709\u7528\u4e8e\u4f20\u9012\u53c2\u6570\u3002\u4e0b\u4e00\u7bc7\u6587\u7ae0\u5c06\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u6807\u51c6\u4e8b\u4ef6\u6765\u4f20\u9012\u53c2\u6570\u7528\u4e8eWinform\u4e2d\u7684\u5f02\u6b65\u5904\u7406\u3002<\/p>\n

\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8eC#\u4e2dGUI\u7f16\u7a0b\u7684\u6807\u51c6\u4e8b\u4ef6\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"

\u6628\u5929\u7684\u6587\u7ae0\uff0c\u5e26\u5927\u5bb6\u7b80\u5355\u5b66\u4e60C#\u4e2d\u7684\u4e8b\u4ef6\uff0c\u4e86\u89e3\u8ba2\u9605\u8005\u548c\u53d1\u5e03\u8005\u4e4b\u95f4\u7684\u903b\u8f91\u5173\u8054\uff0c\u4e5f\u901a\u8fc7\u5c0f\u6848\u4f8b\u8fdb\u884c\u5b9e\u9645\u64cd\u4f5c\uff0c\u53ef\u4ee5\u770b\u5230\u5177 […]<\/p>\n","protected":false},"author":362,"featured_media":234615,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-235214","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/235214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=235214"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/235214\/revisions"}],"predecessor-version":[{"id":235227,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/235214\/revisions\/235227"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/234615"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=235214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=235214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=235214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}