Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

UserControl With a Constructor Via IDE

0 views
Skip to first unread message

eBob.com

unread,
Nov 21, 2009, 11:15:43 PM11/21/09
to
I've done usercontrols with constructors and usercontrols using the IDE.
But I guess I've never used the IDE to do a usercontrol with a constructor.

When I'm working in usercontrol.vb, under (Declarations) I can click on New
(although it's greyed out) and I'm taken to a New Sub but in
usercontrol.Designer.vb. I'm under the distinct impression that I really
shouldn't mess with xxxxxxxx.Designer.vb. So, question 1, how do I do a
constructor for a usercontrol using the IDE? Is it OK to modify the New sub
in usercontrol.Designer.vb? Can I add parameters? I'm pretty sure I can
get away with both but is that the right thing to do?

Also, while researching this problem I noticed that the existing New sub
does not do a MyBase.New. I thought that any class that Inherts a class
must issue MyBase.New. Question 2, how does the IDE's New Sub for a
usercontrol get away without doing that?

Can anyone help me with these questions?

Thanks, Bob


Cor Ligthert[MVP]

unread,
Nov 22, 2009, 2:45:43 AM11/22/09
to
Hi Bob,

What do you call the "the IDE". The IDE is the complete complex of tools you
get in Visual Studio to integrate everything you do to develop in one
environment.

I assume you are not creating programs with notepad?

Cor

"eBob.com" <eBob...@totallybogus.com> wrote in message
news:OE4lspya...@TK2MSFTNGP04.phx.gbl...

Family Tree Mike

unread,
Nov 22, 2009, 7:41:45 AM11/22/09
to

Bob,

Normally, to do this I do these steps:

1. right click the project, and select "Add", then "User Control".
2. right click "UserControl1.vb" and select "View Code".
3. Go to "Declarations dropdown". I see four items: New and Finalize
(enabled), Dispose and InitializeComponent (disabled). Select New.

Now the empty user control code shows:
Public Class UserControl1

Public Sub New()

' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

End Sub
End Class

New does appear disabled if I go to the InitializeComponent call, which
is in the designer.vb. If I select "New" in the designer.vb _without_
any constructor created, it does add it to the designer.vb file.

As you say, it is probably best not to add the constructor to the
designer file, but it is not prohibited.

I hope this helps.

--
Mike

eBob.com

unread,
Nov 22, 2009, 3:58:11 PM11/22/09
to
Hi Cor,

By "IDE" I meant that part of Visual Studio which allows me to graphically
design a form/control via drag/drop and code. I never use Notepad to create
a program, but sometimes if I have a really simple usercontrol I just add a
class to the end of Form1.vb.

Bob

"Cor Ligthert[MVP]" <Notmyfi...@planet.nl> wrote in message
news:ubFhPf0a...@TK2MSFTNGP06.phx.gbl...

eBob.com

unread,
Nov 22, 2009, 4:09:31 PM11/22/09
to
Thank you Mike. I just did a little test. If I create a constructor when I
create the usercontrol then my experience is as you describe. In my case I
had already created and used the usercontrol without a constructor - i.e.
without a constructor which I had touched. And I think that accounts for
why it ended up in the xxxxxx.Designer.vb file.

This morning I found the courage to modify the constructor in the
xxxxxx.Designer.vb file and that seems to work just fine. I think in the
future I will try to remember to touch the constructor in the initial design
work.

Thanks, Bob


"Family Tree Mike" <FamilyT...@ThisOldHouse.com> wrote in message
news:epINlE3a...@TK2MSFTNGP05.phx.gbl...

Sergey Poberezovskiy

unread,
Nov 23, 2009, 12:20:02 AM11/23/09
to
Bob,

I would suggest manually cut the IDE created constructor from the .Designer
file and paste it into the code behind - this way you will have the
custom/IDE code separation.

"eBob.com" wrote:

> .
>

0 new messages