2012-05-23 3 views
0

C에서 linkLabels 묶음을 생성합니다. #. 내가 원하는 것은 각 linkLabel과 다른 URL로 textBox1을 채우는 것입니다. 동적 이벤트는 어떻게 생성합니까? 노드 텍스트 tempAtt.Value, 그리고에 당신은 그것을 얻을 수있을 것이다은을 textBox1 당신은 직접 이벤트에 DAT를 전달할 수 없습니다 att.ValueC#에서 이벤트를 동적으로 생성 하시겠습니까?

+0

삭제하지 말고 다시 게시하십시오. 질문을 편집 할 수 있습니다. –

답변

2

로 채워 져야 클릭해야

foreach (var node in nodes) 
{ 
    HtmlAttribute att = node.Attributes["href"]; 
    HtmlAgilityPack.HtmlDocument tempDoc = new HtmlAgilityPack.HtmlDocument(); 
    tempDoc.LoadHtml(node.InnerHtml); 
    var tempNode = tempDoc.DocumentNode.SelectSingleNode("//img[@alt]"); 
    HtmlAttribute tempAtt = tempNode.Attributes["alt"]; 
    LinkLabel ll = new LinkLabel(); 
    ll.Location = new Point(20, 20 * i); 
    ll.Text = tempAtt.Value; 
    this.Controls.Add(ll); 
    i++; 
} 

:이 예입니다 핸들러 내부에서 다른 방법으로.

foreach (var node in nodes) 
{ 
    ... 
    LinkLabel ll = new LinkLabel(); 
    ... 
    ll.Click += MyLabelClickHandler; 
    this.Controls.Add(ll); 

    i++; 
} 

void MyLabelClickHandler(object sender, Eventargs e) 
{ 
    senderLabel = sender as LinkLabel; 
    string text = senderlabel.text; 
    .... 
} 
관련 문제