Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

Usercontrols. Are they worth the effort?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Josh Newman - 17 Dec 2004 09:57 GMT
I have a form that is approximatly 5000 lines of code. I estimate that about
70% of this is designer generated code for my controls on the form.

Would it be worth it to group some of the controls on the form into user
controls to reduce the size of the form?

What else can/should be done to keep the size of forms reasonable?

I have heard that user contorls cause all kind of weird behaviour in the
IDE?
John Saunders - 17 Dec 2004 15:28 GMT
>I have a form that is approximatly 5000 lines of code. I estimate that
>about 70% of this is designer generated code for my controls on the form.
[quoted text clipped - 3 lines]
>
> What else can/should be done to keep the size of forms reasonable?

Is the size of the form creating a specific problem? If so, what problem is
it causing? You would then want to make sure that your usercontrol solution
solved this particular problem.

If it isn't causing a specific problem, then you've already got your
solution! :-)

John Saunders
Bruce Wood - 17 Dec 2004 19:16 GMT
I would never create a user control simply to group things on a form.

User controls certainly are worth the hassle. In fact, they're a
wonderful innovation. However, I would use them only when a group of
controls performs a single, simple function that I could state in one
sentence.

For example, I have a complicated user control that allows the user to
enter a normalized or denormalized fraction. It consists of a text box
and three combo boxes, but all work in concert to do a single, simple
thing. I use it wherever I need to have the user enter a fraction that
could be denormalized.

On the other hand, I would never (for example) create a user control to
enter dimensional information for lumber products. That's far too vague
a requirement, and it would be used in too few places.

I also have inherited text boxes that expect only integers, or only
decimal values, or only monetary amounts. Again, they offer
functionality that I will need often in the future, so I put it in a
user control rather than recreating it every time (and possibly getting
it wrong).
Marcos Stefanakopolus - 21 Dec 2004 06:48 GMT
> I also have inherited text boxes that expect only integers, or only
> decimal values, or only monetary amounts. Again, they offer
> functionality that I will need often in the future, so I put it in a
> user control rather than recreating it every time (and possibly getting
> it wrong).

On a related note: is it possible to subclass an existing control to add
functionality to it, _and_ get the forms designer to play nice with your
version of the control, without going to the trouble of creating a whole
user control?  For instance, I want to subclass PictureBox to give it more
display modes (that is, I really dislike the default clip-or-stretch
behaviors for images that exceed the dimensions of the PictureBox), but
that's all.  I'd like it if, when I drag a PictureBox into my app, I get an
instance of a myPictureBox class, rather than of a
System.Windows.Forms.PictureBox.

Can I do this without explicitly creating a user control just to hold my
subclassed control?
John Saunders - 21 Dec 2004 17:03 GMT
>> I also have inherited text boxes that expect only integers, or only
>> decimal values, or only monetary amounts. Again, they offer
[quoted text clipped - 14 lines]
> Can I do this without explicitly creating a user control just to hold my
> subclassed control?

How would VS.NET know to substitute your class for the one in the Toolbox?

Is there some difficulty putting your class into the toolbox?

John Saunders
Bruce Wood - 22 Dec 2004 18:37 GMT
The short answer is yes. In fact, that's what I did for my specialized
TextBoxes, but I didn't want to muddy the discussion on this thread
with that detail.

So, you can subclass PictureBox and insert your custom PictureBox on
forms just as you would a normal PictureBox. The only detail is that
you need to place your new PictureBox class in the tool box in Visual
Studio. VS will not "know" to use your PictureBox specialization
whenever you add a PictureBox to your Form, particularly since there
could be multiple specializations (just as I have multiple
specializations of TextBox).

Or, you could cheat like I do and simply insert a normal PictureBox and
then modify the code that the Designer inserts into your Form class.
You have to change it in only two spots: the declaration and the
instantiation. :)
Ed Kaim - 18 Dec 2004 00:44 GMT
What do you mean by "size of the form"? Is it a display real estate problem,
a memory problem, a source code problem, or other?

>I have a form that is approximatly 5000 lines of code. I estimate that
>about 70% of this is designer generated code for my controls on the form.
[quoted text clipped - 6 lines]
> I have heard that user contorls cause all kind of weird behaviour in the
> IDE?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.