{"id":213,"date":"2009-04-11T12:23:57","date_gmt":"2009-04-11T12:23:57","guid":{"rendered":""},"modified":"2009-04-11T12:23:57","modified_gmt":"2009-04-11T12:23:57","slug":"213","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=213","title":{"rendered":"C# \u4e2d\u52a8\u6001\u6dfb\u52a0\u63a7\u4ef6\u53ca\u5176\u4e8b\u4ef6"},"content":{"rendered":"<p>\u9996\u5148,\u521b\u5efa\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf&#8221;i &#8220;\u7528\u6765\u533a\u5206\u5404\u4e2a\u65b0\u7684\u6309\u94ae:<br \/>private int i=0;<br \/>\u7136\u540e\u5728\u5df2\u6709\u7684\u6309\u94ae\u4e2d\u6dfb\u52a0\u65b9\u6cd5\u5982\u4e0b:<br \/><code><br \/>&nbsp;&nbsp; private void button1_Click(object sender, System.EventArgs e)<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;i++;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Button b = new Button();\/\/\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6309\u94ae<br \/>&nbsp;&nbsp;&nbsp;&nbsp;b.Name=\"b\"+i;\/\/\u8fd9\u662f\u6211\u7528\u6765\u533a\u522b\u5404\u4e2a\u6309\u94ae\u7684\u529e\u6cd5<br \/>&nbsp;&nbsp;&nbsp;&nbsp;System.Drawing.Point p = new Point(12,13+i*30);\/\/\u521b\u5efa\u4e00\u4e2a\u5750\u6807,\u7528\u6765\u7ed9\u65b0\u7684\u6309\u94ae\u5b9a\u4f4d<br \/>&nbsp;&nbsp;&nbsp;&nbsp;b.Location = p;\/\/\u628a\u6309\u94ae\u7684\u4f4d\u7f6e\u4e0e\u521a\u521b\u5efa\u7684\u5750\u6807\u7ed1\u5b9a\u5728\u4e00\u8d77<br \/>&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;panel1.Controls.Add(b);\/\/\u5411panel\u4e2d\u6dfb\u52a0\u6b64\u6309\u94ae<br \/>&nbsp;&nbsp;&nbsp;&nbsp;b.Click += new System.EventHandler(btn_click);\/\/\u5c06\u6309\u94ae\u7684\u65b9\u6cd5\u7ed1\u5b9a\u5230\u6309\u94ae\u7684\u5355\u51fb\u4e8b\u4ef6\u4e2db.Click\u662f\u6309\u94ae\u7684\u5355\u51fb\u4e8b\u4ef6 <br \/>&nbsp;&nbsp; }<br \/><\/code><br \/>\u5b8c\u6210\u4ee5\u4e0a\u6b65\u9aa4\u5c31\u5df2\u7ecf\u53ef\u4ee5\u8fdb\u884c\u52a8\u6001\u6309\u94ae\u7684\u521b\u5efa<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u6765\u8bb2\u5982\u4f55\u5bf9\u65b0\u5efa\u7684\u6309\u94ae\u6dfb\u52a0\u5bf9\u5e94\u7684\u4e8b\u4ef6\u65b9\u6cd5btn_click():<br \/><code><br \/>&nbsp;&nbsp; private void btn_click(object sender, System.EventArgs e)<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Button b1 = (Button)sender;\/\/\u5c06\u89e6\u53d1\u6b64\u4e8b\u4ef6\u7684\u5bf9\u8c61\u8f6c\u6362\u4e3a\u8be5Button\u5bf9\u8c61<br \/>&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp; MessageBox.Show(\"\"+b1.Name);<br \/>&nbsp;&nbsp; }<br \/><\/code><br \/>\u81f3\u6b64\u5c31\u5df2\u7ecf\u5b8c\u6210\u4e86\u52a8\u6001\u521b\u5efa\u6309\u94ae\u548c\u4e8b\u4ef6<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148,\u521b\u5efa\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf&#8221;i &#8220;\u7528\u6765\u533a\u5206\u5404\u4e2a\u65b0&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","category-NET"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=213"}],"version-history":[{"count":0,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/213\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}