Google
 
Web itpro-blogger.blogspot.com
火曜日, 2月 03, 2009

[VB2005]数値入力用のテキストボックス・コンボボックス

▼質問
数値入力専用のテキストボックスとコンボボックスを作成したいんだ。

どうしたらできるか教えてくれ!

▼回答
次のコードを参考にしてくれ!!

カスタムテキストボックスとコンボボックスだ。



Option Strict On
Option Explicit On

Public Class CustomTextBox
Inherits System.Windows.Forms.TextBox

'''
''' System.Windows.Forms.TextBox.KeyPress イベントで発生します.
'''

''' コントロールオブジェクト.
''' EventArgsクラス.
Private Sub CustomTextBox_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles Me.KeyPress
If (Asc(e.KeyChar) = System.Windows.Forms.Keys.Back) Then Exit Sub
'数値キーをチェックする.
If (Not e.KeyChar Like "[0-9]") Then e.KeyChar = CChar("")
End Sub

End Class


Option Strict On
Option Explicit On

Public Class CustomComboBox
Inherits System.Windows.Forms.ComboBox

'''
''' System.Windows.Forms.TextBox.KeyPress イベントで発生します.
'''

''' コントロールオブジェクト.
''' EventArgsクラス.
Private Sub CustomTextBox_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles Me.KeyPress
If (Asc(e.KeyChar) = System.Windows.Forms.Keys.Back) Then Exit Sub
'数値キーをチェックする.
If (Not e.KeyChar Like "[0-9]") Then e.KeyChar = CChar("")
End Sub

End Class








Comments: コメントを投稿

<< Home

This page is powered by Blogger. Isn't yours?