I'm trying to create a tabbed notepad application but having problems in deleting the "close buttons" on the tabs. The tabs gets removed as they should, but I'm only able to remove 1 close button. Can anyone please help and direct me into the right direction:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace My_Notepad
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int TabCount = 0;
int btx = 96;
private int i;
public void newBox()
{
TabPage tp = new TabPage("New Document ");
RichTextBox rtb = new RichTextBox();
rtb.Dock = DockStyle.Fill;
tp.Controls.Add(rtb);
tabControl1.TabPages.Add(tp);
this.tabControl1.SelectedTab = tp;
this.tabControl1.Appearance = TabAppearance.FlatButtons;
Button btnPlay = new Button();
this.btnPlay = btnPlay;
btnPlay.Width = 16;
btnPlay.Height = 18;
btnPlay.FlatStyle = FlatStyle.Flat;
btnPlay.FlatAppearance.BorderSize = 0;
btnPlay.Top = 25;
btnPlay.Left = btx;
btnPlay.Image = Image.FromFile(@"C:\\close-button.png");
btnPlay.Click += new EventHandler(btnPlay_Click);
this.Controls.Add(btnPlay);
btnPlay.BringToFront();
TabCount++;
i++;
}
private void btnPlay_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab.Dispose();
this.Controls.Remove(btnPlay);
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
newBox();
btx = btx + 126;
}
public Button btnPlay { get; set; }
}
}