custom controls not working with toolbox.

dluxoh

New member
Joined
Oct 21, 2008
Messages
4
Programming Experience
1-3
Hello I'm using VB.Net Express 2008 to write a program and want to make a custom control that inherits the TextBox class. I've done so successfully to a degree, but whats happening now is very frustrating.

I can successfully instanciate my new textbox using the following code in my main form:

VB.NET:
Public Class SignBuilderForm
    Dim test As FormattedTextbox
    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        test = New FormattedTextbox
        test.Enabled = True
        test.Visible = True
        test.Parent = GroupBox1
        test.Width = 50

        ' Add any initialization after the InitializeComponent() call.

    End Sub
End Class

However, if I try to drag my component onto the form from the toolbox using the designer, I get errors once I save the project or try to build it.

VB.NET:
Error    1    Type 'SignBuilderForm.FormattedTextbox' is not defined.
  C:\Documents and Settings\Administrator\Desktop\Gregs Projects\VBApps\SignBuilderForm\SignBuilderForm\SignBuilderForm.Designer.vb
  32    36    SignBuilderForm
Error    2    Type 'SignBuilderForm.FormattedTextbox' is not defined.
  C:\Documents and Settings\Administrator\Desktop\Gregs Projects\VBApps\SignBuilderForm\SignBuilderForm\SignBuilderForm.Designer.vb
  134    44    SignBuilderForm


Am I mistaken or is visual studio express supposed to allow you to use the designer to place your user created controls onto your project? What am I doing incorrectly here?

Thanks

P.S. I appologize for the repost, I feel that my problem is much better worded on this post. I tried to delete my previous thread but it looks like thats not an option ont his forum.
 
What I do is I make the control, then I compile the project (run it) and after that it shows up in the toolbox, drop it on the form and there ya go.
 
I've added System.Windows.Forms to my resources. I don't get an error now, but I do get a warning:
VB.NET:
Warning	1	Namespace or type specified in the project-level 
Imports 'FormattedTextBox' doesn't contain any public member or cannot be 
found. Make sure the namespace or the type is defined and contains at least 
one public member. Make sure the imported element name doesn't use any 
aliases.	SignFormBuilder

Of course warnings are never good to have either... once again, any useful information would be appreciated.
What I do is I make the control, then I compile the project (run it) and after that it shows up in the toolbox, drop it on the form and there ya go.

I am following those exact same steps, only I get an error :( this makes no sense to me and is very frustrating.
 
Well you're not using the same steps, you've added this level of complexity:
VB.NET:
Public Class SignBuilderForm
    Dim test As FormattedTextbox
    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        test = New FormattedTextbox
        test.Enabled = True
        test.Visible = True
        test.Parent = GroupBox1
        test.Width = 50

        ' Add any initialization after the InitializeComponent() call.

    End Sub
End Class
Which I don't know what you're doing here, so I can't tell you what's wrong.
 
Well the point that I was trying to get across is that if I create a custom control, and drag it from the toolbox onto my form, I get errors and all sorts of mess.

However, if I manually create an instance of my custom control (the code shown), I don't get any errors at all.... I do not have any intention of using that code, it was an example of what is working vs what isn't working.

Should I reinstall my IDE? It has to be something I'm doing incorrectly.
 
I've had similar problems with this before, post your custom control code here, I'm willing to bet it has something to do with a property you're overriding.

Also if you posted the error message, that'll help narrow down the problem too.
 
All that information is in my first post... I'll start over. New project, and a fresh class that inherits textbox.

here's my class:
VB.NET:
Public Class MySpecialTextBox : Inherits TextBox
End Class
Next I build the project.
So far so good.
Now I drag my new component from the toolbox to the form. I see a textbox on the form...
now I build. . . and it works... strange... I don't know what I did differently this time asside from choosing a different name for my component... oh well I guess I'll never know :p
 
All that information is in my first post... I'll start over. New project, and a fresh class that inherits textbox.

here's my class:
VB.NET:
Public Class MySpecialTextBox : Inherits TextBox
End Class
Next I build the project.
So far so good.
Now I drag my new component from the toolbox to the form. I see a textbox on the form...
now I build. . . and it works... strange... I don't know what I did differently this time asside from choosing a different name for my component... oh well I guess I'll never know :p
You have an inconsistency going here. In your first post the only custom control code you posted was this line:
VB.NET:
    Dim test As FormattedTextbox
Which doesn't show any of the actual control's code. It doesn't provide any information as to why you're getting an error at all.

Now in the most recent of your posts you have a custom control named 'FormattedTextbox' which isn't 'MySpecialTextBox'. What's actually going on?
 
Back
Top