Deleting Custom Controls Only To Put Them Back Again.

  • Thread starter Thread starter Wayne
  • Start date Start date
W

Wayne

1. I have created my own class that inherits the textbox (called it
CyanFocusTextBox). I put in some code and some new properties. All
this works. I build the dll that contains this class successfully.

2. I add it to the user controls section of toolbox and it appears.

3. I add the new CyanFocusTextBoxes to the form and it all works.

4. The problem comes when I update the class CyanFocusTextBox in the
dll and rebuild it. These updates are not used by the
CyanFocusTextBoxes that I dropped on the form earlier. I have to
delete those and put them back. Is there anyway around this? It is a
lot of work to delete the controls and put them back.

5. My project and dll are all in the same solution and the build
order is my dll first then my form. I have even tried rebuilding the
whole solution.

Thanks.

Wayne
 
Wayne,

I too have wrestled with the toolbox, and frankly, I
think the design sucks. Perhaps someone will have a
better solution to this problem than I do, but my
conclusion is to avoid using the toolbox unless absolutely
necessary; if a component is unlikly to change, or if it
can't be represented visually by a standard control.

What I would do in the case of your custom textbox is to
add a regular textbox to your form, then edit the sacred
form designer code section of the code by changing the
class that your control instantiates.

Thus:

Friend WithEvents txtMyTextbox As TextBox

Becomes:

Friend WithEvents txtMyTextbox As CyanFocusTextBox

And:

Me.txtMyTextBox = New TextBox

Becomes:

Me.txtMyTextBox = New CyanFocusTextBox

The form designer doesn't seem to mind - at least not for
me so far, and I have implemented this strategy throughout
a large application. While it is a work-around, it beats
playing the toolbox shuffle, or worse yet, going without
a visual design representation of a control.

I suspect Microsoft imagined a highly structured enterprise
development environment. Well, excuse me!

If I have to admit to a more seat-of-the-pants approach to
programming, so be it.

Randy
 
Randy,

Wow, I like your work around and I am not afraid of the sacred form
designer code.

We can't be the only two that have wrestled with this problem. There
has got to be a way to use the latest version of your class without
doing the toolbox shuffle or deleting controls and putting them back
or changing the designer code. Perhaps I am just beating my head
against the proverbial .net wall but I can't believe the game ends
like this.

Wayne
 
Randy,

Got it.

Here is the sequence that I have used.

1. First update your class, make modifications, add functionality ...

2. Build your class (Mine was CyanFocusTextBox). My class is in a
dll.

3. Then go and look at the form that has the controls that are based
upon the rebuilt class (CyanFocusTextBox). Make sure you look at the
form in design mode. There is a delay on my computer when I do this.
It appears to be rewriting the sacred designer form code.

4. Run the program. The updated functionality of your class is
available to all the controls that are based upon your class
(CyanFocusTextBox) on the form.

This means that I do not have to delete the controls that are based
upon CyanFocusTextBox and put them back. I do not have to play the
toolbox shuffle.

It works like I would hope it works.

Wayne

Wayne
 
Back
Top