2009-06-14 10 views
0

私は以下のような状況に陥っています。 私の機能では、XMLファイルを取得し、それを解析し、XMLファイルの各ポストノードの画像とテキストボックスを含むグループボックスを追加します。ボックスには名前とツールストリップメニューが割り当てられています。このアイテムはクリックしたときに表示されます(アイテムにはJeffという名前が付けられています)。メニューアイテムJeffを押してテキストを追加するとテキストボックス(テキストは「@Jeff」です)。私はtoolstripmenuに名前を追加することができますが、私はそれを作って、各人のテキストボックスに名前を追加します。C#toolstrip menu&something more

そしてここに私の機能があるので、あなたは私が何を話しているかを見ることができた

public void parseXmlatme() 

    { 


     string sUser, sUrl; 

     string avatar; 
     sUser = Settings.Default.user; 
     AtMeFlowLayoutPanel.Controls.Clear(); 
     sUrl = "http://edno23.com/api/xml/get.php?username=" + sUser + "&type=posts_mention_me"; 
     rssReader = new XmlTextReader(sUrl.ToString()); 
     rssDoc = new XmlDocument(); 
     rssDoc.Load(rssReader); 

     for (int i = 0; i < rssDoc.ChildNodes.Count; i++) 
     { 
      if (rssDoc.ChildNodes[i].Name == "edno23") 
      { 
       nodeRss = rssDoc.ChildNodes[i]; 
      } 
     } 

     for (int i = 0; i < nodeRss.ChildNodes.Count; i++) 
     { 
      if (nodeRss.ChildNodes[i].Name == "posts") 
      { 
       nodeChannel = nodeRss.ChildNodes[i]; 
      } 
     } 

     for (int i = 0; i < nodeChannel.ChildNodes.Count; i++) 
     { 
      if (nodeChannel.ChildNodes[i].Name == "post") 
      { 
       nodeItem = nodeChannel.ChildNodes[i]; 
       string C; 
       C = nodeItem["user_from"].InnerText; 
       avatar = nodeItem["user_from_avatar"].InnerText; ; 
       // 
       // groupBox1 
       // 
       GroupBox grpBox = new GroupBox(); 
       TextBox txtBox = new TextBox(); 
       PictureBox picBox = new PictureBox(); 
       ContextMenuStrip rightMenu = new ContextMenuStrip(); 
       ToolStripMenuItem atMe = new ToolStripMenuItem(); 

       // 
       // rightMenu 
       // 
       rightMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 
       atMe}); 
       rightMenu.Name = "rightclick"; 
       rightMenu.Size = new System.Drawing.Size(153, 70); 
       // 
       // toolStripMenuItem2 
       // 
       atMe.Name = "toolStripMenuItem2"; 
       atMe.Size = new System.Drawing.Size(152, 22); 
       atMe.Text = "@"+C; 
       name = C; 
       atMe.Click += atMe_Click; 



       //// 
       grpBox.Location = new System.Drawing.Point(3, 3); 
       grpBox.Name = "grpBoxatme" + i; 
       grpBox.Size = new System.Drawing.Size(301, 73); 
       grpBox.TabIndex = 0; 
       grpBox.TabStop = false; 
       grpBox.Text = C; 
       grpBox.ContextMenuStrip = rightMenu; 
       // rightMenu.Items.Add(C); 
       // txtbox 
       txtBox.BackColor = System.Drawing.SystemColors.ControlLightLight; 
       txtBox.Location = new System.Drawing.Point(59, 16); 
       txtBox.Multiline = true; 
       txtBox.Name = "txtBoxatme" + i; 
       txtBox.ReadOnly = true; 
       txtBox.Size = new System.Drawing.Size(235, 49); 
       txtBox.TabIndex = 2; 
       txtBox.Text = nodeItem["message"].InnerText; 

       //pic box 
       picBox.Dock = System.Windows.Forms.DockStyle.Left; 
       picBox.ImageLocation = "http://img.edno23.com/avatars/thumbs/" + avatar; 
       picBox.Location = new System.Drawing.Point(3, 16); 
       picBox.Name = "pictureBoxatme" + i; 
       picBox.Size = new System.Drawing.Size(50, 54); 
       picBox.TabIndex = 0; 
       picBox.TabStop = false; 

       AtMeFlowLayoutPanel.Controls.Add(picBox); 
       AtMeFlowLayoutPanel.Controls.Add(grpBox); 
       grpBox.Controls.Add(picBox); 
       grpBox.Controls.Add(txtBox); 
      } 
     } 




    } 

ありがとうございます。

答えて

0

ここに私は質問を解決するのに役立つ手がかりです。

using System; 

using System.Drawing; 

using System.Windows.Forms; 

    public partial class Form1 : Form 
    { 
     public Button sb; 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      for (int x = 0; x < 10; x++) 
      { 
       sb = new Button(); 
       sb.Size = new Size(25, 25); 
       sb.Location = new Point(x * 25, 10); 
       sb.Visible = true; 
       sb.Text = x.ToString(); 
       sb.Click += new EventHandler(sb_Click); 
       Controls.Add(sb); 
      } 
     } 

     private void sb_Click(object sender, System.EventArgs e) 
     { 
      Button sb = sender as Button; 
      this.Text = sb.Text; 
     } 
    }