aewarnick Posted October 29, 2003 Posted October 29, 2003 Here is the issue: I created my own listbox that requres an initialization variable be sent to it. The designer does not automatically put that in, so I have to edit the initialization in InitializeComponent for this listbox. I pass a vaiable to it when it is created: MyListBox lb=new MyListBox(4); The problem is that when I go back to the designer it restores the initialization to the way it was- thus, really messing thing up and making me angry. Is the any way to tell the designer to put certain code in the initialization of a variable? Or maybe a way to tell the designer not to modify that variable? Or another idea? Quote C#
*Experts* Nerseus Posted October 30, 2003 *Experts* Posted October 30, 2003 AFAIK, the designer won't preserve control arrays and probably never will. For control arrays, you'll have to manually create them in code. I've done similar things and put all the code in a function that I call immediately after InitializeComponent. You won't see the controls in the designer though. -Ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
aewarnick Posted October 30, 2003 Author Posted October 30, 2003 I'm not using control arrays. Maybe you glanced at the () and thought that was VB syntax not C#. Here is a better example: MyListBox lb=new MyListBox("Sending this string to new instance"); This is the way the designer seems to want it: MyListBox lb=new MyListBox(); But I need a way to send something to the new instance of the control. If I just need to rough it out without the designer, than so be it. Quote C#
Mehyar Posted October 30, 2003 Posted October 30, 2003 Finally, some one had the same problem i did. But I could not solve it till now. I made my own derived datagrid class and my constructor takes booleans to wether show the vertical and horizental scroll bars Ex: Dim dgRules as new MyDataGrid(True,False) but when ever i use them in the designer the designer changes them to : Dim dgRules as new MyDataGrid() I could not solve this one, but what i did is create my own initialize component and copied everything from the windows designer and pasted in in my sub and replaced the InitializeComponent by the sub i created, but I dont recommend it to anyone, you would lose the designer and anything you do in the design view you have to manually change the code in your custom function (which is extreme torture if your project is in its beginnings) Hope this helps, Quote Dream as if you'll live forever, live as if you'll die today
aewarnick Posted October 30, 2003 Author Posted October 30, 2003 I was hoping that wasn't the only solution. I didn't want to lose visual support. But I'll deal with it. Thanks guys. Quote C#
*Gurus* divil Posted October 30, 2003 *Gurus* Posted October 30, 2003 You have to create a new TypeConverter class for your listbox, and derive it from whatever typeconverter it uses as the moment. Then you have to provide a new way of converting to an InstanceDescriptor. This is the same way as in a few of the articles I've published. You then have to tell it to use your new constructor, and the designers will know how to serialize it properly. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted October 30, 2003 Author Posted October 30, 2003 Thanks divil, I'll look into it. Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.