C#在panel中动态添加按钮与分批删除参考⽂章:
先来⼀张效果图。
画布中的图⽚是以 button 的属性BackgroundImage = global::TEST4.Properties.Resources.画布活动铰⽀; PS1: [如果要背景图⽚透明效果 需要 把 图⽚⽤PS 擦除 保存为PNG格式]
在同⼀张画布中,清除控件的常⽤⽅法有
system的头文件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  ,然后由此来作为删除的判断

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。