How do I pass along variable in a custom control?

I've created a custom control in C# in VSE, and it appears on the list on the left. But I want to pass along a reference to my main form, and I'm currently doing so in the constructor. And then I've manually edited, the VSE Designer generated code to pass along the form itself. But hereafter when i try to with the designview VSE shows an errormessage. Have i done this the wrong way?

class canvas : Control
 {

     public canvas(Form1 theForm)
     {

     }
 }

And then in the designer generated code:

this.canvas2 = new panel2.canvas(this);

Answers


you could just use a public property.

public Form1 mainForm { get; set; }

You can then pass it in as a parameter on your canvas object.

<canvas mainForm='<%= this %>'></canvas>

Or from code:

this.canvas2.mainForm = this;

Need Your Help

How are lambdas resolved in the .NET framework?

c# .net vb.net lambda

For example, you can use lambda expressions in Visual Studio 2010, but still target .NET 2.0.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.