关于一个屏幕键盘的问题?

kenways 2005-08-18 11:02:26
本在开发的程序中,要用上触摸屏幕,而设计了一个屏幕小键盘,问题是:在一个窗口的所有TEXTBOX中,不知道如何获得小键盘上的值,如果只有一个TEXTBOX那就好办,但多个TEXTBOX时不知道如何确定???
...全文
115 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
malingxian 2005-08-18
  • 打赏
  • 举报
回复
好办!你在窗体中设置一个全局变量,变量类型为Textbox类型,假设这个变量名为txtTmp。然后在每个需要输入的TextBox的GotFocus事件中加入txtTmp = ctype(sender,textbox).
然后用模拟键盘输入的时候直接针对更改txtTmp即可。
mingpingzhang 2005-08-18
  • 打赏
  • 举报
回复
不明白你的意思,按说这做一个屏幕键盘应该是很简单的。
malingxian 2005-08-18
  • 打赏
  • 举报
回复
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.Button1)
Me.GroupBox1.Controls.Add(Me.Button2)
Me.GroupBox1.Controls.Add(Me.Button3)
Me.GroupBox1.Controls.Add(Me.Button4)
Me.GroupBox1.Controls.Add(Me.Button5)
Me.GroupBox1.Controls.Add(Me.Button6)
Me.GroupBox1.Controls.Add(Me.Button7)
Me.GroupBox1.Controls.Add(Me.Button8)
Me.GroupBox1.Controls.Add(Me.Button9)
Me.GroupBox1.Controls.Add(Me.Button10)
Me.GroupBox1.Location = New System.Drawing.Point(4, 68)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(316, 100)
Me.GroupBox1.TabIndex = 1
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "键盘区"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 28)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 28)
Me.Button1.TabIndex = 0
Me.Button1.Text = "1"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(76, 28)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(48, 28)
Me.Button2.TabIndex = 0
Me.Button2.Text = "2"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(136, 28)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(48, 28)
Me.Button3.TabIndex = 0
Me.Button3.Text = "3"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(196, 28)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(48, 28)
Me.Button4.TabIndex = 0
Me.Button4.Text = "4"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(256, 28)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(48, 28)
Me.Button5.TabIndex = 0
Me.Button5.Text = "5"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(16, 68)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(48, 28)
Me.Button6.TabIndex = 0
Me.Button6.Text = "6"
'
'Button7
'
Me.Button7.Location = New System.Drawing.Point(76, 68)
Me.Button7.Name = "Button7"
Me.Button7.Size = New System.Drawing.Size(48, 28)
Me.Button7.TabIndex = 0
Me.Button7.Text = "7"
'
'Button8
'
Me.Button8.Location = New System.Drawing.Point(136, 68)
Me.Button8.Name = "Button8"
Me.Button8.Size = New System.Drawing.Size(48, 28)
Me.Button8.TabIndex = 0
Me.Button8.Text = "8"
'
'Button9
'
Me.Button9.Location = New System.Drawing.Point(196, 68)
Me.Button9.Name = "Button9"
Me.Button9.Size = New System.Drawing.Size(48, 28)
Me.Button9.TabIndex = 0
Me.Button9.Text = "9"
'
'Button10
'
Me.Button10.Location = New System.Drawing.Point(256, 68)
Me.Button10.Name = "Button10"
Me.Button10.Size = New System.Drawing.Size(48, 28)
Me.Button10.TabIndex = 0
Me.Button10.Text = "0"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(328, 173)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.TextBox5)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.Text = "Form1"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Private tt As TextBox = TextBox1

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus, TextBox4.GotFocus, TextBox5.GotFocus
tt = CType(sender, TextBox)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click
tt.Text = tt.Text & CType(sender, Button).Text
End Sub
End Class
malingxian 2005-08-18
  • 打赏
  • 举报
回复
好吧,给你下面的代码看看:
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()
MyBase.New()

'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写 dispose 以清理组件列表。
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

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Button7 As System.Windows.Forms.Button
Friend WithEvents Button8 As System.Windows.Forms.Button
Friend WithEvents Button9 As System.Windows.Forms.Button
Friend WithEvents Button10 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.Button6 = New System.Windows.Forms.Button
Me.Button7 = New System.Windows.Forms.Button
Me.Button8 = New System.Windows.Forms.Button
Me.Button9 = New System.Windows.Forms.Button
Me.Button10 = New System.Windows.Forms.Button
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(12, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(148, 21)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(164, 8)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(148, 21)
Me.TextBox2.TabIndex = 0
Me.TextBox2.Text = ""
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(12, 36)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(148, 21)
Me.TextBox4.TabIndex = 0
Me.TextBox4.Text = ""
'
'TextBox5
'
Me.TextBox5.Location = New System.Drawing.Point(164, 36)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.Size = New System.Drawing.Size(148, 21)
Me.TextBox5.TabIndex = 0
Me.TextBox5.Text = ""
malingxian 2005-08-18
  • 打赏
  • 举报
回复
好吧,给你下面的代码看看:
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()
MyBase.New()

'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写 dispose 以清理组件列表。
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

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Button7 As System.Windows.Forms.Button
Friend WithEvents Button8 As System.Windows.Forms.Button
Friend WithEvents Button9 As System.Windows.Forms.Button
Friend WithEvents Button10 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.Button6 = New System.Windows.Forms.Button
Me.Button7 = New System.Windows.Forms.Button
Me.Button8 = New System.Windows.Forms.Button
Me.Button9 = New System.Windows.Forms.Button
Me.Button10 = New System.Windows.Forms.Button
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(12, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(148, 21)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(164, 8)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(148, 21)
Me.TextBox2.TabIndex = 0
Me.TextBox2.Text = ""
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(12, 36)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(148, 21)
Me.TextBox4.TabIndex = 0
Me.TextBox4.Text = ""
'
'TextBox5
'
Me.TextBox5.Location = New System.Drawing.Point(164, 36)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.Size = New System.Drawing.Size(148, 21)
Me.TextBox5.TabIndex = 0
Me.TextBox5.Text = ""
kenways 2005-08-18
  • 打赏
  • 举报
回复
加变量和用GotFocus事件之前已经试过了,存在的问题是这样的:
(1)当按中屏幕上的小键盘区时,焦点已经去了键盘区所按的BUTTON上,不能触发GOTFOCUS,当按完键盘后再按TEXTBOX时才能显示刚才所按的值
(2)当存在多个TEXTBOX时,其他TEXTBOX发生GOTFOCUS时,所显示的值是之前哪个所按的键盘值.
问题2就好办,只需把变量="",但问题(1)不知怎样解决!!!
因为每个FORM都有用到小键盘,所以我已把小键盘做成了自定义的用户控件

望各位大哥提供建议

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧