问题描述
怎么通过判断数组里的值如果是1就在flowLayoutPane里动态创建一个button如果是0就不创建。代码写到这了。。。不知道怎么写了privatevoidflowLayoutPanel1_Paint(objectsender,PaintEventArgse){stringpath="F:test.txt";string[]a=File.ReadAllLines(path);int[]b=newint[a.Length];for(inti=0;i<a.Length;i++){b[i]=int.Parse(a[i]);}
解决方案
解决方案二:
privatevoidflowLayoutPanel1_Paint(objectsender,PaintEventArgse){stringpath="F:test.txt";string[]a=File.ReadAllLines(path);for(inti=0;i<a.Length;i++){if(Regex.IsMatch(a[i],@"^s*1s*$"){Buttonbtn=newButton();this.Controls.Add(btn);}}
解决方案三:
if(b[i]!=0)
解决方案四:
privatevoidflowLayoutPanel1_Paint(objectsender,PaintEventArgse){stringpath="F:test.txt";string[]a=File.ReadAllLines(path);int[]b=newint[a.Length];for(inti=0;i<a.Length;i++){b[i]=int.Parse(a[i]);if(b[i]!=0){//创建ButtonButtonbtn=newButton();btn.Name="btn"+i.ToString();btn.Text="按钮"+i.ToString();this.Controls.Add(btn);//添加到窗体}}
解决方案五:
引用1楼superwfei的回复:
privatevoidflowLayoutPanel1_Paint(objectsender,PaintEventArgse){stringpath="F:test.txt";string[]a=File.ReadAllLines(path);for(inti=0;i<a.Length;i++){if(Regex.IsMatch(a[i],@"^s*1s*$"){Buttonbtn=newButton();this.Controls.Add(btn);}}
Regex这个是什么呢
解决方案六:
引用4楼liuuilliuuil123的回复:
Quote: 引用1楼superwfei的回复:
privatevoidflowLayoutPanel1_Paint(objectsender,PaintEventArgse){stringpath="F:test.txt";string[]a=File.ReadAllLines(path);for(inti=0;i<a.Length;i++){if(Regex.IsMatch(a[i],@"^s*1s*$"){Buttonbtn=newButton();this.Controls.Add(btn);}}Regex这个是什么呢
你不会度娘一下啊,撸主正则判断嘛