Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Sokol cu distorsiuni de cross-over

Filtru apa potabila cu osmoza inv...

Kanal D va difuza serialul “...

Upgrade xiaomi mi11
 securitate - acum se dau drept - ...

Farmacia Dr Max - Pareri / Sugest...

De unde cumparati suspensii / gar...

[UNDE] Reconditionare obiecte lemn
 Infiltratii casa noua

sugestie usa interior

ANAF si plata la selfpay

Imprimanta ciss rezista perioade ...
 Garmin fēnix 7 / PRO / Saphi...

Care sunt cele mai mari regrete a...

Alfa Romeo Stelvio 2.2 jtd

Intrebari srl nou
 

[VB] Scrierea in caseta text selectata

- - - - -
  • Please log in to reply
5 replies to this topic

#1
BASIL

BASIL

    Junior Member

  • Grup: Members
  • Posts: 80
  • Înscris: 20.05.2005
Buna ziua,
Am nevoie de un programel in Visual Basic 2010 care sa scrie in caseta RichText selectata  cifre, imaginea este pentru un Touchscreen, astfel incit dupa ce  atingi casuta dorita sa poti scire cifrele  de la 1 la 100  de pe  tastatura  din imagine.
Ma intereseaza. daca se poate, doar  cum pot sa folosesc acele butoane  in locul tastaturii calculatorului.

Attached Files



#2
red46

red46

    Senior Member

  • Grup: Senior Members
  • Posts: 4,556
  • Înscris: 06.03.2016
Uite aici un exemplu.

Attached Files


Edited by red46, 25 September 2016 - 16:24.


#3
dani.user

dani.user

    Guru Member

  • Grup: Senior Members
  • Posts: 30,235
  • Înscris: 24.02.2007
Trebuie sa tii minte pe ce casuta text a fost ultima data pentru a stii pe care s-o modifici cand apesi butonul.

TextBox iti ajunge, RichText e pentru texte complexe gen ce scrii in Word, nu pentru cifre.

Public Class Form1

   Dim _lastSelectedTextBox as TextBox

   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

	  For i = 1 To 4

		 Dim textBox = new TextBox
		 textBox.Height = 20
		 textBox.Top = 50 + i * (10 + textBox.Height)
		 textBox.Left = 50
		 textBox.Width = 100
		 textBox.Text = "0"
		 Controls.Add(textBox)

		 AddHandler textBox.GotFocus, AddressOf TextBox_onfocus
		 AddHandler textBox.KeyPress, AddressOf TextBox_KeyPress

		 If _lastSelectedTextBox is Nothing Then
			_lastSelectedTextBox = textBox
		 End If

		 Dim label = new Label
		 label.Text = "%"
		 label.Top = textBox.Top
		 label.Left = textBox.Left + textBox.Width + "10"

		 Controls.Add(label)
	  Next

	  Dim x = 0, y = 3
	  For i = 0 To 9
		 Dim button = New Button
		 button.Text = i.ToString()
		 button.Tag = i
		 button.Width = 40
		 button.Height = 40
		 button.Left = 300 + x * (button.Width + 10) 
		 button.Top = 50 + y * (button.Height + 10)

		 AddHandler button.Click, AddressOf Digit_Click

		 x = (x + 1) Mod 3
		 If x = 0 Or y = 3 Then
			y -= 1
			x = 0
		 End If

		 controls.Add(button)
	  Next

   End Sub

   Private Sub TextBox_KeyPress(sender As Object, e As KeyPressEventArgs)
	  If Not Char.IsDigit(e.KeyChar) And not char.IsControl(e.KeyChar) Then
		 e.Handled = true
	  End If
   End Sub

   Private Sub Digit_Click(sender As Object, e As EventArgs)
	  Dim digit = Convert.ToInt32(CType(sender, Button).Tag)
	  Dim currentValue = Convert.ToInt32(Iif(String.IsNullOrWhiteSpace(_lastSelectedTextBox.Text), "0", _lastSelectedTextBox.Text))
	  currentValue = currentValue * 10 + digit
	  If currentValue <= 100 Then
		 _lastSelectedTextBox.Text = currentValue.ToString()
	  End If
   End Sub

   Private Sub TextBox_onfocus(sender As Object, e As EventArgs)
	  _lastSelectedTextBox = Ctype(sender, TextBox)
   End Sub
End Class




#4
BASIL

BASIL

    Junior Member

  • Grup: Members
  • Posts: 80
  • Înscris: 20.05.2005
Draga Dani  Solutia ta functioneaza foarte bine .
Multumesc .
Sunt la inceput cu Visual Basic-ul. De aceea te rog sa nu te superi daca
unele inrebari sau cerinte ale mele  sunt "puerile"
Dupa ce sunt scrise, nu pot sa mai modific numerele.
Cum as putea sa fac ca   sa apara in Form Desing  Ca sa pot  modifica locul Marimea  si pozitia
Pe Touchscreen sunt mai greu de nimerit asa mici
Multumesc

#5
BASIL

BASIL

    Junior Member

  • Grup: Members
  • Posts: 80
  • Înscris: 20.05.2005
Multumesc si lui Red 46 pentru informatie.
Scrisul in mai multe casete este esential si cred ca modifica  total constructia programului.

#6
BASIL

BASIL

    Junior Member

  • Grup: Members
  • Posts: 80
  • Înscris: 20.05.2005
Am incercat asa ceva azi noapte si nu merge
Public Class Form1
	Dim Cifra As String
	Dim Valid(4) As Boolean
	Dim textBoxes() As TextBox = {TextBox1, TextBox2, TextBox3, TextBox4}

	Private Sub Decide(ByVal Valoare As String)
		For i = 1 To 4
			If Valid(i) = True Then
				textBoxes(i).Text = Valoare
			End If
			REM TextBox1.Text += Valoare
		Next
	End Sub
	Private Sub Validare(ByVal NrCaseta As Integer)
		For i = 1 To 4
			Valid(i) = False
			Valid(NrCaseta) = True
		Next
	End Sub
	Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox1.Click
		Validare(1)
	End Sub
	Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged, TextBox2.Click
		Validare(2)
	End Sub
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Cifra = "1"
		Decide(Cifra)
	End Sub
	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		Cifra = "2"
		Decide(Cifra)
	End Sub
	Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
		Validare(3)
	End Sub
	Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
		Validare(4)
	End Sub
End Class

Attached Files


Edited by MarianG, 04 May 2017 - 22:20.
tag-uri code


Anunturi

Bun venit pe Forumul Softpedia!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate