Click here to Skip to main content
15,301,624 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a Control which inherits Menu strip. I do not need the controls like ComboBox, TextBox Menu Item, I actually need ToolStripRadioButton, ToolStripButton and ToolStripLabel controls. How do I Change the available controls to my required controls.
Can any body suggest any thing.

What I have tried:

I nave created a Class which inherits Menu strip.

Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", GetType(IDesigner))> _
Partial Class MPanel
    Inherits System.Windows.Forms.MenuStrip
    Implements IContainerControl

Dim MItem As New NRadioButton.TSRadio

    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    <Editor("System.ComponentModel.Design.CollectionEditor, Systen.Design", GetType(System.Drawing.Design.UITypeEditor))> _
    <Browsable(True)> _
    Public Property MenuItems() As ToolStripItemCollection                           'ToolStripItemCollection
        Get
            'Return mnuMain.Items
            Return Me.Items
        End Get
        Set(ByVal value As ToolStripItemCollection)
            'mnuMain.Items.Clear()
            Me.Items.Clear()

            'For Each elem In value
            'Me.Items.Add(CType(elem, ToolStripItem))
            Me.Items.Add(CType(MItem, ToolStripItem))
            'Next
        End Set
    End Property
Posted
Updated 13-Mar-21 10:25am
Comments
Gerry Schmitz 30-Dec-20 16:06pm
   
Create your own menu; don't inherit.

1 solution

you cannot use properties to change single values of it. properties can only be used to replace its content entirely.

this works:

MyProperty = new Thing()

this wont work
MyProperty.Thingus = Something
   
Comments
Richard Deeming 15-Mar-21 9:36am
   
Wrong. If the property returns an instance of any non-immutable reference type, or returns a value type by reference, you can change the properties of that instance directly.
public class Foo
{
    public int Bar { get; set; }
}

public class Baz
{
    public Foo Foo { get; } = new Foo();
}

Baz baz = new Baz();
baz.Foo.Bar = 42; // <-- Works fine in C#, and in VB.NET

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900