[RESOLVED] [2008] Create my own textbox
Hi all
I want to create my own control like a textbox with more properties...
I know that I should use "Inherits the textbox" but don't understand how?
I've tried to create a usercontrol and inside a textbox... but I couldn't change the size of the textbox inside the usercontrol...
So I tried to created my own class and inherits the textbox class... and add my properties that I need...
I want to be able to drag from the toolbox my control and the idea is that it will look and behave like the textbox but with my additional properties and methods... thanks
Re: [2008] Create my own textbox
Create and compile your user control. Right-click on the toolbox and select "Choose Items". There's a "Browse" button there that lets you navigate to the executable for the control you just compiled. Select that and it will show up on the toolbox and you can drag it onto your form.
Re: [2008] Create my own textbox
If by resize you mean resize its height then no you cant unless you make it multiline.
Re: [2008] Create my own textbox
Controls inside a user-control can not be resized from the form, you'll have to go into the usercontrols design-view and change it. But the best thing would be, as you mentioned, to inherit the TextBox.
You should create a new class by clicking "New item.." in the Project menu, Simply add "Inherits TextBox, on the second line of your new class. It will now inherit from the TextBox and you're free to add new members to it as you please.
Re: [2008] Create my own textbox
But remember that by only using a class that inherits the textbox you wil have to manually add a regular textbox control to your for and then modify the designer code to point to your class instance as there is no toolbox item to drop for an inherited class. ;)
Re: [2008] Create my own textbox
Quote:
Originally Posted by RobDog888
But remember that by only using a class that inherits the textbox you wil have to manually add a regular textbox control to your for and then modify the designer code to point to your class instance as there is no toolbox item to drop for an inherited class. ;)
It appears in the toolbox if you just build your project doesnt i? It does for me :eek: Unless I'm confusing myself right now:D
Re: [2008] Create my own textbox
Oops, needed to hit Build
Bad Robdog! * SLAP * :cry:
I was just working with 2003 which doesnt do that for you. :D
Re: [2008] Create my own textbox
ok it works...
All my new properties are under "Misc" category is there a code to change this?
Re: [2008] Create my own textbox
There should be a Category attribute that you can add to the property that will place it where it needs to be:
<Category("General")> _
public property X () ...
I'm not sure if it needs to be a category that already exists and you have to do something else to add new ones or if it creates a new category if the one that's listed there doesn't already exist.
Re: [2008] Create my own textbox
and also but not very important... how can I change the icon for my class... I don't like that wheel
Re: [2008] Create my own textbox
Quote:
Originally Posted by mnavas
and also but not very important... how can I change the icon for my class... I don't like that wheel
Use the ToolBoxBitmap attribute.
If you have a 16x16 bitmap you want to use:
VB.Net Code:
<ToolboxBitmap("c:\someFile.bmp")> _
Public Class Class1
End Class
If you want to use the bitmap of an existing control:
VB.Net Code:
<ToolboxBitmap(GetType(TextBox))> _
Public Class Class1
End Class
Re: [2008] Create my own textbox
Its a gear :D
If you link a file on your system, it will get compiled into the exe as a internal resource so distributing the image file is not an issue. ;)
Re: [2008] Create my own textbox
Am I missing something? Do I need to import something?
I got this error
type 'toolboxbitmap' is not defined
Re: [2008] Create my own textbox
You shouldnt have to. Its in the System.Drawing class just in case.