Replacing several winforms controls with custom controls in VS2010 - vb.net

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.

Related

How to add hidden controls to a form (not programmatically)?

I used a custom "skin" or w/e you may call it for uniquely designed forms in Visual Studio, to be accurate for VB.NET.
I decided to remove the custom form and the problem is that all controls are now hidden, but they still exist within the project.
Is there any way to make them visible in designer again, so I can add them to my new form.
Check to Location of the missing controls , maybe it's outside bounds.

Display controls in Designer VB.Net 2013

I have a set of controls which are added dynamically to a panel. The number of controls depends on which tab a user selects from TabPage control, which is embedded in a form.
At the moment, the controls don't appear in Designer, but appear during execution.
I managed to display controls for other forms which are not dynamic by moving the non-design code to the vb file, but how can I display the other ones?
The only answer that I know of is to add your code in the .Designer.vb file of the Form.
BUT! I strongly advise you to avoid that if you are not sure how it works! Custom code in the .Designer. files can break your form design and project with possible random crashes.
Also, your code can be changed and removed by the Visual Studio designer:
Custom code in designer.vb file goes away when making edits in design mode
Instead, you can make the panels into custom user controls and add those to the tabs.

How can I derive a control to an inherited form in 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)

Referencing user controls that are contained within the same VB.NET project

I do apologize if this post is a duplicate, but I haven't found anything similar when I searched.
I'm fairly new to VB.NET and I'm currently playing around with user controls, figuring out good programming practices. As far as I understand, to create and use a UserControl, I need to create a project with the UserControl in it, then build the project and use that DLL (add it to Toolbox or otherwise).
My question is this: Is there a way a have a project (a Form with a bunch of things on it) that contains a UserControl written in a *.vb file inside that same Project? If you do that, the DLL (in my case) never gets produced, possibly because the UserControl is never used and building it is simply omitted. Is it perhaps a bad practice to do that altogether? It simply makes sense to me to keep a UserControl as a part of the Project that uniquely uses it. Is there a reason not to do that?
Thanks in advance! = )
SOLUTION:
Visual Studio does not automatically include your own controls to the toolbox by default! In order to change that, go to Tools>Options>Windows Form Designer>General and set AutoToolboxPopulate to True. When you build your project next time, your new Control will appear in your Toolbox.
It's a perfectly valid design decision to include a UserControl in a WinForm or WPF project that uses it. If you do this then VS will not create a DLL for the UserControl; instead the UserControl will be built into the assembly your project is producing.
If you did want to reuse a UserControl in multiple projects then you would want to create separate project that generates a DLL that can be reused.

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.