将简单形状添加到工具箱 [英] Add A Simple Shape To Toolbox

查看:71
本文介绍了将简单形状添加到工具箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个继承自Microsoft.VisualBasic.PowerPacks.OvalShape的OvalShape。

控件运行良好,但它没有显示在设计器工具箱中。

< b>如何让形状控件显示在工具箱中?



我做了一些搜索并尝试使用以下属性进行播放:

I created an OvalShape that inherited from Microsoft.VisualBasic.PowerPacks.OvalShape.
The control works great but it does no show up in the designer Toolbox.
How do I get the shape control to show up in the Toolbox?

I did some searching and tried playing with the attributes such as adding:

[ToolboxItem(true)]



还想到我添加的东西可能导致设计师不想添加我创建了一个测试类,我继承了OvalShape并且没有添加任何东西,它没有显示出来。

我还有一些其他的控件,我从Button和Label继承而且它们显示得很好。



目前我正在使用

Visual Studio Express 2012版本11.0.50727.42.VSLRSTAGE

Microsoft .NET框架版本4.5.50709

Windows 7



谢谢,

Vince



* /编辑\ *

这看起来像是ar eal初学者问题,但我之前做过控制,从来没有遇到进入工具箱的问题。当你继承自Microsoft.VisualBasic.PowerPacks.OvalShape


Also thinking that maybe something I added caused the designer to not want to add it I created a test class where I inherited from the OvalShape and added nothing to it and it did not show up.
I have a few other controls I inherited from Button and Label and they show up fine.

Currently I'm using
Visual Studio Express 2012 Version 11.0.50727.42.VSLRSTAGE
Microsoft .NET Framework Version 4.5.50709
Windows 7

Thanks,
Vince

*/Edit\*
This may seem like a real beginner question but I have made controls before and never had problems getting them into the toolbox. Something real strange is happening when you inherit from Microsoft.VisualBasic.PowerPacks.OvalShape

推荐答案

我遇到了同样的问题。到目前为止我还没有解决它,但是要提供一些信息:



SimpleShape派生自Shape,它是一个组件(IComponent)。



如果您将任何预定义的形状(例如LineShape,OvalShape等)拖放到表单中,它们会自动添加到ShapeContainer中,而ShapeContainer是在不存在时创建的。 br />
这个ShapeContainer是一个控件,管理形状。



此行为由自定义ToolboxItem实现完成。例如对于LineShape,这由LineShapeToolboxItem完成

I have the same problem. I have not solved it so far, but to give some information:

SimpleShape derives from Shape, which is a Component (IComponent).

If you drag and drop for instance any of the predefined Shapes, such as LineShape, OvalShape, etc.. to your form they are added automatically to a ShapeContainer, which is created when not existing.
This ShapeContainer is a Control, managing the Shapes.

This behaviour is done by a custom ToolboxItem implementation. For instance for LineShape this ist done by LineShapeToolboxItem
[ToolboxItem("Microsoft.VisualBasic.PowerPacks.Design.LineShapeToolboxItem, Microsoft.VisualBasic.PowerPacks.VsPackage, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
 [Designer("Microsoft.VisualBasic.PowerPacks.Design.LineShapeDesigner, Microsoft.VisualBasic.PowerPacks.VsPackage, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
 [ToolboxItemFilter("System.Windows.Forms")]
 [DesignTimeVisible(false)]
 [SResDescription("DescriptionLineShape")]
 [ToolboxBitmap(typeof (LineShape), "Microsoft.VisualBasic.PowerPacks.LineShape.bmp")]
 public class LineShape : Shape
 {







namespace Microsoft.VisualBasic.PowerPacks.Design
{
  [Serializable]
  internal sealed class LineShapeToolboxItem : ShapeToolboxItem
  {










namespace Microsoft.VisualBasic.PowerPacks.Design
{
  internal abstract class ShapeToolboxItem : ToolboxItem
  {





编写自定义时ToolBoxItem,必须重写CreateComponentsCore方法。当您在工具箱中选择并将其拖放到表单上的控件/组件时,应该创建此方法。它返回一个Components数组。所以你可以返回100个标签,然后由设计师插入。



一个非常难看的是,所有这些漂亮的设计内容都被隐藏为内部(并且经常密封)Microsoft.VisualBasic.PowerPacks.Design命名空间中的类。实现在



C:\Program Files(x86)\ Microsoft Visual Studio 10.0 \ Common7 \IDE \ PrivatePrivateAssemblies\Microsoft.VisualBasic。 PowerPacks.VsPackage.dll



(您可以通过一些反编译器查看它,例如DotNetPeek)





SimpleShape没有指定的ToolboxItem。你必须编写自己的一个,这也意味着你必须管理与ShapeContainer相关的东西。



除了ToolboxItems之外,还有几个Designer类。



如果您可以管理自定义形状的创建,然后将其插入到ShapeContainer中,并且您编写了自定义设计器,则在ShapeConainter之后会出现异常。添加到Form.Controls并应绘制,因为

(在ShapeContainerdesigner中)



When writing a custom ToolBoxItem, the CreateComponentsCore method has to be overridden. This method is called, when the control/component, you select in the toolbox and drag &drop it on your form, should be created. It returns an array of Components. So you could for instance return 100 Labels, that then are inserted by the designer.

One very ugly thing is, that all these nice design stuff is hidden as internal (and often sealed) class within the Microsoft.VisualBasic.PowerPacks.Design namespace. the implemenattion is in

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualBasic.PowerPacks.VsPackage.dll

(you can have a look on it with some decompilers, such as DotNetPeek)


The SimpleShape does not have a specified ToolboxItem. You have to write your own one, which also means that you have to manage the stuff related to the ShapeContainer.

Beside the ToolboxItems, there are several Designer classes.

If you can manage the creation of your custom shape, which then is inserted into a ShapeContainer, and you have written your custom designer an exception will rise, after the ShapeConainter is added to Form.Controls and should be Painted, since
(within the ShapeContainerdesigner)

 private void OnPaintShapeContainer(object sender, PaintEventArgs e)
    {
     ...
          Shape shape = (Shape) this.ShapeContainer.Shapes.get_Item(index);
          ShapeDesigner shapeDesigner = (ShapeDesigner) (object) designerHost.GetDesigner((IComponent) shape);
...  





你的自定义形状的设计师被铸造成ShapeDesigner,这是一个类,你不能继承。 ....



似乎微软希望你自己编写所有内容,或者复制并粘贴反汇编代码进行修改....(可能不会允许)

:o





真诚的你

Martin



your custom shape's designer is casted as ShapeDesigner, which is a class, you can not inherit from.....

It seems that Microsoft wants either you writing everything on your own, or to copy and paste disassembled code for modification....(which may not be allowed)
:o


Sincerely Yours
Martin


对我来说最简单和最好的解决方案是添加属性
The simplest and the best solution that worked for me is adding attribute
DesignTimeVisible(true)

继承类。


这篇关于将简单形状添加到工具箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆