|
|
IN-VESTI DNW!!! Sono finalmente arrivate le nuovissime T-Shirt di DotNetWork!!! Con soli 15,00 € ci sosterrai nelle spese di gestione della Community e ti invieremo a casa una splendida maglietta. Se vuoi contribuire al mantenimento di DotNetWork.it Vai sulla pagina Iscrizioni Effettua il pagamento usando IWBank Oppure un Bonifico bancario (le coordinate sono sulla pagina Iscrizioni), inviaci una mail a support@dotnetwork.it indicandoci la tua taglia e l'indirizzo di spedizione. Non appena verificata la ricezione del pagamento provvederemo a spedirti la tua T-Shirt. Le magliette sono disponibili nelle taglie S-M-L-XL-XXL (in caso di esaurimento di una delle taglie, indica quella di "Backup"). Grazie per IN-VESTIRTI con NOI!!! .:DotNetWork Founders:.
|
|
|
|
|
cambiare a runtime un carattere in un TxtBox
Ultimo Post 23 feb 2009 21.59 by Panatronic. 6 Risposte.
|
Ordina:
|
 Posts:537
 |
| 23 feb 2009 17.39 |
|
Buonasera a tutti.
Mentre si digita un prezzo in un TxTBox, dovrei intercettare il carattere "." e il carattere "," e sostituirli con uno che ho in una variabile....
Come posso fare questo? |
|
|
|
|
 Posts:94
 |
| 23 feb 2009 17.48 |
|
ti consiglio di lavorare sull'evento keydown del controllo, puoi sapere che carattere è stato premuto e poi con il metodo replace delle stringe sotituire quelli che non vuoi.
|
|
|
|
|
 Posts:537
 |
| 23 feb 2009 18.40 |
|
ho lavorato sull'evento KeyPress con questo codice: If e.KeyChar = Char.ConvertFromUtf32(46) Then TxtPrezzoAcquisto.Text = TxtPrezzoAcquisto.Text.ToString.Replace(".", separatoreDecimale) ElseIf e.KeyChar = Char.ConvertFromUtf32(44) Then TxtPrezzoAcquisto.Text = TxtPrezzoAcquisto.Text.ToString.Replace(",", separatoreDecimale) End If ma non funziona. In poche parlo se scrivo 125.25 rimane 125.25 e basta fare un secondo punto (.) e mi riscrive .125,25 nella variabile separatoreDecimale c'è il valore ",". GRazie |
|
|
|
|
 Posts:662
 |
| 23 feb 2009 20.03 |
|
ma non funziona. In poche parlo se scrivo 125.25 rimane 125.25 e basta fare un secondo punto (.) e mi riscrive .125,25 nella variabile separatoreDecimale c'è il valore ",". Nell'evento KeyPress della text box metti questo codice: If e.KeyChar = "," Or e.KeyChar = "." Then If Me.Text.IndexOf(",") > 0 Then e.Handled = True Exit Sub Else If e.KeyChar = "." Then Me.AppendText(",") e.Handled = True Exit Sub End If If e.KeyChar = "," Then e.Handled = False Exit Sub End If End If End If e.Handled = Not Char.IsNumber(e.KeyChar) |
|
|
|
|
 Posts:537
 |
| 23 feb 2009 21.24 |
|
Grazie Alberto. Non la prendere a male...ho apportato alcune modifiche: dato che ho messo in una variabile il carattere usato nel sistema: Dim culture As System.Globalization.CultureInfo Public separatoreDecimale As String culture = System.Threading.Thread.CurrentThread.CurrentCultu re separatoreDecimale = culture.NumberFormat.NumberDecimalSeparator Ho modificato in questo modo il codice di Alberto... If e.KeyChar = "," Or e.KeyChar = "." Then If TxtPrezzoPubblico.Text.IndexOf(separatoreDecimale) > 0 Then e.Handled = True Exit Sub Else If e.KeyChar = "." Or e.KeyChar = "." Then TxtPrezzoPubblico.AppendText(separatoreDecimale) e.Handled = True Exit Sub End If End If End If e.Handled = Not Char.IsNumber(e.KeyChar) In questo modo se in un PC c'è configurato il punto come separatore decimale, viene impostato bene comuque (lo spero). Altro problema superabile per ora con i tasti freccia e il tasto Canc, è che non va il tasto BackSpace. Sicuramente perchè con l'ultima riga,vengono accettati solo caratteri numeri... Grazie mille a tutti.
|
|
|
|
|
 Posts:537
 |
| 23 feb 2009 21.45 |
|
Questa sera sono in vena di esperimenti. Ho fatto questa funzione in una DLL base (vedere articoli di Sabrina): Private Sub ImpostaValuta(ByVal TxtBox As TextBox, ByVal Carattere As System.Windows.Forms.KeyPressEventArgs, ByVal UsaTabInvio As Boolean) If Carattere.KeyChar = "," Or Carattere.KeyChar = "." Then If TxtBox.Text.IndexOf(separatoreDecimale) > 0 Then Carattere.Handled = True Exit Sub Else If Carattere.KeyChar = "." Or Carattere.KeyChar = "." Then TxtBox.AppendText(separatoreDecimale) Carattere.Handled = True Exit Sub End If End If ElseIf UsaTabInvio = True And Carattere.KeyChar = Char.ConvertFromUtf32(13) Then TxtPrezzoAcquisto.Focus() End If End Sub ora nei TxtBox per i quali voglio questa funzione ci scrivo solo: ImpostaValuta(DirectCast(sender, TextBox), e, True) Devo solo aggiungere qualcosa per generare il tasto Tab al posto dell'Invio... Lo so, non centra nulla la parte " TxtPrezzoAcquisto.Focus()" ma dovevo provare se andava...mettendo la funzione del Form dove la stavo provando.... Da questo si vede che le lezioni di Alberto e Sabrina sono servite a qualcosa. Grazie mille.
|
|
|
|
|
 Posts:537
 |
| 23 feb 2009 21.59 |
|
Ecco la funzione giusta: Private Sub ImpostaValuta(ByVal TxtBox As TextBox, ByVal Carattere As System.Windows.Forms.KeyPressEventArgs, ByVal UsaTabInvio As Boolean) If Carattere.KeyChar = "," Or Carattere.KeyChar = "." Then If TxtBox.Text.IndexOf(separatoreDecimale) > 0 Then Carattere.Handled = True Exit Sub Else If Carattere.KeyChar = "." Or Carattere.KeyChar = "." Then TxtBox.AppendText(separatoreDecimale) Carattere.Handled = True Exit Sub End If End If ElseIf UsaTabInvio = True And Carattere.KeyChar = Char.ConvertFromUtf32(13) Then SendKeys.Send("{TAB}") 'SendKeys.Send(vbTab) End If End Sub La parte che ho commentato è la versione della pressione del tasto Tab con la DLL Microsoft.VisualBasic che io ormai ho deciso di abbandonare...per vari motivi. Grazie a tutti e spero che vi possa essere utile questa mia funzione.
|
|
|
|
|
| Non sei autorizzato ad inviare una risposta. |
|
Active Forums 4.1
|
|
|
|
|
|
|
|
|
|
|
Icone e Toolstrip |
 |
Icone della giusta dimensione e Toolstrip modificate a runtime |
 |
|
2009/06/28 | Autore: Sabrina Cosolo
|
|
|
|
|
|
|
|
|
|
|
|