How do I access controls/methods from another class using control designer verbs

Nazgulled

Centurion
Joined
Jun 1, 2004
Messages
119
Hi, I have the following code I got from divil (Introduction to Designers):

[csharp]using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;

namespace CSharpTest
{
[Designer(typeof(MyControlDesigner))]
public class UserControl1 : UserControl {
public Button button1 = new Button();
public void TestMethod() { }
}

internal class MyControlDesigner : ControlDesigner {
public override DesignerVerbCollection Verbs {
get {
DesignerVerbCollection v = new DesignerVerbCollection();
v.Add(new DesignerVerb("Sample Verb", new EventHandler(SampleVerbHandler)));
return v;
}
}

private void SampleVerbHandler(object sender, System.EventArgs e) {
// CODE GOES HERE
}
}
}[/csharp]


This codes places a task link in my subclassed usercontrol that I have placed on a form:
designerverb.jpg


I need to know how can I acces the controls/methods in the UserControl1 class inside the SampleVerbHandler().

Is this possible, how?
 
Solved:

[csharp]private void SampleVerbHandler(object sender, System.EventArgs e) {
UserControl1 myControl = this.Control as UserControl1;
if (myControl != null) {
// DO WORK HERE
}
}[/csharp]
 
Back
Top