Code Generation

B

Bhargavan

I have created a user control to be used in form designing. When I add the
control to a form, it automatically generates the code for all the members
of that user control class. But I also have couple of methods in the class
and the code generation to call those methods are not automatically
generated. Any ideas about what I should be doing to fix this?
 
R

Richard Blewett [DevelopMentor]

Are you talking about Windows Forms or ASP.NET?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I have created a user control to be used in form designing. When I add the
control to a form, it automatically generates the code for all the members
of that user control class. But I also have couple of methods in the class
and the code generation to call those methods are not automatically
generated. Any ideas about what I should be doing to fix this?
 
M

Mohamoss

hi
I am not sure if I got you right! But if you just want these function code
to be called , why don't you add a call to these functions within
InitializeComponent(); of your control
rivate void InitializeComponent()
{
components = new System.ComponentModel.Container();
myfunction1();
myfunction2();
}

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
B

Bhargavan

Hi,
Thanks for your reply. I am talking about windows forms. I am trying to
autogenerate code for method call. The generated code should look something
like this...'this.usercontrol.addmethod(somevariable);'. But when I call the
method from Initialize component, it just runs that part of the code but
does not generate code in the windows form designer. Hope you understand the
situation now.
 
R

Richard Blewett [DevelopMentor]

Don't put these calls into the InitializeComponent call. This method is "owned" by the design environment and abything the designer can't understand will vanish when the deigner recreates the method (which is everytime something changes in the design view). If you want these method calls to be generated, in other words you want to make sure your code gets called by the designer, you could implement ISupportInitialize. When a control/component trhat implements ISupportInitialize is dropped on to the design surface, the compiler emits a call to ISupportInitialize.BeginInit and ISupportInitialize.EndInit into InitializeComponent. So if you are happy to have your method calls executed *before* the designer emits your property sets then you could put your method calls inside your ISupportInitialize.BeginInit.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

Hi,
Thanks for your reply. I am talking about windows forms. I am trying to
autogenerate code for method call. The generated code should look something
like this...'this.usercontrol.addmethod(somevariable);'. But when I call the
method from Initialize component, it just runs that part of the code but
does not generate code in the windows form designer. Hope you understand the
situation now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top