2013-09-05 1 views
-4

에 C#을 구성 요소로 변환는 .NET

Custom Tab Control

내가 오류가 SuspendLayout을 말하고와 문제에 봉착하는 FlatTabControl.FlatTabControl의 구성원이 아닌, 심지어 ControlsFlatTabControl의 구성원이 아닙니다.

누구든지 문제를 해결하는 방법을 알고 계십니까?

다음은 VB.Net 코드로 변환 한 C# 코드입니다. 여전히 작동하지 않습니다.

건배.

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"); 
    } 
} 
} 
+0

이 아마도 당신이 VB.Net으로 C#을 변환 의미 ... 닷넷 C#을 것 같다니까? 그렇다면 VB 코드도 함께 입력하십시오. – UIlrvnd

+1

새 C# -project를 만들고이 컨트롤을 그 안에 넣는 것이 어떨까요? 그런 다음 VB-Solution에서 ControlDll을 참조하고 컨트롤을 사용할 수 있어야합니다. – Tomtom

+0

어디에서 FlatTabControl을 가져 왔습니까? 제 3 자 컨트롤이기 때문에 아마도 해당 컨트롤에 대한 코드가 들어있는 어셈블리/DLL에 대한 참조를 추가하는 것을 잊었을 것입니다. – BrutalDev

답변

0

UPDATE : 추가 실제 시험 프로젝트는 내가 아래를 참조하고 있음을했다 : 첫째 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