Inherits System.Windows.Forms.Control..
Author Message
 Inherits System.Windows.Forms.Control...

I'm trying to create a new control from scratch using code only.  Just to
start small, I'd like to duplicate a textbox (it's pointless except as an
exercise).  I have this declaration:

Public Class myControl
    Inherits System.Windows.Forms.Control

    Private myText as System.Windows.Forms.TextBox

    Public Sub New()
        MyBase.New()
        myText=new System.Windows.Forms.TextBox
        myText.Visible=True
    End Sub
End Class

However, upon startup, the textbox will 'flicker' into and out of existence
once, then it is just gone...  My implementation is like this:

Module Module 1
    Public frmMain as New System.Windows.Forms.Form()
    Public myControl as New myControl()

    Public Sub Main()
        frmMain.Controls.Add(myControl)
        System.Windows.Forms.Application.Run(frmMain)
    End Sub
End Module

Any help on keeping my control alive would be helpful... thanks! =)

Joseph Hicks
Salt Lake City



Fri, 29 Oct 2004 23:41:40 GMT  
 Inherits System.Windows.Forms.Control...

Quote:

> Public Class myControl
>     Inherits System.Windows.Forms.Control

Better try:

Public Class myControl
    Inherits System.Windows.Forms.Textbox

Your Usercontrol is now a Textbox with all the properties.

Marc



Sat, 30 Oct 2004 01:46:14 GMT  
 Inherits System.Windows.Forms.Control...
Yes, I know this, but eventually it will contain arrays of multiple control
types.  I just want to start small and work my way up to more complex
objects.


Quote:

> > Public Class myControl
> >     Inherits System.Windows.Forms.Control

> Better try:

> Public Class myControl
>     Inherits System.Windows.Forms.Textbox

> Your Usercontrol is now a Textbox with all the properties.

> Marc



Sat, 30 Oct 2004 02:06:10 GMT  
 Inherits System.Windows.Forms.Control...


Quote:
> I'm trying to create a new control from scratch using code only.  Just to
> start small, I'd like to duplicate a textbox (it's pointless except as an
> exercise).  I have this declaration:

> Public Class myControl
>     Inherits System.Windows.Forms.Control

>     Private myText as System.Windows.Forms.TextBox

>     Public Sub New()
>         MyBase.New()
>         myText=new System.Windows.Forms.TextBox
>         myText.Visible=True
>     End Sub
> End Class

> However, upon startup, the textbox will 'flicker' into and out of
existence
> once, then it is just gone...  My implementation is like this:

> Module Module 1
>     Public frmMain as New System.Windows.Forms.Form()
>     Public myControl as New myControl()

>     Public Sub Main()
>         frmMain.Controls.Add(myControl)
>         System.Windows.Forms.Application.Run(frmMain)
>     End Sub
> End Module

> Any help on keeping my control alive would be helpful... thanks! =)

> Joseph Hicks
> Salt Lake City

You forget to add the textbox to the user control.

Change the user control as follows:

Public Sub New()
    MyBase.New()
    InitializeComponent()
    myText = New TextBox()
    'set properties like size, location etc here
    Me.Controls.Add(myText) 'add textbox to usercontrol
End Sub

And inherit from user control, i.e.:
    Inherits System.Windows.Forms.UserControl

You might want to check out:
http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsCreating...
s.aspx#Adding%20Properties,%20Events%20and%20MetaData

It's a good start when beginning to build your own user controls.



Sat, 30 Oct 2004 02:05:03 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. howto Inherits System.Windows.Forms.TextBoxbase

2. Error in System.Windows.Forms.Form.UpdateLayered()

3. When to Inherit System.ComponentModel.Component?

4. Inherits System.Collections.CollectionBase

5. Inheriting System.ComponentModel.Component

6. System.Windows.Forms.RichTextBox.SelectionFont.Size

7. System.Windows.Forms.RichTextBox.SelectionFont.Size

8. System.Windows.Forms.Application.Exit()

9. custom form control: Cannot view design view of forms that inherit this form

10. Excel 2000, Windows XP, System.Runtime.InteropServices.COMException

11. System.Windows.ControlPaint.DrawMenuGlyph

12. Solution for Setting the Windows-NT-System-Default-Printer (without any dialog)

 

 
Powered by phpBB® Forum Software