相关疑难解决方法(0)

自定义TabControl以关闭单个选项卡

我的方案如下:

我正在使用C#中的winforms应用程序,它在tabcontrol的主页面内有一个按钮,每次单击它时都会生成另一个tabpage.每个新标签页都将包含由用户控件定义的布局.

我的问题是:

  1. 如何允许用户关闭在运行时动态创建的其中一个选项卡?

  2. 我如何修改tabcontrol本身,以便在每个标签中都有一个小的"X",用户可以点击该标签以关闭该特定标签?(像Firefox一样)

  3. 如果我想用用户控件中的按钮关闭选项卡,我怎样才能将tabcontrol的SelectedIndex属性公开给用户控件呢?

c# user-interface controls tabcontrol winforms

18
推荐指数
3
解决办法
5万
查看次数

带关闭和添加按钮的TabControl

我想让一个标签控件有一个"x"(关闭按钮)和"+"(新标签按钮).我找到了一个添加a的解决方案x button,标签现在看起来像这样:

在此输入图像描述

但我想+现在添加一个黑色圆圈的位置.我不知道如何,我尝试绘制Paint最后一个标签的事件,如下所示:

var p = tabs.TabPages[tabs.TabCount - 1];
p.Paint += new PaintEventHandler(tab_OnDrawPage);

private void tab_OnDrawPage(object sender, PaintEventArgs e)
{
    // e.ClipRectangle.
    e.Graphics.DrawString("+", 
                          new Font("verdana", 
                                   10, 
                                   FontStyle.Bold), 
                          Brushes.Black, 
                          e.ClipRectangle.X + 10, 
                          e.ClipRectangle.Y + 10);
}
Run Code Online (Sandbox Code Playgroud)

但它并没有显示任何吸引力.我想这与我传递给他们的位置有关DrawString(),但我不知道要使用的正确位置.我使用+10将它从最后一个标签中拉出来.如何解决?我自己没有做任何自定义绘图,我正在学习它.

.net c# tabcontrol custom-controls winforms

11
推荐指数
1
解决办法
7639
查看次数

TabPages从右到左TabControl的关闭按钮c#

我想关闭按钮添加到TabPagesTabControl.我尝试这个代码,它适用于从左到右TabControl:

private Point _imageLocation = new Point(13, 5);
private Point _imgHitArea = new Point(13, 2);

this.tabControl2.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;

tabControl2.DrawItem += TabControl2_DrawItem;

private void TabControl2_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
    try
    {
        Image img = new Bitmap(GestionP.Properties.Resources.Close);
        Rectangle r = e.Bounds;
        r = this.tabControl2.GetTabRect(e.Index);
        r.Offset(2, 2);
        Brush TitleBrush = new SolidBrush(Color.Black);
        Font f = this.Font;
        string title = this.tabControl2.TabPages[e.Index].Text;
        e.Graphics.DrawString(title, f, TitleBrush, new PointF(r.X, r.Y));

        if (tabControl2.SelectedIndex >= 1)
        {
            e.Graphics.DrawImage(img, new Point(r.X + (this.tabControl2.GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y)); …
Run Code Online (Sandbox Code Playgroud)

c# tabcontrol tabpage winforms right-to-left

8
推荐指数
1
解决办法
3324
查看次数

在C#Windows窗体的tabpage选项卡标题中添加关闭按钮

我试图在tabcontrol的tabpage面板上添加关闭按钮或'X',我已经通过阅读此stackoverflow问题成功完成了此操作.

问题是标签页标题和X标志合并在一起.我发现tabpage title面板没有根据标题文本调整大小.

这是代码:

//This code will render a "x" mark at the end of the Tab caption. 
e.Graphics.DrawString("X", e.Font, Brushes.Black, e.Bounds.Right + 15, e.Bounds.Top + 4);
e.Graphics.DrawString(this.tabControl1.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left+5, e.Bounds.Top + 4);

e.DrawFocusRectangle();
Run Code Online (Sandbox Code Playgroud)

结果是在这里我改变了e.bounds.right价值,但它仍然没有用.

c# tabpage winforms

3
推荐指数
2
解决办法
1万
查看次数

在按钮上打开标签页单击Winform C#

我有几个标签页集合.默认情况下,当用户打开应用程序时,第一个标签页是开始标签页,然后用户将关闭标签页.现在我想创建一种情况,当用户转到菜单条时,单击"标签页1按钮",然后"标签页1"将出现在标签控件中.任何专业知识都可以帮助我...

c# tabcontrol winforms

2
推荐指数
1
解决办法
2万
查看次数