Tastiera virtuale in classe

domenica 30 settembre 2012 - 13.46
Tag Elenco Tags  VB.NET  |  .NET 4.0

massimo1965 Profilo | Junior Member

Ciao a Tutti,
ho l'esigenza di crearmi un tastierino numerico per un touch screnn.
Di esempi ce ne sono molti in rete solo che volevo crearmi una classe da richiamare più volte all'interno del progetto.
In teoria pensavo di creare un panel con dentro 10 bottoni da 0 a 9 e nella mia classe pensavo di :
passare il contenitore
aggiungere un handler per ogni bottone
che se premuto scatenasse un evento
in pratica funziona tutto, arrivo fino a raisevent ma nella form non viene intercettato nulla.
Provo a postare il codice.
Grazie


Public Class Form1

Dim WithEvents _KeyNum As New KeyNum
Public Sub InviaDato_CChar(ByVal s As String)

TextBox1.Text &= s
End Sub
Private Sub Button10_Click(sender As System.Object, e As System.EventArgs) Handles Button10.Click
_KeyNum.Init(Panel1)
End Sub

End Class

Public Class KeyNum
Public Event InviaDato_CChar(ByVal s As String)
Dim _Panel As Panel
Sub Init(ByRef _Pannel As Control)
Dim _Control As Control
For Each _Control In _Pannel.Controls
If TypeOf _Control Is Button Then
Dim _Button As Button = CType(_Control, Button)
AddHandler _Button.Click, AddressOf AddHandrer_InviaDato
End If
Next
End Sub
Sub AddHandrer_InviaDato(ByVal sender As System.Object, ByVal e As System.EventArgs)
Try
Dim Mybutton As Button = CType(sender, Button)
Dim s As String = Mybutton.Text
RaiseEvent InviaDato_CChar(s)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class

Vinsent Profilo | Senior Member

Non viene intercettato nulla perchè richiami '_KeyNum.Init' alla pressione di un button, AMMESSO che sia un button del tastierino, e l' AddHandler avviene DOPO il click quindi l' evento viene aggiunto dopo che si è verificato.
Inoltre in 'InviaDato_CChar' manca l' 'Handles'.
Così dovrebbe funzionare:
Public Class Form1 Dim WithEvents _KeyNum As New KeyNum Sub New() InitializeComponent() _KeyNum.Init(Panel1) End Sub Public Sub InviaDato_CChar(ByVal s As String) Handles _KeyNum.InviaDato_CChar TextBox1.Text &= s End Sub End Class

ciao

PS: quando posti del codice puoi formattarlo con il tag apposito? diventa più leggibile....

massimo1965 Profilo | Junior Member

Vincent
ero andato in oca, per non dire altro.....
E si che guardavo un altro progetto simile e non vedevo perchè funzionava.
Mai lavorare di domenica.

Grazie ancora.
M

Vinsent Profilo | Senior Member

>Vincent
con la "s"...della serie "parla come mangi"

>Grazie ancora.
Di niente!

ciao!
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5