C# 在panel中動態新增按鈕 與 分批刪除
阿新 • • 發佈:2019-01-05
參考文章:
①http://www.cnblogs.com/yuzhihui/p/5749233.html
②http://www.cnblogs.com/steed-zgf/archive/2012/04/03/2430819.html
先來一張效果圖。
畫布中的圖片是以 button 的屬性BackgroundImage = global::TEST4.Properties.Resources.畫布活動鉸支;
PS1: [如果要背景圖片透明效果 需要 把 圖片用PS 擦除 儲存為PNG格式]
在同一張畫布中,清除控制元件的常用方法有
panel.Controls.Clear(); 該方法是一次性清除畫布上的所有子控制元件,不能分批清除
panel.Controls.Remove(); ()中返回的是Control類,
單純的用foreach方法 是不能一次性清除同一類的控制元件,
參考文章②中有提到;
//標頭檔案 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Threading; namespace TEST4 { public partial class Form1 : Form { public float RodLength; public Single RodLength_rate; public string gdzhidianweizhi; public string hdzhidianweizhi; public int count11; public int count22; Button but1; Button butt2; static int G = 0; static int Q = 0; //Button butt2; public Form1() { InitializeComponent(); //this.button6.Parent = this.button7 ; //this.button7.Parent = this.panel3; }
/////////////////////////////////////////////////////////////////////////////////從此開始
////出現suitch 和try-catch都是針對textbox輸入時 中斷的 格式異常處理
1.
2.
3.
4.
5.
思路: 文字框中用split(",")切割文字,
例項化按鈕時 butt2.Name ,然後由此來作為刪除的判斷