2014-04-26 27 views
-1

你好傢伙我試圖繼承tabcontrol時出現以下錯誤:基類'System.Windows.Forms.TabControl'爲類'Form1'指定不能不同於基類'System.Windows .Forms.Form'的其他部分類型之一!錯誤當試圖繼承TabControl

這裏有一個畫面:http://prntscr.com/3dqzd6

什麼我嘗試做一個動畫選項卡控制。我發現了一個代碼,但它只是爲Visual Basic(在C#代碼,我這不過是代碼的VB只) 我的代碼:

Public Class Form1 
Inherits TabControl//Here i got the error 
Dim OldIndex As Integer 

Private _Speed As Integer = 9 
Property Speed As Integer 
    Get 
     Return _Speed 
    End Get 
    Set(ByVal value As Integer) 
     If value > 20 Or value < -20 Then 
      MsgBox("Speed needs to be in between -20 and 20.") 
     Else 
      _Speed = value 
     End If 
    End Set 
End Property 

Sub New() 
    SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw, True) 
End Sub 

Sub DoAnimationScrollLeft(ByVal Control1 As Control, ByVal Control2 As Control) 
    Dim G As Graphics = Control1.CreateGraphics() 
    Dim P1 As New Bitmap(Control1.Width, Control1.Height) 
    Dim P2 As New Bitmap(Control2.Width, Control2.Height) 
    Control1.DrawToBitmap(P1, New Rectangle(0, 0, Control1.Width, Control1.Height)) 
    Control2.DrawToBitmap(P2, New Rectangle(0, 0, Control2.Width, Control2.Height)) 

    For Each c As Control In Control1.Controls 
     c.Hide() 
    Next 

    Dim Slide As Integer = Control1.Width - (Control1.Width Mod _Speed) 

    Dim a As Integer 
    For a = 0 To Slide Step _Speed 
     G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height)) 
     G.DrawImage(P2, New Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height)) 
    Next 
    a = Control1.Width 
    G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height)) 
    G.DrawImage(P2, New Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height)) 

    SelectedTab = Control2 

    For Each c As Control In Control2.Controls 
     c.Show() 
    Next 

    For Each c As Control In Control1.Controls 
     c.Show() 
    Next 
End Sub 

Protected Overrides Sub OnSelecting(ByVal e As System.Windows.Forms.TabControlCancelEventArgs) 
    If OldIndex < e.TabPageIndex Then 
     DoAnimationScrollRight(TabPages(OldIndex), TabPages(e.TabPageIndex)) 
    Else 
     DoAnimationScrollLeft(TabPages(OldIndex), TabPages(e.TabPageIndex)) 
    End If 
End Sub 

Protected Overrides Sub OnDeselecting(ByVal e As System.Windows.Forms.TabControlCancelEventArgs) 
    OldIndex = e.TabPageIndex 
End Sub 

Sub DoAnimationScrollRight(ByVal Control1 As Control, ByVal Control2 As Control) 
    Dim G As Graphics = Control1.CreateGraphics() 
    Dim P1 As New Bitmap(Control1.Width, Control1.Height) 
    Dim P2 As New Bitmap(Control2.Width, Control2.Height) 
    Control1.DrawToBitmap(P1, New Rectangle(0, 0, Control1.Width, Control1.Height)) 
    Control2.DrawToBitmap(P2, New Rectangle(0, 0, Control2.Width, Control2.Height)) 

    For Each c As Control In Control1.Controls 
     c.Hide() 
    Next 

    Dim Slide As Integer = Control1.Width - (Control1.Width Mod _Speed) 

    Dim a As Integer 
    For a = 0 To -Slide Step -_Speed 
     G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height)) 
     G.DrawImage(P2, New Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height)) 
    Next 
    a = Control1.Width 
    G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height)) 
    G.DrawImage(P2, New Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height)) 

    SelectedTab = Control2 

    For Each c As Control In Control2.Controls 
     c.Show() 
    Next 

    For Each c As Control In Control1.Controls 
     c.Show() 
    Next 
End Sub 

請幫幫我!

-Christos

+1

你必須有一個表格名爲Form1。更改此類的名稱。 – OneFineDay

+0

你的意思是?你能舉個例子嗎? – Christos92

+0

像「Form1」這樣的名稱是有原因自動生成的。它應該幫助你避免麻煩。沒有工作,很難猜測你的大腦如此糟糕。當然,這不是因爲你曾經拿起過關於Winforms或Visual Studio的書。您必須按控制器上的B按鈕才能進行跳轉,請使用Project +添加新項目+類。 –

回答

0

當你創建一個表單設計器,使一個名叫Form1它有一個Partial Class同名 - 這是生成的代碼維持,而不應被你感動。這Form1System.Windows.Forms.Form繼承,因此不能從TabControl繼承。如果您只是簡單地更改上面的課程名稱,那麼該課程將會是Sub-Classed版本的,那麼一切都會很順利。

Public Class Form1 
... 
End Class 

Partial Class Form1 
'same class as above just allowed to be seperate 
'they share the internal code 
End Class 

您的代碼應該這樣開始:

Public Class myTabControl : Inherits TabControl 
'continue with sub classing 
+0

謝謝它的作品:) THANSK ALOT – Christos92