Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 17th, 2005, 09:35 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old July 17th, 2005, 09:51 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: India.
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


Reply With Quote
  #3 (permalink)  
Old July 17th, 2005, 08:30 PM
Registered User
 
Join Date: Jul 2005
Location: , , .
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:17 PM.


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