Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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 April 22nd, 2005, 05:12 AM
Fia Fia is offline
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create NumericTextbox

Down below is code for creating a control, NumericTextbox
Public Class NumericTextbox
    Inherits System.Windows.Forms.TextBox
    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
            Case 45 'minus tecken
                If InStr(Me.Text, "-") <> 0 Then
                    KeyAscii = 0
                End If
            Case 46 'punkt
                If InStr(Me.Text, ".") <> 0 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
End Class

which only allow users to enter digits, not characters. The code is from the book Professional VB.NET.

But if I use this control on a form and uses the control NumericTextbox:s event KeyPress like this

Private Sub NumericTextbox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles NumericTextbox1.KeyPress
    Me.NumericTextbox1.Text = e.KeyChar
End Sub

you can put characters in the textbox. The KeyPress event shouldn't be
available in the left-hand drop-down box for the NumericTextbox1, since we have used the KeyPress event for our control to make it just allow digits, not characters. Is there a way to remove the KeyPress event from the left-hand drop-down box for the NumericTextbox, so the users of the control NumericTextbox can't use the KeyPress event or is there another way to make the KeyPress event unavailable for users of the NumricTextbox???

Please Help

Fia



 
Old April 22nd, 2005, 10:35 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

What is “the left-hand drop-down box for the NumericTextbox1” and “the left-hand drop-down box for the NumericTextbox”?

It would be interesting to know the order in which these KeyPress events are handled. I suspect that both the textbox contained in the control that you have built, and the instance of that control in your program both get a shot at the key press (though I would have thought that the e.Handled = True would have warded off the instance’s opportunity to handle it).

Have you tried
Code:
     . . .
    If KeyAscii = 0 Then
        e.KeyChar = 0    ' Eliminate the value upon which to opperate.
        e.Handled = True
    Else
        e.Handled = False
    End If
 
Old April 22nd, 2005, 12:36 PM
Fia Fia is offline
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The left-hand drop-down box for the NumericTextbox or the NumericTextbox1 is the same. When I tried to use e.KeyChar = 0, I got an error and it said that property KeyChar is ReadOnly.

Fia

 
Old April 25th, 2005, 10:01 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

What do you mean by “The left-hand drop-down box for the NumericTextbox”?
Textboxes do not have drop-down anythings!
Have you added a special button beside the textbox to show a list box?
Are you using combo boxes, but mistakenly calling them textboxes?
Plus, drop-down buttons are on the right.

I am asking for clarification on what you mean by “the left-hand drop-down box” for [u]whatever</u>. What is a left-hand drop-down—as a [u]class</u> of thing?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create generic XSL Template to create table Venkatachalapathy XSLT 5 March 11th, 2008 07:49 AM
Create Application deontae45 ASP.NET 1.0 and 1.1 Basics 1 February 21st, 2007 02:04 PM
document create clinfix BOOK: Professional Ajax ISBN: 978-0-471-77778-6 3 August 8th, 2006 07:09 PM
create form kobystud C# 3 July 5th, 2004 09:13 AM
how to create a COM using VC++ iceman1188 Visual C++ 0 June 8th, 2004 12:31 AM





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