回覆列表
  • 1 # 使用者1535246701791

    單擊button1在panel上動態新建了多個label,現在想要點選選擇某個動態新建的label,按button2,可以把這個label刪掉在button1_Click事件中,建立label,程式碼:Labellb1=newLabel(); lb1.Name="panel"+j; lb1.BackColor=Color.Transparent; lb1.BorderStyle=BorderStyle.FixedSingle; Panel1.Controls.Add(lb1);為這些label增加Click事件 Labellb1=newLabel(); lb1.Name="panel"+j; lb1.BackColor=Color.Transparent; lb1.Click+=newEventHandler(label_Click); lb1.BorderStyle=BorderStyle.FixedSingle;Panel1.Controls.Add(lb1);stringname="";privatevoidlabel_Click(objectsender,EventArgse){ Labellbl=senderasLabel; name=lbl.Name;}然後在Button2的Click中:privatevoidbutton2_Click(objectsender,EventArgse){ Labellbl=Panel1.Controls[name]; if(lbl!=null) Panel1.Controls.Remove(lbl);}

  • 中秋節和大豐收的關聯?
  • 世界“醫學”奇蹟,長達24年面癱的病人居然被喬碧羅“治癒”,你如何評價?