使用 WinForms 中的 EasyTabs 使用 Chrome 样式选项卡的应用程序 [英] Application with Chrome-Style Tabs using EasyTabs in WinForms

查看:16
本文介绍了使用 WinForms 中的 EasyTabs 使用 Chrome 样式选项卡的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 WinForms 中的 EasyTabs 创建带有 Chrome 样式选项卡的 C# 应用程序,但收到以下错误代码:

I am trying to create a C# Application with Chrome-Style Tabs using EasyTabs in WinForms, but I am getting the following error code:

设计者必须创建一个类型为EasyTabs.TitleBarTabs"的实例,但不能,因为该类型被声明为抽象类型.

The designer must create an instance of type 'EasyTabs.TitleBarTabs' but it cannot because the type is declared as abstract.

我已经按照下面的 Youtube 教程作为指导.

I have followed the Youtube-tutorial beneath as a guideline.

https://www.youtube.com/watch?v=WVFjegJK8EY

代码:

using System;
using EasyTabs;

namespace WindowsFormsApp1
{
    public partial class AppContainer : TitleBarTabs
    {
        public AppContainer()
        {
            InitializeComponent();

            AeroPeekEnabled = true;
            TabRenderer = new ChromeTabRenderer(this);
        }

        public override TitleBarTab CreateTab()
        {
            return new TitleBarTab(this)
            {
                Content = Form1
                {
                    Text = "New Tab"
                }
            };
        }

        private void AppContainer_Load(object sender, EventArgs e)
        {

        }
    }
}

推荐答案

直接尝试查看AppContainer.cs时出现此错误是正常的.

It is normal to see this error when you try to view AppContainer.cs directly.

设计者必须创建一个类型为EasyTabs.TitleBarTabs"的实例,但不能,因为该类型被声明为抽象类型.不要让这阻止你实现你想要实现的目标.忽略错误,只需右键单击 AppContainer.cs 并选择查看代码

The designer must create an instance of type 'EasyTabs.TitleBarTabs' but it cannot because the type is declared as abstract. Let that not deter you from achieving what you wanted to achieve. Ignore the error and simply right click on AppContainer.cs and select View Code

using EasyTabs;

namespace WindowsFormsApp1
{
    public partial class AppContainer : TitleBarTabs
    {
        public AppTabs()
        {
            InitializeComponent();

            AeroPeekEnabled = true;
            TabRenderer = new ChromeTabRenderer(this);
            Icon = mBible.Properties.Resources.appico;
        }

        public override TitleBarTab CreateTab()
        {
            return new TitleBarTab(this)
            {
                Content = new Form1
                {
                    Text = "New Tab"
                }
            };
        }
    }
}

这应该足以为您生成新标签.

That should be enough to generate new tabs for you.

现在要轻松创建选项卡,假设您有一个表单MainForm",而您要生成的选项卡是Form1",这就是我们要做的

Now to create tabs easily lets assume you have a form 'MainForm' and the tab you want to be generating is 'Form1' here is what we do

using System;
using System.Windows.Forms;
using EasyTabs;

namespace WindowsFormsApp1
{
    public partial class MainForm : Form
    {
        public static AppContainer tabbedApp = new AppContainer();

        public MainForm()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            tabbedApp.Tabs.Add(new TitleBarTab(tabbedApp)
            {
                Content = new Form1
                {
                    Text = "New Tab"
                }
            });
            tabbedApp.SelectedTabIndex = 0;

            TitleBarTabsApplicationContext applicationContext = new TitleBarTabsApplicationContext();
            applicationContext.Start(tabbedApp);

            this.Hide();
        }

    }
}

您可以随时通过在另一个表单上调用此代码轻松地向您的标签添加新标签

You can always add to your tabs a new tab easily by calling this code on another form

    AppContainer.tabbedApp.Tabs.Add(new TitleBarTab(AppContainer.tabbedApp)
    {
         Content = new Form2 { Text = "Another Tab" }
   });
   AppContainer.tabbedApp.SelectedTabIndex = 0;

我希望能帮助到任何在类似问题上寻求帮助的人.

I hope that helps and anyone looking for help on similar issues.

这篇关于使用 WinForms 中的 EasyTabs 使用 Chrome 样式选项卡的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆