ozie Posted June 4, 2004 Posted June 4, 2004 Hello all I read through and have been playing with Tim's "Hosting Windows Forms Designers" code and tut.. I would be the first to say that I really understood about 2% of the important hows and whys, but I am having a little trouble with it Firstly i only understand vb and not c#(one day will learn) what i have done is played around and extended the demo code and added my own usercontrol that displays a propertygrid linked to my own class which holds a few properties like dock and anchor and a few others. now then you change the dock property within my control it changes the current selected item on the host form to the docking style i select..this is all good.. the problem is that once the control moves the box around it that display the grips stays where the control was, it doesnt move with it. the other problem i am having is adding controls via code when the program starts.. ie i want to add say a tab control and dock it to the bottom of the host window. Now in a way i think i have it working.. pnlViewHost.Controls.Add(view) host.CreateComponent(GetType(Janus.Windows.UI.Tab.UITab)) .. i think this because once i run the program if i drag from the toolbox another tab control it labels it tab 2 so the one i added was tab 1. But the tab i created does not display on the form.. i wanted to work this out so that once i have a form setup that i could somhow work out a way to save it so that i could open it and have it display what i saved later on. thanks for any help. Oz PS - with many controls once you drop them on the form they have a right mouse menu for things like the tab control to add a new tab.. can this also be done?? Quote
AlexCode Posted June 7, 2004 Posted June 7, 2004 I also used the Tim's hosting article to develop my own IDE. My stuff is somethig a little diferent from the usual, as it persists the controls to XML along with the user code, so no exe's neither dll's... only XML. This XML files are addins scripts to my ERP app, most like templates. So this is how I persist the results of my IDE... how do you do it? You're having problems showing the forms... but how do you persist tjem? It's a start so I can help you... Alex :P Quote Software bugs are impossible to detect by anybody except the end user.
ozie Posted June 7, 2004 Author Posted June 7, 2004 Yeah I was going to use XML to store the control location etc.. then when the app is run load them to the form and bind the data table items to the correct control on the form (textboxes) i just cant work out how to have the IDE designer of Tim's open and load items.. ie if i have created one and saved it, i now want to open it and change things around.. I just can not seem to work out how to add controls etc via code Thanks Oz Quote
AlexCode Posted June 7, 2004 Posted June 7, 2004 I can't give you the exact code because it's already registered to my company... ;) But I can give you some hints: 1- You have to serialize the objects, this isn't easy, and it's not documented around the internet. You must create your own inherited controls, lets say fom a Button control, and implement the IXMLSerializable interface. Then write your own WriteXML, ReadXML and XMLSchema code so it knows what properties you want to persist to XML. 2- Using the technique descrybed above, you can persist the Controls property of the form, and it will create a chain of controls as Parent->Child. This way, when you deserialize the controls they will be on their correct places. 3- As to code, use the Scripting technique Tim describes... This way you'll be able to have code related to the persisted objects. Compiling the deserialized objects with the scripted code will integrate both. 4- Using this, if you create your objects on the script code, they will appear on the form... Note... This took me about 1 month to accomplish... so don't expect this to be easy. The used time was mostly spent on the object serialization/deserialization process and on the code text editor... Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
ozie Posted June 8, 2004 Author Posted June 8, 2004 Thanks.. I already have all the XML and schemas ready to go.. the whole purpose of the post was to get some code help. i already knew that "isn't easy" and "it's not documented around the internet" hence the reason for the question since there isnt any help out there. Guess i'll just keep lookings Thanks Oz Quote
AlexCode Posted June 8, 2004 Posted June 8, 2004 As is, is my 3rd point on my previous post... Use the scripting technique, it's the best way I've found. It's not just copy/past from Tim's code, but using Delegates or, one level up, simple events to connect the two modules (code and objects) you'll find the way out... As a start code structure taka a detailed look at the auto generated code by the vs.net... the onlu part you don't need it's the object properties, the rest it's all suitable. Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
*Gurus* divil Posted June 8, 2004 *Gurus* Posted June 8, 2004 If you implement IDesignerSerializationManager you can use the existing code serialization build in to the framework to serialize your designed form/document. This is the same stuff VS uses. 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
AlexCode Posted June 8, 2004 Posted June 8, 2004 My present serialized form document looks like the attached file. This represents a Form (myMDIChild), with a Panel (myPanel1) with two button in it (myButton2 & myBut). The <UnderlyingCode> tag represents the user code for that form... If you noticed, everything is between a <SerClass> tag. This SerClass is a class that holds several typed arrays, each one representig a possible serialized type. The "my[controls]" represent my custom inherited controls that implement IXMLSerialize. This is my way of doing it! :p Alex :pWorking.zip Quote Software bugs are impossible to detect by anybody except the end user.
ozie Posted June 9, 2004 Author Posted June 9, 2004 Thanks divil and alexcode I will look further into all this and see how i go Oz Quote
ozie Posted June 11, 2004 Author Posted June 11, 2004 Tim.. I came across this old posting of yours http://www.dotnet247.com/247reference/msgs/33/165825.aspx could you explain a bit for me how you go about "you then have to add it to the design container anyway, and still have to add it to the form to make it show up" Just like the other person that asked the same sort of question as to what i am trying to do, i cant work out how once i create an instance of a control in code to add it to the designer?? i really have no idea how to use or code into the sample the IDesignerSerializationManager Oz Quote
ozie Posted June 11, 2004 Author Posted June 11, 2004 OK I HAVE FOUND IT ALL... If anyone else is interested in this it is C# :( But it is a fully coded example of how it all works and shows code in the designer in C# or VB or XML http://www.it-faq.pl/mskb/813/808.HTM the file that you want to get and check out is at: http://download.microsoft.com/download/f/d/9/fd986a23-d3d6-44c3-8fa0-75e21b0094bf/DesignerHost.exe thanks everyone for ya help Oz Quote
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.