|
-
Oct 10th, 2002, 10:22 PM
#1
Thread Starter
Addicted Member
User Controls
Ok,
I have finished a user control that I plan on using. I could assign an icon to a particular control really easy in vb6 but I don't see the option to assign an icon to a user form in VB.net.
Any idea?
Jeremy
-
Oct 10th, 2002, 11:36 PM
#2
This is from the Help:
Providing a Toolbox Bitmap for Your ControlSee Also
Control Authoring for Windows Forms | Visual Basic .NET Attributes | Introduction to Attributes
You might want to have a special icon for your control appear in the Toolbox. You can specify a particular image by using the ToolboxBitmapAttribute Class. This class is an attribute, a special kind of class that you can attach to other classes. For more information on attributes, see Attributes Overview for Visual Basic and Introduction to Attributes for C#.
Using the ToolboxBitmapAttribute, you can specify a String that indicates the path and file name for a 16 by 16 pixel bitmap. This bitmap will then appear next to your control when added to the Toolbox. You can also specify a Type, in which case the bitmap that is associated with that type is loaded. Or you can specify both a Type and a String, in which case the control will search along the path specified for a bitmap file, and if none is found then it will use the bitmap associated with the type.
To specify a Toolbox bitmap for your control
Add the ToolBoxBitmapAttribute to the class declaration of your control before the Class keyword for Visual Basic, and above the class declaration for Visual C#.
' Visual Basic
' Specifies the bitmap associated with the Button type.
<ToolboxBitmap(GetType(Button))> Class MyControl
' Specifies a bitmap file.
<ToolboxBitmap("C:\myImage.bmp")> Class MyControl
' Specifies both a custom image, and a default type image.
<ToolboxBitmap(GetType(Button), "C:\myImage.bmp") Class MyControl
// C#
// Specifies the bitmap associated with the Button type.
[ToolboxBitmap(typeof(Button)]
class MyControl : UserControl
// Specifies a bitmap file.
[ToolboxBitmap(@"C:\myImage.bmp")]
class MyControl : UserControl
[ToolboxBitmap(typeof(Button), @"C:\myimage.bmp")]
class MyControl : UserControl
See Also
Control Authoring for Windows Forms | Visual Basic .NET Attributes | Introduction to Attributes
-
Oct 11th, 2002, 11:20 AM
#3
Thread Starter
Addicted Member
This is the code i am using:
<ToolboxBitmap(GetType(Button), "C:\icon.bmp")> Class ToolBarIcon
End Class
Public Class Statusbar
Inherits System.Windows.Forms.UserControl
.....
This is the error:
An error occurred while loading the document. Fix the error, and they try loading the document again. The error message follows:
The class Statusbar can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file and try loading the designer again.
-
Oct 11th, 2002, 11:22 AM
#4
What the heck does that mean? Does it only do it when you add the Icon to the control?
-
Oct 11th, 2002, 11:54 AM
#5
Thread Starter
Addicted Member
Every thing works great until I put that toolbar statement in there, if i take it out and recompile it works again.
Jeremy
-
Oct 11th, 2002, 12:00 PM
#6
I think it should be this:
VB Code:
<ToolboxBitmap(GetType(Button), "C:\icon.bmp")> _
Public Class Statusbar
'or if you want then this
<ToolboxBitmap(GetType(Button), "C:\icon.bmp")> Public Class Statusbar
Unless you a have a Toolbar Class as well.
-
Oct 11th, 2002, 12:22 PM
#7
Thread Starter
Addicted Member
Ahh, that would explain it.
Thanks, I guess I was just reading it wrong.
Jeremy
-
Oct 11th, 2002, 12:31 PM
#8
Yeah i think it was a little more confusing because the class name kinda sounded like something to do with the toolbox.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|