Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 17th, 2005, 09:35 AM
Registered User
 
Join Date: Jul 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to lok_tan
Default Textbox custom control

Hai All,

is there anybody here who have experience with developing custom controls? especially the textbox control.

The easy way is to inherit the .NET's TextBox control.

If there's any circumstance that not allowed us to inherit from that control, how we can do it?

Inherit from UserControl? or Control?

What we use to trap keyboard event? Is it suficient if we use KeyUp/KeyDown/KeyPressed?

What we use to display blinking cursor? using timer?

Thanks and regards,

Lok
 
Old July 17th, 2005, 09:51 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default

hi,

i think the follwing code will help

Ashu

'******************************************

Public Class NumericTextBox
    Inherits System.Windows.Forms.TextBox

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl1 overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'NumericTextBox
        '
        Me.AccessibleRole = System.Windows.Forms.AccessibleRole.Application
        Me.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle

    End Sub

#End Region

    Private Sub NumericTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        Dim KeyAscii As Integer

        KeyAscii = Asc(e.KeyChar)

        Select Case KeyAscii

            Case 48 To 57, 8, 13 '0-9, Backspace, Enter KEY
                'Do nothing

            Case 45 'Minus sign (-)
                If InStr(Me.Text, "-") <> 0 Then
                    KeyAscii = 0
                End If

                If Me.SelectionStart <> 0 Then
                    KeyAscii = 0
                End If

            Case 46 'Dot (.)
                If InStr(Me.Text, ".") Then
                    KeyAscii = 0
                End If

            Case Else
                KeyAscii = 0

        End Select

        If KeyAscii = 0 Then
            e.Handled = True
        Else
            e.Handled = False
        End If
    End Sub

    Private Sub NumericTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Enter
        Me.SelectionStart = 0
        Me.SelectionLength = Me.Text.Length
    End Sub

End Class


 
Old July 17th, 2005, 08:30 PM
Registered User
 
Join Date: Jul 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to lok_tan
Default

Thanks Ashu,

Unfortunately, that's not what I'm looking for.

The one that I'm looking is a custom control that directly inherit System.Windows.Forms.Control or System.Windows.Forms.UserControl, not the one who inherits from other ready-made control (in your case it inherits System.Windows.Forms.TextBox control).

I need to know what happening behind the screen to produce TextBox-like control without inheriting it.

Thanks & regards,

Lok





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Server Control....Custom Property Editor ZArrinPour ASP.NET 1.0 and 1.1 Basics 1 June 15th, 2010 11:30 AM
Web Service, Custom Control, Custom Return Type robzyc ASP.NET 2.0 Basics 6 June 10th, 2008 08:03 AM
custom control inside custom control issues StevesonD ASP.NET 2.0 Professional 1 February 19th, 2008 06:54 PM
Help! Custom Server Control using User Control diehard ASP.NET 1.0 and 1.1 Professional 2 January 4th, 2006 12:33 PM
To get each textbox control in C# JelfMaria VS.NET 2002/2003 2 June 29th, 2005 12:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.