March 17, 2005

Verbs in C# Whidbey

Error: Verbs Error: no suitable method found to override.
If you have the "public override DesignerVerbCollection Verbs" problem in your UserControl's Class (in C# 2.0 or C# 2005) then you must use an "internal class" of "ControlDesigner" similar to your UserControl's class because the UserControl dose not contain the Verbs property and the "public override DesignerVerbCollection Verbs" can't accept the override method.
The brilliant way to insert a new item in the Actions Menu in the design mode for your UserControl(s) is to use the "internal class" after your UserControl class.
For example:

internal class MyControlDesigner : System.Windows.Forms.Design.ControlDesigner
{
    private DesignerVerbCollection m_pVerbs = new DesignerVerbCollection();
    public override System.ComponentModel.Design.DesignerVerbCollection Verbs
    {
        get
        {
            if (m_pVerbs.Count < 1)
            {
                m_pVerbs.Add(new DesignerVerb("About", new EventHandler(this.heoAbout_Click)));
            }
            return m_pVerbs;
        }
    }
    private void heoAbout_Click(object sender, EventArgs e)
    {
        MessageBox.Show("You're Successful");
    }
}
But this is important that you must show this class to the Runtime Designer, with like this code:
[Designer(typeof(MyControlDesigner))]
You must put this code to top of your master UserControl class.
Please, attention to this: System.Windows.Forms.Design
If you don't have this reference in your Project's References you must add it.
خب راستش بدجوری تو گل گیر کرده بودم تا اینکه راهش پیدا شد. یک پروژه تو 2003 را به 2005 بیارید و بعد از Convert شدن خوب بررسیش کنید. اصولا اغلب تغییرات رو می شه از همین روش پیدا نمود البته تا زمانی که یه help درست حسابی براش بیاد. اگه متن بالا رو هم بخونید متوجه می شوید که چه راحت می شه یک Verb override نوشت تازه کلی هم به کلاس برنامه اضافه می شه :)) خوش باشید.

2 comments:

Anonymous said...

High Google and Yahoo link popularity can be yours,

Anonymous said...

Sometimes, these gambles pay off, but there are occasions when they fail miserably,