用户控件的图标。 [英] Icon to a User Control.

查看:98
本文介绍了用户控件的图标。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向用户控件中默认显示的齿轮显示不同的图像。当指示属性指向我正确获取的文件时,但当我希望嵌入DLL作为资源时不能。

请帮忙吗?

工作原理:

I'm trying to show a different image to the gear that comes by default in a user control. When indicated attribute pointing to a file I get correctly, but when I wish to be embedded in the DLL as a resource can not.
Any help please?
How it works:

[ToolboxBitmap(@"\\se41\noasistencial\ServTecnInfor348\Desarrollo\Imagenes\ControlesDeUsuarios\Ravisoft\rvsPanel.bmp")]
public class rvsPanel: System.Windows.Forms.Panel
{
 ...
}




[ToolboxBitmapAttribute(typeof(Panel), "rvsPanel.bmp")]
public class rvsPanel: System.Windows.Forms.Panel
{
 ...
}



在后一种情况下,bmp作为项目资源包含在内。


In the latter case the bmp is included as a project resource.

推荐答案

要理解MSDN文档是什么并不容易主题实际上意味着。



首先,我认为如果全名用于Type,属性更容易理解,

例如

It is not easy to understand what the MSDN documentation for this topic actually means.

Firstly I think the attribute is easier to understand if full names are used for the Type,
e.g.
namespace ControlLib {
  [ToolboxBitmap(typeof(ControlLib.MyUserControl), "Bitmaps.red.bmp")]
  public partial class MyUserControl : UserControl {
    public MyUserControl() {
      InitializeComponent();
    }
  }
}





该属性隐含的资源名称为

resourcename =ControlLib+。 +Bitmaps.red.bmp



那么我们如何创建 ControlLib.Bitmaps.red.bmp 资源?



假设项目具有默认命名空间ControlLib



The name of the resource implied by that attribute is
resourcename = "ControlLib" + "." + "Bitmaps.red.bmp"

So how do we create the ControlLib.Bitmaps.red.bmp resource?

Assuming a project with the default namespace ControlLib

1) Add the file red.bmp to the Bitmaps subdirectory<br />
2) In Solution Explorer right click the file to get the properties page and change the Build Action from None to Embedded Resource





请注意,通过设计器生成的强类型资源类ControlLib.Properties.Resources无法访问以这种方式添加的资源。



任何引用ControlLib程序集的项目都应该看到自定义工具箱位图。在我相当老的VS(c#express 2005)中存在一些困难



Note that a resource added in this way is not accessible via the designer generated strongly typed resource class ControlLib.Properties.Resources.

Any project referencing the ControlLib assembly should see custom toolbox bitmaps. In my rather old VS (c# express 2005) there are some difficulties

1) The default bitmaps are used when the assembly is added as a project reference.<br />
2) Custom bitmaps are not automatically refreshed and if changed must be deleted from the toolbox and readded via the Choose Toolbox Items dialog.





最后,我很难弄明白何时会使用 [ToolboxBitmap(Type)] ,但是2006年这个说明(http://support.microsoft.com/kb/311315 [ ^ ])清楚地表明它允许您使用现有控件中的自定义位图。例如,如果您的自定义控件是已修改的ProgressBar,则可能需要使用该位图。方法如下:



Finally I struggled to figure out when [ToolboxBitmap(Type)] would be used, but this note from 2006 (http://support.microsoft.com/kb/311315[^]) makes it clear that it allows you to use the custom bitmap from an existing control. For example if your custom control is a modified ProgressBar you may want to use that bitmap. Here's how:

namespace ControlLib {
  [ToolboxBitmap(typeof(System.Windows.Forms.ProgressBar))]
  public class MyProgressBar : ProgressBar {





Alan。



Alan.


这篇关于用户控件的图标。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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