|
-
Jan 30th, 2003, 08:19 PM
#1
Thread Starter
Junior Member
Custom Designer
Hello, I have the following problem: I created an inherited class that inherits DataGrid and I added a property called MyProperty as integer. Then I created another class called CustomDesigner that inherits from System.Windows.Forms.Design.ControlDesigner and I setup the Design Attribute for my grid class to use this custom designer.
All works ok (I can see some messages I inserted in the Initialize() function in the designer)... but... I fail to understand how to make the actual "connection" between the changes in the property and the code behind the form. For example, if I change the property "AllowDrop" from the default value of false to True, if I look in the code, right away the line: Me.TestGrid1.AllowDrop = True appears in the InitializeComponent() routine....
But, when I change the additional property (MyProperty) nothing changes in the code behind the form, therefore rendering my custom designer to a useless item...
So, my question is: how can I "catch" the changes in the properties that extend a base class and reflect them in the InitializeComponent() function from the code behind the form?
Any help is appreciated,
Thank you!
Iulian
PS: If you know any books that talk about custom designers...
-
Jan 31st, 2003, 10:54 PM
#2
Thread Starter
Junior Member
Ok, I did some research yesterday (I went to bed at 3... I was like a zombie at work)... and I found out that I actually have to use the codeDOM to generate the new code... For example, this:
Dim cscProvider As VBCodeProvider = New VBCodeProvider()
Dim cscg As ICodeGenerator = cscProvider.CreateGenerator(Console.Out)
Dim cop As CodeGeneratorOptions = New CodeGeneratorOptions()
Dim csu1 As CodeSnippetCompileUnit = New CodeSnippetCompileUnit("using System")
Dim csu2 As CodeSnippetCompileUnit = New CodeSnippetCompileUnit("using System.IO")
cscg.GenerateCodeFromCompileUnit(csu1, Console.Out, cop)
cscg.GenerateCodeFromCompileUnit(csu2, Console.Out, cop)
Dim st As CodeAssignStatement = New CodeAssignStatement(New CodeVariableReferenceExpression("x"), New CodePrimitiveExpression(1))
cscg.GenerateCodeFromStatement(st, Console.Out, cop)
would create this:
Using System
Using System.IO
x = 1
Not that it has any sense but it proves that it can be done... But now... the new problem! I can output the code wherever I want, but I really need to dump it in the code behind the form, and more exactly somewhere before the end of the InitializeComponent... I don't know now how to get a reference to the code and direct my output there? And how to locate the place? Maybe by parsing the code and looking for the last sentance??
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|