المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : C#: Need help deleting new button instances that i've create in my program! Please Help!



C# Programming
10-01-2009, 10:41 AM
Hi, http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif I'm currently stuck at my assignment where I need to create new buttons by naming it and also able to delete it after right clicking on it, choosing "delete" from the contextMenu

Here's my code


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace New_One
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_MouseDown(object sender, MouseEventArgs e)
{
Point p = new Point(e.X, e.Y);


if (e.Button == MouseButtons.Right)
{
contextMenuStrip1.Show(button1, p);
}

}

private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
button1.Dispose();
//I don't know what to enter here to delete the new button...

}

private void bt_add_Click(object sender, EventArgs e)
{
Button newButton = new Button();
newButton.Name = tb_name.Name;
newButton.Text = tb_name.Text;
flowLayoutPanel1.Controls.Add(newButton);
newButton.MouseDown += new MouseEventHandler(newButton_MouseDown);

}

void newButton_MouseDown(object sender, MouseEventArgs e)
{

Point p = new Point(e.X, e.Y);


if (e.Button == MouseButtons.Right)
{
//I don't know what to enter here to right click next to
//the new button...
//I tried this --> contextMenuStrip1.Show(newbutton ,p);
//but it can't work?!
}

}




}
}