-4

I am trying to use the component below in my vb.net program

Custom Tab Control

What I'm having troubles with is errors saying SuspendLayout is not a member of FlatTabControl.FlatTabControl, and even with Controls not being a member of FlatTabControl.

Anyone know how to fix this?

Below is the C# code which I converted to VB.Net code, still can't get it working.

Cheers.

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

namespace TabControlTest
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private FlatTabControl.FlatTabControl tabControl1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Button button3;
    private System.Windows.Forms.ImageList imageList1;
    private System.Windows.Forms.TabPage tabPage1;
    private System.Windows.Forms.TabPage tabPage2;
    private System.Windows.Forms.TabPage tabPage3;
    private System.Windows.Forms.TabPage tabPage4;
    private System.ComponentModel.IContainer components;

    public Form1()
    {
        //
        // Required for Windows Form Designer support
        //
        InitializeComponent();

        //
        // TODO: Add any constructor code after InitializeComponent call
        //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
        if( disposing )
        {
            if (components != null) 
            {
                components.Dispose();
            }
        }
        base.Dispose( disposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
        this.tabControl1 = new FlatTabControl.FlatTabControl();
        this.tabPage1 = new System.Windows.Forms.TabPage();
        this.tabPage2 = new System.Windows.Forms.TabPage();
        this.tabPage3 = new System.Windows.Forms.TabPage();
        this.tabPage4 = new System.Windows.Forms.TabPage();
        this.imageList1 = new System.Windows.Forms.ImageList(this.components);
        this.button2 = new System.Windows.Forms.Button();
        this.button3 = new System.Windows.Forms.Button();
        this.tabControl1.SuspendLayout();
        this.SuspendLayout();
        // 
        // tabControl1
        // 
        this.tabControl1.Controls.Add(this.tabPage1);
        this.tabControl1.Controls.Add(this.tabPage2);
        this.tabControl1.Controls.Add(this.tabPage3);
        this.tabControl1.Controls.Add(this.tabPage4);
        this.tabControl1.ImageList = this.imageList1;
        this.tabControl1.Location = new System.Drawing.Point(8, 16);
        this.tabControl1.myBackColor = System.Drawing.SystemColors.Control;
        this.tabControl1.Name = "tabControl1";
        this.tabControl1.SelectedIndex = 2;
        this.tabControl1.Size = new System.Drawing.Size(328, 240);
        this.tabControl1.TabIndex = 0;
        // 
        // tabPage1
        // 
        this.tabPage1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(224)))), ((int)(((byte)(192)))));
        this.tabPage1.ImageIndex = 0;
        this.tabPage1.Location = new System.Drawing.Point(4, 25);
        this.tabPage1.Name = "tabPage1";
        this.tabPage1.Size = new System.Drawing.Size(320, 211);
        this.tabPage1.TabIndex = 1;
        this.tabPage1.Text = "tabPage1";
        // 
        // tabPage2
        // 
        this.tabPage2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
        this.tabPage2.ImageIndex = 1;
        this.tabPage2.Location = new System.Drawing.Point(4, 25);
        this.tabPage2.Name = "tabPage2";
        this.tabPage2.Size = new System.Drawing.Size(192, 71);
        this.tabPage2.TabIndex = 0;
        this.tabPage2.Text = "tabPage2";
        // 
        // tabPage3
        // 
        this.tabPage3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
        this.tabPage3.ImageIndex = 2;
        this.tabPage3.Location = new System.Drawing.Point(4, 25);
        this.tabPage3.Name = "tabPage3";
        this.tabPage3.Size = new System.Drawing.Size(192, 71);
        this.tabPage3.TabIndex = 2;
        this.tabPage3.Text = "tabPage3";
        // 
        // tabPage4
        // 
        this.tabPage4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
        this.tabPage4.ImageIndex = 0;
        this.tabPage4.Location = new System.Drawing.Point(4, 25);
        this.tabPage4.Name = "tabPage4";
        this.tabPage4.Size = new System.Drawing.Size(192, 71);
        this.tabPage4.TabIndex = 3;
        this.tabPage4.Text = "tabPage4";
        // 
        // imageList1
        // 
        this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
        this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
        this.imageList1.Images.SetKeyName(0, "");
        this.imageList1.Images.SetKeyName(1, "");
        this.imageList1.Images.SetKeyName(2, "");
        // 
        // button2
        // 
        this.button2.Location = new System.Drawing.Point(352, 160);
        this.button2.Name = "button2";
        this.button2.Size = new System.Drawing.Size(75, 23);
        this.button2.TabIndex = 2;
        this.button2.Text = "Add";
        this.button2.Click += new System.EventHandler(this.button2_Click);
        // 
        // button3
        // 
        this.button3.Location = new System.Drawing.Point(352, 208);
        this.button3.Name = "button3";
        this.button3.Size = new System.Drawing.Size(75, 23);
        this.button3.TabIndex = 3;
        this.button3.Text = "Remove";
        this.button3.Click += new System.EventHandler(this.button3_Click);
        // 
        // Form1
        // 
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.BackColor = System.Drawing.SystemColors.Control;
        this.ClientSize = new System.Drawing.Size(448, 269);
        this.Controls.Add(this.button3);
        this.Controls.Add(this.button2);
        this.Controls.Add(this.tabControl1);
        this.Name = "Form1";
        this.Text = "FlatTabControl test";
        this.Load += new System.EventHandler(this.Form1_Load);
        this.tabControl1.ResumeLayout(false);
        this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
        Application.Run(new Form1());
    }

    private void Form1_Load(object sender, System.EventArgs e)
    {

    }

    private static int nt = 0;

    private void button2_Click(object sender, System.EventArgs e)
    {
        TabPage tabPage = new System.Windows.Forms.TabPage("newTab");

        switch (nt)
        {
            case 0:
            {
                tabPage.BackColor = Color.LightCoral;
                tabPage.ImageIndex = 0;
                nt = 1;
            }
            break;

            case 1:
            {
                tabPage.BackColor = Color.LightGoldenrodYellow;
                tabPage.ImageIndex = 1;
                nt = 2;
            }
            break;

            case 2:
            {
                tabPage.BackColor = Color.LightSeaGreen;
                tabPage.ImageIndex = 2;
                nt = 0;
            }
            break;
        }

        tabControl1.TabPages.Add(tabPage);
    }

    private void button3_Click(object sender, System.EventArgs e)
    {
        tabControl1.TabPages.RemoveAt(tabControl1.SelectedIndex);
    }

    private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
        MessageBox.Show("1");
    }
}
}
4

1 回答 1

0

更新:添加了我在下面提到的实际测试项目:http ://www.brutaldev.com/file.axd?file=FlatTabExample-18627930.zip

首先,您需要从这里下载 FlatTabControl.dll 文件:http: //www.codeproject.com/KB/tabs/FlatTabControl/FlatTabControl_demo.zip

在 Visual Studio 中创建一个新的 Windows Forms VB.NET 项目,添加对 FlatTabControl.dll 的引用(右键单击 -> 添加引用)。您还可以将程序集拖放到工具箱中,以便您可以轻松地将其添加到表单中,这也将在您将其拖放到表单时立即创建参考。

我将您的 C# 代码转换为 VB.NET,它应该看起来像这样。

Form1.Designer.vb - 你应该让它由 Visual Studio 生成,但为了完整起见,我将它包括在这里。

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
    Me.tabControl1 = New FlatTabControl.FlatTabControl()
    Me.TabPage1 = New System.Windows.Forms.TabPage()
    Me.TabPage2 = New System.Windows.Forms.TabPage()
    Me.Button1 = New System.Windows.Forms.Button()
    Me.Button2 = New System.Windows.Forms.Button()
    Me.tabControl1.SuspendLayout()
    Me.SuspendLayout()
    '
    'tabControl1
    '
    Me.tabControl1.Controls.Add(Me.TabPage1)
    Me.tabControl1.Controls.Add(Me.TabPage2)
    Me.tabControl1.Location = New System.Drawing.Point(13, 13)
    Me.tabControl1.Name = "tabControl1"
    Me.tabControl1.SelectedIndex = 0
    Me.tabControl1.Size = New System.Drawing.Size(265, 202)
    Me.tabControl1.TabIndex = 0
    '
    'TabPage1
    '
    Me.TabPage1.Location = New System.Drawing.Point(4, 25)
    Me.TabPage1.Name = "TabPage1"
    Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)
    Me.TabPage1.Size = New System.Drawing.Size(257, 173)
    Me.TabPage1.TabIndex = 0
    Me.TabPage1.Text = "TabPage1"
    Me.TabPage1.UseVisualStyleBackColor = True
    '
    'TabPage2
    '
    Me.TabPage2.Location = New System.Drawing.Point(4, 25)
    Me.TabPage2.Name = "TabPage2"
    Me.TabPage2.Padding = New System.Windows.Forms.Padding(3)
    Me.TabPage2.Size = New System.Drawing.Size(192, 71)
    Me.TabPage2.TabIndex = 1
    Me.TabPage2.Text = "TabPage2"
    Me.TabPage2.UseVisualStyleBackColor = True
    '
    'Button1
    '
    Me.Button1.Location = New System.Drawing.Point(17, 222)
    Me.Button1.Name = "Button1"
    Me.Button1.Size = New System.Drawing.Size(75, 23)
    Me.Button1.TabIndex = 1
    Me.Button1.Text = "Button1"
    Me.Button1.UseVisualStyleBackColor = True
    '
    'Button2
    '
    Me.Button2.Location = New System.Drawing.Point(99, 222)
    Me.Button2.Name = "Button2"
    Me.Button2.Size = New System.Drawing.Size(75, 23)
    Me.Button2.TabIndex = 2
    Me.Button2.Text = "Button2"
    Me.Button2.UseVisualStyleBackColor = True
    '
    'Form1
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.ClientSize = New System.Drawing.Size(290, 268)
    Me.Controls.Add(Me.Button2)
    Me.Controls.Add(Me.Button1)
    Me.Controls.Add(Me.tabControl1)
    Me.Name = "Form1"
    Me.Text = "Form1"
    Me.tabControl1.ResumeLayout(False)
    Me.ResumeLayout(False)

  End Sub
  Friend WithEvents tabControl1 As FlatTabControl.FlatTabControl
  Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
  Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
  Friend WithEvents Button1 As System.Windows.Forms.Button
  Friend WithEvents Button2 As System.Windows.Forms.Button

End Class

Form1.vb

Public Class Form1
  Private Shared nt As Integer = 0

  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim tabPage As TabPage = New System.Windows.Forms.TabPage("newTab")

    Select Case nt
      Case 0
        If True Then
          tabPage.BackColor = Color.LightCoral
          tabPage.ImageIndex = 0
          nt = 1
        End If
        Exit Select

      Case 1
        If True Then
          tabPage.BackColor = Color.LightGoldenrodYellow
          tabPage.ImageIndex = 1
          nt = 2
        End If
        Exit Select

      Case 2
        If True Then
          tabPage.BackColor = Color.LightSeaGreen
          tabPage.ImageIndex = 2
          nt = 0
        End If
        Exit Select
    End Select

    tabControl1.TabPages.Add(tabPage)
  End Sub

  Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    tabControl1.TabPages.RemoveAt(tabControl1.SelectedIndex)
  End Sub
End Class
于 2013-09-05T05:08:06.113 回答