如何在自定义控件的“属性”窗口中创建链接?

发布于 2024-10-03 15:28:41 字数 207 浏览 4 评论 0原文

在 .NET Framework 中,有多个控件在 Visual Studio 设计器的“属性”窗口中的属性列表下方列出了许多链接。 (例如TabControl、ComboBox)

我已经构建了一个自定义控件,并且我想在属性窗口上创建一个链接,如TabControl 和ComboBox。单击链接时,应该调用我的控件上的某个方法。

我该怎么做?

谢谢!

In the .NET Framework, there are several controls that list a number of links underneath the property list in the Properties window in the Visual Studio designer. (e.g. TabControl, ComboBox)

I have built a custom control, and I want to create a link on the Properties Window like the TabControl and ComboBox. When the link is clicked, a certain method on my control should be called.

How can I do this?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦里寻她 2024-10-10 15:28:41

您需要为您的控件创建一个自定义设计器并覆盖 Verbs 属性。第一次调用重写时,创建一个 DesignerVerbCollection 并填充它。在每次后续调用时返回集合。

编辑:顺便说一下,您可以通过从 System.Windows.Forms.Design.ControlDesigner 派生来创建设计器,并通过将此属性放在类上来将其应用到您的类:

 [Designer(MyControlDesigner)]
 public class MyControl
 {
    // ...
 }

You need to create a custom designer for your control and override the Verbs property. The first time your override is called, create a DesignerVerbCollection and populate it. Return the collection on each subsequent call.

Edit: By the way, you create the designer by deriving from System.Windows.Forms.Design.ControlDesigner and you apply it to your class by putting this attribute on your class:

 [Designer(MyControlDesigner)]
 public class MyControl
 {
    // ...
 }
玻璃人 2024-10-10 15:28:41

我认为您正在寻找 DesignerVerb班级。

I think you're looking for the DesignerVerb class.

酒与心事 2024-10-10 15:28:41

devarticles< /a>

public class DirectoryTreeDesigner : ControlDesigner 
{ 

protected override void PostFilterProperties( 
System.Collections.IDictionary properties) 
{ 
     properties.Remove("Nodes"); 
} 

DesignerVerbCollection verbs = new DesignerVerbCollection(); 

public DirectoryTreeDesigner() 
{ 
     // Configure the designer verb collection. 
     string[] drives = System.IO.Directory.GetLogicalDrives(); 

     foreach (string drive in drives) 
     { 
         verbs.Add(new DesignerVerb("Set Drive " + drive, new EventHandler(OnVerb))); 
     } 
} 

public override DesignerVerbCollection Verbs 
{ 
     get { return verbs; } 
} 

protected void OnVerb(object sender, EventArgs e) 
{ 
    // Retrieve the selected drive. 
    char driveLetter = ((DesignerVerb)sender).Text[10]; 

    // Adjust the associated control. 
    ((DirectoryTree)this.Control).Drive = driveLetter; 
} 

}

devarticles

public class DirectoryTreeDesigner : ControlDesigner 
{ 

protected override void PostFilterProperties( 
System.Collections.IDictionary properties) 
{ 
     properties.Remove("Nodes"); 
} 

DesignerVerbCollection verbs = new DesignerVerbCollection(); 

public DirectoryTreeDesigner() 
{ 
     // Configure the designer verb collection. 
     string[] drives = System.IO.Directory.GetLogicalDrives(); 

     foreach (string drive in drives) 
     { 
         verbs.Add(new DesignerVerb("Set Drive " + drive, new EventHandler(OnVerb))); 
     } 
} 

public override DesignerVerbCollection Verbs 
{ 
     get { return verbs; } 
} 

protected void OnVerb(object sender, EventArgs e) 
{ 
    // Retrieve the selected drive. 
    char driveLetter = ((DesignerVerb)sender).Text[10]; 

    // Adjust the associated control. 
    ((DirectoryTree)this.Control).Drive = driveLetter; 
} 

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文