How can I derive a control to an inherited form in VB.Net? - vb.net

everybody.
I have a VB form (named "MyBaseForm"), with an ImageList control ("MyIcons").
I want to derive MyBaseForm to another form ("MyDerivedForm"), allowing it to use MyIcons ImageList defined into the base class.
Of course what I want to do is to use the images of MyIcons to define MyDerivedForm with Designer and/or into the code.
To do that, i set MyBaseForm.MyIcons.Modifiers property to Protected (I also tried with Public and Protected Friend, with the same results...)
In this way, I expect that if i modify the MyIcons image list from the Designer view of MyBaseForm, I would find the change into MyDerivedForm.
But, if i for example add a new image to MyBaseForm.MyIcons, MyDerivedForm.MyIcons keeps being still unchanged.
It looks like when i create the derived form, VisualStudio just create a copy of the ImageList control. Which is not what i want.
To have MyDerivedForm.MyIcons updated, what I have to do is to manually remove the "MyIcons" section of file MyDerivedForm.Designer.vb, so that, when I re-build, VisualStudio re-generates that section.
Is there a way to have that control REALLY derived, or, alternatively, to force the compiler to re-create MyDerivedForm.Designer.vb at any build (without having to manually manipulate the self-generated code)?
(I am using VB.Net 2005)

Related

VBA Adding a User Defined Control to Userform at Runtime

So I've made the following control in Design Mode then added the control to a new page Custom in my toolbox.
Now, what would I use for the progID parameter in Controls.Add()? How do I look up this value? Controls.Add("Forms.Frame.1") adds a regular frame, not the desired custom control.
As far as I am aware, you do not generate a new progID with a custom control. Per the MSDN documentation for custom/modified controls:
Note: When you drag a control onto the Control Toolbox, you only transfer the advanced property values.
So only the properties are transferred; the actual control is still of the same type/s as the one you created it from. Further, it looks like this progID is "a unique system-wide string that the Windows operating system can use to identify your control's type." So unless you are up to coding your own control, it looks as though you're just passing properties to the custom toolbox controls you create there.
You'll have to just replicate the custom control each time you want to add it. Just create a sub with all the correct properties and call it. Not what you were looking for, but it'll get the job done.

How can I remove all properties of a user control?

I am working on a Visual Basic project and I had to create my own user control. I want to remove-hide ALL default properties of this user control but not by using this <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> way, one by one property. I need something more massive.
I'm afraid what you want to do isn't possible in VB, as it would require to add the attributes dynamically (on all properties) and in VB attributes are static and cannot be added or removed dynamically.
The only way to do what you want to do is to add the attributes one by one property.

VB.NET Exposing child control properties

For a custom control I'm making, the datagridview is pretty much only going to be a customized version of the original. However, so that other controls I have made can interact with it, I have made it inherit my MetroControl class.
Since I cannot add multiple "Inherits", I have placed a DataGridView and docked it inside the control. From here I can then influence and theme it. Most of the properties are handled by my theming (such as the "RowHeadersStyle" etc..
I need to push forward the "Columns" property of the DataGridView so that the user can interact with the same column setup screen that they would as if they were using the normal DataGridView. Is there any way I can simply forward this property (as it would make it much easier for both me and the user)?
Yes, you can add a property on your UserControl that just returns the Columns property on the DataGridView (Assuming that your DataGridView is stored in field named dataGridView):
public DataGridViewColumnCollection Columns {
get { return dataGridView.Columns; }
}
That's it

Replacing several winforms controls with custom controls in VS2010

I have inherited a VB.net project, and I need to give several ListBoxes some custom functionality. So I've created a subclass of System.Windows.Forms.ListBox, and now I'd like to replace several "regular" ListBoxes with my subclass.
I want to be extremely careful not to change any properties that are set in the designer, so I'm hoping to just "drop in" my replacement.
Does the VS2010 winforms designer have a built-in way of simply changing the user control's type, without deleting and re-inserting the control?
You will need to change the type in the Form.designer.vb file. Every control used on the form is declared in there.
In my experience it will be best to use the Visual Studio find and replace tool to replace the ListBox control where you need to in all the .ASPX files as well as the .designer.cs files.
You'll need to add a reference to your control's assembly in the .ASPX files too.

Can I change properties of inherited controls at design time?

I am using visual inheritance and was wondering if there is a way to change the properties of inherited controls at design time, preferably in the form designer. If not, then in the designer code.
I have my control declared as Public in the base class. I can access it in the child form code, but not in the form designer. Is this just not possible?
There are limitations placed within visual studio for visual inheritance. Unfortunately, derived forms\usercontrols cannot modify controls containing collections within the base, namely DataGridViewRows, ToolStrips, ListViewColumns, etc.
Microsoft Bug Report
There are ways around this in certain situations. Create a protected property in the base class that exposes the exact properties of the control you wish to modify (DataGridView.BackgroundColor, or ListView.Columns).
Your base form should be able access this property to change the components needed. I've done this for ListView.Columns, and DataGridView.rows successfully, however ToolStrip.Items would not work.
It seems to work only for certain controls, but not all and I can't understand why. On my base form I have a TabControl that within it is a ComboBox, a ToolStrip, and a DataGridView. All of them are set to Public, but I can only modify the properties of the ComboBox and not the other two controls.
I have no idea why this is.
You need to change your control visibility. Put the control property Modifiers on public and recompile the project and then you can change properties of the inherited control.