0

I have an template Windows Form and an child Form which Inherits the template.

But I cannot make any Changes in the Designer of the child.

I am using Visual Studio 2015 Community Edition

Template

.vb

Public Class Form1

    Private isMouseDown As Boolean = False
    Private mouseOffset As Point

    ' Left mouse button pressed
    Private Sub Move_MouseDown(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel2.MouseDown, PictureBox2.MouseDown, PictureBox1.MouseDown
        If e.Button = MouseButtons.Left Then
            ' Get the new position
            Dim mouseRelative As Point = Me.PointToClient(Cursor.Position)
            mouseOffset = New Point(-mouseRelative.X, -mouseRelative.Y)
            ' Set that left button is pressed
            isMouseDown = True
        End If
    End Sub

    ' MouseMove used to check if mouse cursor is moving
    Private Sub Move_MouseMove(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel2.MouseMove, PictureBox2.MouseMove, PictureBox1.MouseMove
        If isMouseDown Then
            Dim mousePos As Point = Control.MousePosition
            ' Get the new form position
            mousePos.Offset(mouseOffset.X, mouseOffset.Y)
            Me.Location = mousePos
        End If
    End Sub

    ' Left mouse button released, form should stop moving
    Private Sub Move_MouseUp(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel2.MouseUp, PictureBox2.MouseUp, PictureBox1.MouseUp
        If e.Button = MouseButtons.Left Then
            isMouseDown = False
        End If
    End Sub


End Class

.Designer.vb

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

    'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
    <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

    'Wird vom Windows Form-Designer benötigt.
    Private components As System.ComponentModel.IContainer

    'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
    'Das Bearbeiten ist mit dem Windows Form-Designer möglich.  
    'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
    <System.Diagnostics.DebuggerStepThrough()>
    Private Sub InitializeComponent()
        Dim Panel1 As System.Windows.Forms.Panel
        Dim TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel
        Me.Panel2 = New System.Windows.Forms.Panel()
        Me.Panel3 = New System.Windows.Forms.Panel()
        Me.TableLayoutPanel2 = New System.Windows.Forms.TableLayoutPanel()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox()
        Me.PictureBox2 = New System.Windows.Forms.PictureBox()
        Panel1 = New System.Windows.Forms.Panel()
        TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
        Me.TableLayoutPanel2.SuspendLayout()
        TableLayoutPanel1.SuspendLayout()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox2, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Panel2
        '
        Me.Panel2.BackColor = System.Drawing.Color.FromArgb(CType(CType(55, Byte), Integer), CType(CType(129, Byte), Integer), CType(CType(175, Byte), Integer))
        Me.Panel2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.Panel2.Location = New System.Drawing.Point(0, 343)
        Me.Panel2.Margin = New System.Windows.Forms.Padding(0)
        Me.Panel2.Name = "Panel2"
        Me.Panel2.Size = New System.Drawing.Size(534, 19)
        Me.Panel2.TabIndex = 1
        '
        'Panel3
        '
        Me.Panel3.BackColor = System.Drawing.Color.FromArgb(CType(CType(193, Byte), Integer), CType(CType(193, Byte), Integer), CType(CType(193, Byte), Integer))
        Me.Panel3.Dock = System.Windows.Forms.DockStyle.Fill
        Me.Panel3.Location = New System.Drawing.Point(0, 329)
        Me.Panel3.Margin = New System.Windows.Forms.Padding(0)
        Me.Panel3.Name = "Panel3"
        Me.Panel3.Size = New System.Drawing.Size(534, 14)
        Me.Panel3.TabIndex = 2
        '
        'TableLayoutPanel2
        '
        Me.TableLayoutPanel2.BackColor = System.Drawing.Color.FromArgb(CType(CType(55, Byte), Integer), CType(CType(129, Byte), Integer), CType(CType(175, Byte), Integer))
        Me.TableLayoutPanel2.ColumnCount = 2
        Me.TableLayoutPanel2.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel2.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel2.Controls.Add(Me.PictureBox1, 0, 0)
        Me.TableLayoutPanel2.Controls.Add(Me.PictureBox2, 1, 0)
        Me.TableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.TableLayoutPanel2.Location = New System.Drawing.Point(0, 0)
        Me.TableLayoutPanel2.Margin = New System.Windows.Forms.Padding(0)
        Me.TableLayoutPanel2.Name = "TableLayoutPanel2"
        Me.TableLayoutPanel2.RowCount = 1
        Me.TableLayoutPanel2.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel2.Size = New System.Drawing.Size(534, 63)
        Me.TableLayoutPanel2.TabIndex = 4
        '
        'Panel1
        '
        Panel1.Dock = System.Windows.Forms.DockStyle.Fill
        Panel1.Location = New System.Drawing.Point(0, 63)
        Panel1.Margin = New System.Windows.Forms.Padding(0)
        Panel1.Name = "Panel1"
        Panel1.Size = New System.Drawing.Size(534, 266)
        Panel1.TabIndex = 5
        '
        'TableLayoutPanel1
        '
        TableLayoutPanel1.ColumnCount = 1
        TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100.0!))
        TableLayoutPanel1.Controls.Add(Panel1, 0, 1)
        TableLayoutPanel1.Controls.Add(Me.Panel2, 0, 3)
        TableLayoutPanel1.Controls.Add(Me.Panel3, 0, 2)
        TableLayoutPanel1.Controls.Add(Me.TableLayoutPanel2, 0, 0)
        TableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        TableLayoutPanel1.Location = New System.Drawing.Point(0, 0)
        TableLayoutPanel1.Name = "TableLayoutPanel1"
        TableLayoutPanel1.RowCount = 4
        TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 17.5!))
        TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 73.5!))
        TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 4.0!))
        TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 5.0!))
        TableLayoutPanel1.Size = New System.Drawing.Size(534, 362)
        TableLayoutPanel1.TabIndex = 0
        '
        'PictureBox1
        '
        Me.PictureBox1.Anchor = System.Windows.Forms.AnchorStyles.Left
        Me.PictureBox1.Image = Global.WindowsApplication2.My.Resources.Resources.Logo
        Me.PictureBox1.Location = New System.Drawing.Point(3, 3)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(261, 57)
        Me.PictureBox1.TabIndex = 0
        Me.PictureBox1.TabStop = False
        '
        'PictureBox2
        '
        Me.PictureBox2.Anchor = System.Windows.Forms.AnchorStyles.Right
        Me.PictureBox2.Image = Global.WindowsApplication2.My.Resources.Resources.Image
        Me.PictureBox2.Location = New System.Drawing.Point(355, 6)
        Me.PictureBox2.Name = "PictureBox2"
        Me.PictureBox2.Size = New System.Drawing.Size(176, 50)
        Me.PictureBox2.TabIndex = 1
        Me.PictureBox2.TabStop = False
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.BackColor = System.Drawing.SystemColors.ControlLightLight
        Me.ClientSize = New System.Drawing.Size(534, 362)
        Me.Controls.Add(TableLayoutPanel1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.TableLayoutPanel2.ResumeLayout(False)
        TableLayoutPanel1.ResumeLayout(False)
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox2, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents Panel2 As Panel
    Friend WithEvents Panel3 As Panel
    Friend WithEvents TableLayoutPanel2 As TableLayoutPanel
    Friend WithEvents PictureBox1 As PictureBox
    Friend WithEvents PictureBox2 As PictureBox
End Class

Child

.vb

Public Class Form2
    Inherits WindowsApplication2.Form1


End Class

.Designer.vb

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form2
    Inherits WindowsApplication2.Form1

    'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Wird vom Windows Form-Designer benötigt.
    Private components As System.ComponentModel.IContainer

    'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
    'Das Bearbeiten ist mit dem Windows Form-Designer möglich.  
    'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'Form2
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.ClientSize = New System.Drawing.Size(534, 362)
        Me.Name = "Form2"
        Me.ResumeLayout(False)

    End Sub

End Class
Error404
  • 719
  • 9
  • 30
  • 1
    You are not supposed to edit `.designer` files anyway. What are you trying to do? – GSerg Jul 26 '16 at 15:36
  • 1
    The `TableLayoutPanel` control does not support visual inheritance in the Windows Forms Designer. A `TableLayoutPanel` control in a derived class appears as "locked" at design time. For more information read: [Best Practices for the TableLayoutPanel Control](https://msdn.microsoft.com/en-us/library/ms171689(v=vs.110).aspx) – Reza Aghaei Jul 26 '16 at 15:54
  • 1
    You also have asked the question for C# [here](http://stackoverflow.com/questions/38585648/make-changes-in-inherited-child-windows-form-visual-studio-c). Is there anything unclear about the comments? – Reza Aghaei Jul 26 '16 at 15:56
  • @RezaAghaei It is working in C# but not in Visual Basic – Error404 Jul 26 '16 at 19:06
  • @GSerg I neab the visual designer not the .designer file – Error404 Jul 26 '16 at 19:06
  • @RezaAghaei I just want to change the content of panel1 which worked in C# – Error404 Jul 26 '16 at 19:11
  • Here is the answer for `Panel`: By default, the Windows Forms Designer assigns the private (Friend in Visual Basic) modifier to container controls like `Panel`. If your base `UserControl` or `Form` has a container control, it will not accept new children in inherited controls and forms. The solution is to change the modifier of the base container control to protected or public. For more information read [How to: Use the Modifiers and GenerateMember Properties](https://msdn.microsoft.com/en-us/library/ms233630(v=vs.110).aspx) – Reza Aghaei Jul 26 '16 at 19:45
  • @RezaAghaei thats what i did but it is still not working – Error404 Jul 26 '16 at 22:01
  • @Error404 Which part of comments is not clear. You can't do it! Take a look at this line of code `TableLayoutPanel1.Controls.Add(Panel1, 0, 1)`. You added `Panel1` to `TableLayoutPanel1`. So since the designer of `TableLayoutPanel` doesn't support visual inheritance, it will be shown in 'locked' state and you can not add any control to in in child form, regardless of any modifier you set for `TableLayoutPanel1` or `Panel1`. – Reza Aghaei Jul 27 '16 at 10:10
  • @RezaAghaei But it was working with C# – Error404 Jul 27 '16 at 10:56

1 Answers1

0

Solved:

For Visual Inheritance to work following Changes has to be done: ("Path" refers to the "Controls Tree Path")

All Controls in the Path have to have the Generate Member-Property disabled, except the last one for which it has to be enabled.

All Controls in the Path have to have the Modify-Property set to Protected, Protected Friend or Public.


Now the last Member of the Path is editable in Child Windows Forms.

Error404
  • 719
  • 9
  • 30