473,388 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

User Control constructors taking arguments?

Hi, me again,
I'm trying to create a User Control in VS2003 that takes an object as an
argument from its parent form and designs itself accordingly.
At the moment, I'm having to create a default, empty constructor method
and then adjust the size later by sending in the argument in a later
method and then resizing everything, instead of simply creating things
according to these arguments in the first place.

Obviously, seeing as the whole design of the User Control is based on the
object I'm feeding it, I'd prefer to feed the object directly into the
constructor, but doing that involves altering that part of the code that
Visual Studio tells you not to (the InitializeComponent() method) and
which throws an absolute, utter fit whenever I have done.

These work fine as workarounds go, but I really would prefer to simply
have a constructor for the User Control that takes an argument.

Perhaps this would be better put into the microsoft.public.vstudio.general
newsgroup, seeing as this seems to be all VS's fault for rewriting my code
and throwing fits and stuff, but as that looks utterly dead, I thought I'd
try here first.
Any advice, or I do stick to my workarounds?

KF

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Sep 5 '06 #1
3 5060
These work fine as workarounds go, but I really would prefer to simply
have a constructor for the User Control that takes an argument.

Perhaps this would be better put into the microsoft.public.vstudio.general
newsgroup, seeing as this seems to be all VS's fault for rewriting my code
and throwing fits and stuff, but as that looks utterly dead, I thought I'd
try here first.
Any advice, or I do stick to my workarounds?
You can create a constructor that takes an argument of course. Just make
sure the first thing you do in the constructor is call
"InitializeComponent". Of course you can't make use of this in Design-Time
only if you dynamically create the control at run-time, which I assume you
are wanting to do. Otherwise, you could give the control a property and set
that property at Design-Time, but this might require some messing about ;).

Sep 5 '06 #2
Ah well, I guess I'll just have to code everything in manually, then.
It's pretty annoying, though. The main reason I'm using VB in the first
place is because of the ease-of-use of the Form Designer. Not being able
to use that now for a lot of my custom components... kind of makes using
VB a bit pointless, really.

KF

On Tue, 05 Sep 2006 15:33:36 +0100, Robinson
<it*****************@nowmyinboxisfull.comwrote:
>
>These work fine as workarounds go, but I really would prefer to simply
have a constructor for the User Control that takes an argument.

Perhaps this would be better put into the
microsoft.public.vstudio.general
newsgroup, seeing as this seems to be all VS's fault for rewriting my
code
and throwing fits and stuff, but as that looks utterly dead, I thought
I'd
try here first.
Any advice, or I do stick to my workarounds?

You can create a constructor that takes an argument of course. Just
make sure the first thing you do in the constructor is call
"InitializeComponent". Of course you can't make use of this in
Design-Time only if you dynamically create the control at run-time,
which I assume you are wanting to do. Otherwise, you could give the
control a property and set that property at Design-Time, but this might
require some messing about ;).


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Sep 5 '06 #3
Ah well, I guess I'll just have to code everything in manually, then.
It's pretty annoying, though. The main reason I'm using VB in the first
place is because of the ease-of-use of the Form Designer. Not being able
to use that now for a lot of my custom components... kind of makes using
VB a bit pointless, really.

You can determine how the visual designer interacts with your control and
make your control like all the other Windows Forms controls too. There is a
whole section on generating your own designer methods. Look up
ParentControlDesigner for example. It's entirely possible to do, but yes
you do have to write more code to get it to work properly (it can also be a
bit of a pain to debug).
Sep 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Philip Smith | last post by:
Call this a C++ programmers hang-up if you like. I don't seem to be able to define multiple versions of __init__ in my matrix class (ie to initialise either from a list of values or from 2...
42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
11
by: Sam Wilson [Bentley] | last post by:
If you pass a C++ object by value as an argument to a function which has a variable-length argument list (...), the MSVC7 C++ compiler does not call the object's copy constructor and will not...
4
by: Ganesh Gella | last post by:
Hi All, While going through xalan's XSLT source code, I came across few constructors which are qualified as "explicit". These constructors are empty constructors. I read about the use of...
3
by: John | last post by:
Before anything else, thanks Marina, Workgroups and Ralf, for your help so far. I am now able to better define the question! After adding more console printout lines to CSum, I tried all...
12
by: Oleg Subachev | last post by:
I am moving from Delphi to C# and hve encountered the problem: I have the following classes and form Load event handler: public class class1 { public string S; public class1( string aS ) {...
3
by: zlf | last post by:
I am asked to complete a COM+ component, there is a class A derived from ServicedComponent. However, when executing , exception is thrown. Messaged: Unhandled Exception:...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
7
by: andrewfsears | last post by:
I have a question: I was wondering if it is possible to simulate the multiple constructors, like in Java (yes, I know that the languages are completely different)? Let's say that I have a class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.