Results 1 to 8 of 8

Thread: User Controls

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207

    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

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    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.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What the heck does that mean? Does it only do it when you add the Icon to the control?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    Every thing works great until I put that toolbar statement in there, if i take it out and recompile it works again.

    Jeremy

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I think it should be this:
    VB Code:
    1. <ToolboxBitmap(GetType(Button), "C:\icon.bmp")> _
    2. Public Class Statusbar
    3.  
    4. 'or if you want then this
    5. <ToolboxBitmap(GetType(Button), "C:\icon.bmp")> Public Class Statusbar

    Unless you a have a Toolbar Class as well.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    Ahh, that would explain it.

    Thanks, I guess I was just reading it wrong.

    Jeremy

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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
  •  



Click Here to Expand Forum to Full Width