PDA

View Full Version : Component Class



regbyte
یک شنبه 21 بهمن 1386, 02:57 صبح
چطوری می تونم به یک Component Class یک Icon اختصاص بدم؟

لطفا راهنمایی کنید.

Mahdi.Kiani
یک شنبه 21 بهمن 1386, 07:59 صبح
ToolBoxBitmap(<icon>);

search

sinpin
یک شنبه 21 بهمن 1386, 08:17 صبح
چطوری می تونم به یک Component Class یک Icon اختصاص بدم؟
لطفا راهنمایی کنید.


The Toolbox Icon
Adding a Toolbox icon is refreshingly easy. All you need to do is add a bitmap to your project and follow
these rules:
• The bitmap file must have the same name as your custom control class (but with the extension
.bmp). For example, you would use a bitmap named CustomTextBox.bmp for the
CustomTextBox control.
• The bitmap must be 16×16 pixels. Otherwise, it will be mangled when Visual Studio
attempts to scale it.
• The bitmap must use only 16 colors.
• Once you add the bitmap file, you must use the Properties window to set the Build Action to
Embedded Resource.
[ToolboxBitmap(typeof(CustomTextBox), "CustomTextBox1.bmp")]
public class CustomTextBox : WebControl, IPostBackDataHandler
{ ... }
You can also use this trick to place bitmaps in a separate subfolder in your project. For example,
here’s how you would refer to a bitmap in a folder named Images:

[ToolboxBitmap(typeof(CustomTextBox), @"Images\CustomTextBox1.bmp")]Finally, it’s also possible to steal bitmaps from core ASP.NET controls, using code like this:

[ToolboxBitmap(typeof(System.Web.UI.WebControls.Tex tBox))]If you’re creating a simple control, all you may need to do is add a set of descriptive properties
and a toolbox icon. However, more complex controls often require other considerations. These
range from code serialization issues (how the control tag is created when you use the Properties window)
to control designers (advanced tools for customizing the design-time HTML your control
renders). In the rest of the chapter, you’ll take a look at these topics.

منبع - این مطالب از این کتاب بود :
Pro ASP.NET 3.5 in C# 2008, Second Edition
کتاب خوبیه و بخشی رو منحصرا به مبحث Design-Time Support اختصاص داده با این مباحث :
■CHAPTER 28 Design-Time Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1151
The Key Players . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1151
Design-Time Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1152
The Properties Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1153
Attributes and Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1157
The Toolbox Icon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1158
Web Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1159
Creating a Resource. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1159
Retrieving a Resource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1160
Text Substitution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1161
Code Serialization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1162
Type Converters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1162
Serialization Attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1170
Type Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1172
Control Designers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1174
Design-Time HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1175
Smart Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1177
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1182