Let’s take a look at this effect first
Give you an idea:
Rewrite the TabControl control and overload the OnPaint method
public class CustomTabControl : TabControl
{
//......
protected override void OnPaint(PaintEventArgs e)
{
this.PaintTransparentBackground(e.Graphics, base.ClientRectangle);
this.PaintAllTheTabs(e);
this.PaintTheTabPageBorder(e);
this.PaintTheSelectedTab(e);
}
//......
}
Create an MDI window and add a ToolStrip control.
Create a form base class
public class BaseForm: Form{
protected ToolStrip toolStrip;
public static ListtoolStripItemList = new Lis();
protected void AddToolStrip(ToolStripItem toolStripItem){
toolStripItemList.add(toolStripItem);
if(toolStrip != null){
toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[]{ toolStripItem });
}
}
protected void SubToolStrip(string formName){
if(toolStrip != null){
foreach (ToolStripItem i in toolStripItemList){
if (i.Name == formName){
toolStrip1.Items.remove(i);
}
}
}
}
}
Create a parent form base class
public class MdiForm: BaseForm{
//Create a ToolStrip control toolStrip1 in the Mdi form and assign it to toolStrip in the base class
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
toolStrip = this.toolStrip1;
}
}
Create a subform base class
public class ChildForm: BaseForm{
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
ToolStripItem toolStripItem = new ToolStripItem();
toolStripItem.Name = this.Name;
toolStripItem.Text = "xxxxxx";
AddToolStrip(toolStripItem);
}
protected override void OnFormClosed(FormClosedEventArgs e) {
base.OnFormClosed(e);
SubToolStrip(this.Name);
}
}
It’s just a simple idea. All forms inherit a base class at the same time. Create two objects in this base class: ToolStrip (a control for adding buttons on the Mdi window) and List (for simplicity here, a simple List, if you want to add other effects, such as field changes in a form, so that the buttons on the ToolStrip have different realistic effects, pictures, etc., you need to create a ToolStripButtonCollection) every time a new subform is loaded, Just add an item to the ToolStripButtonCollection, and the ToolStripButtonCollection will automatically add a button to the ToolStrip. Similarly, if the ToolStripButtonCollection decreases an item, the ToolStrip will automatically decrease a button. Here you can also detect some values in the ToolStripButtonCollection, such as determining whether the field has changed, whether Need to save etc.
Then create the Mdi form and initialize toolStrip in the base class;
After creating a subform, as long as it is a subform inherited from ChildForm, a button named after the name of the subform will be automatically created on the Mdi window, which is very similar to the effect you want. The above code is just for demonstration. The important thing is the creation of the ToolStripButtonCollection class.
The above is the detailed content of How to implement rounded tab drawing in winform. For more information, please follow other related articles on the PHP Chinese website!