C# 在panel中动态添加按钮 与 分批删除

参考文章:

①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  ,然后由此来作为删除的判断

          

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值