Community discussion forum

windows form inherit problem with vb.net vs 2008

  • 3 months ago

    Hi

    In vs 2008 with vb.net I am trying to inherit a form to another form.

    Partial Public Class Form1

    End Class

    Partial Public Class Form2

    Inherits Form1

    End Class

     But it gives following error:

    Error 4 Base class 'Form1' specified for class 'Form2' cannot be different from the base class 'System.Windows.Forms.Form' of one of its other partial types. C:\Documents and Settings\rozsoy\My Documents\myvs2008_projects\ONSITEV3\winmobile5_6_vb_csharp_SVS_V3_controls_vs2008\winmob5\Form2.vb 2 14 winmob5

     

    Any ideas?

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 3 months ago

    I have not this problem in 2008. Maybe if you paste bigger part of code?

  • 3 months ago

    Hi

    In vs 2005 there is inherited form templete but in my vb 2008 I could not find that templete so I just added windows forms.

    Simple 2 forms one inherits the other whic gives error.

    However if I try same thing with c# it works I mean I dont have same problem. But I have to use vb.net.

    I am working with windows mobile 5 and 6 projects but I tried same thing with windows applications as well.

    You are saying you dont have same problem vith vs 2008. Can you send me an example?

    Thanks

    Reside

  • 3 months ago

    Hi
    I solved that problem if I click show all files on the solution explorer it shows designer.vb file.
    I changed Inherits System.Windows.Forms.Form with Inherits Form1 in Forn2.Designer.vb file.

    The error disappeared but if I open from2 designer it  shows a message :
    visual inheritance is currently disabled because the base class references a device-specific component or contains P/Invoke
    Form1 does not have any thing at the moment.
    How can I that problem. If I put any control on form1 I can not see it on form2. It should happen shuldnt it?
    Thanks
    Reside


    software developer

  • 3 months ago

    Ok. Now I maybe understand. If you inherited form added by Project/Add, this thing could make you problems. If you simply type both classes in some existing module, and "clone" your own InitialiseComponent and Dispose from some designer.vb, and type inheritance in such class, you shouldn't get no problems. Try this:

    Project Add Class;

    Class Select All, Delete;

    Type:
    Class BaseForm
    Inherits Form
    Sub InitializeComponent
    Sub Dispose
    End Class

    Class Form2
    Inherits BaseForm
    End Class

    You must only somehow solve overridabilty of Initialize, if you want to use both new classes as forms, not only Inheritance Bases. Possible maybe if you put Overridable Sub Init to Base, which is then called from Base.InitializeComponent. Which is not more overriden than in BaseForm. Also remember MyBase.New before InitializeComponent in Sub New,

  • 3 months ago

    Thanks for helping me. You are great It is working Smiley Face

    From project I added two classes not windows forms and added as following:

    Public Class BaseForm

    Inherits System.Windows.Forms.Form

    Protected Sub New()

    InitializeComponent()

    End Sub

    Protected Overridable Sub InitializeComponent()

    Me.SuspendLayout()

    '

    'BaseForm

    '

    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit

    Me.ClientSize = New System.Drawing.Size(240, 294)

    Me.Name = "BaseForm"

    Me.ResumeLayout(False)

    End Sub

    Shadows Sub Dispose()

    End Sub

     

    Protected Overridable Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    End Class

     

     

    Public Class InheritedForm

    Inherits BaseForm

    Friend WithEvents Button2 As System.Windows.Forms.Button

    Protected Overrides Sub InitializeComponent()

    Me.Button2 = New System.Windows.Forms.Button

    Me.SuspendLayout()

    MyBase.InitializeComponent()

    '

    'Button2

    '

    Me.Button2.Location = New System.Drawing.Point(83, 148)

    Me.Button2.Name = "Button2"

    Me.Button2.Size = New System.Drawing.Size(72, 20)

    Me.Button2.TabIndex = 3

    Me.Button2.Text = "Button2"

    '

    'InheritedForm

    '

    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit

    Me.ClientSize = New System.Drawing.Size(240, 294)

    Me.Controls.Add(Me.Button2)

    Me.Name = "InheritedForm"

    Me.Controls.SetChildIndex(Me.Button2, 0)

    Me.ResumeLayout(False)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    End Sub

    End Class

  • 3 months ago

    Take some prsonal excercise in inheriting. Thats just fine (and very easy) way to ease many things :) (anyway I didn't suppose that this helps :] so this is surprise :)

Post a reply

Enter your message below

Sign in or Join us (it's free).