Create new button for each email c# winforms
Hi i have the following code that allows me to create a new list view item for every email in my inbox, my question is how would i create a new button for each email instead of a list view item.
int i;
for (i = 0; i < bundle.MessageCount - 0; i++)
{
email = bundle.GetEmail(i);
System.Windows.Forms.ListViewItem itmp = new System.Windows.Forms.ListViewItem(email.From);
开发者_高级运维 System.Windows.Forms.ListViewItem.ListViewSubItem itms1 = new System.Windows.Forms.ListViewItem.ListViewSubItem(itmp, email.Subject);
System.Windows.Forms.ListViewItem.ListViewSubItem itms2 = new System.Windows.Forms.ListViewItem.ListViewSubItem(itmp, email.FromName);
itmp.SubItems.Add(itms1);
itmp.SubItems.Add(itms2);
listView1.Items.Add(itmp).Tag = i;
richTextBox1.Text = email.Body;
Just add a button the same way - it inherits from Control
:
System.Windows.Forms.Button button = new System.Windows.Forms.Button();
button.Text = "My button";
button.OnClick += new EventHandler(myButton_Click); // myButton_Click should exist
listView1.Items.Add(button);
You can create a new Button()
, set properties and add event handlers, then add it to a container's Controls
collection.
精彩评论