|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
User Control constructors taking arguments?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 > These work fine as workarounds go, but I really would prefer to simply You can create a constructor that takes an argument of course. Just make > 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? 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 ;). 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 <itoldyounottospamme@nowmyinboxisfull.com> wrote: Show quoteHide quote > >> 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 ;). > Ah well, I guess I'll just have to code everything in manually, then. You can determine how the visual designer interacts with your control and > 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. 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).
Help with Adding A Row
is an object destroyed/closed when an exception occurs Adding event (mouseclick) handlers to GDI+ shapes? How to input characters that are not present in a keyboard to a VB source and multiple machines newbe help please. paste disabled when i add a menubar in vb2005 UI Challenge: How to create a real outliner (like Ecco, Grandview, etc) - SampleDisplay.bmp (0/1) paramertised select query Windows form is getting crashed VB.Net 2005 Commandline Arguments to the exe corresponding to a Windows Service |
|||||||||||||||||||||||