Usuário com melhor resposta
Deslocar imagem via textbox

Pergunta
-
Bom dia gente...como descolar imagem com base em valores digitados em duas textbox (X, Y) o código abaixo desloca a imagem
somente em uma posição...
Dim bottomValue As Integer = PictureBox1.Top + PictureBox1.Height
PictureBox1.Location = New Point(PictureBox1.Location.X + 20, PictureBox1.Location.Y + 5)
Obrigado...
Respostas
-
Boa noite.
O exemplo que dei foi usando o timer e com valores prefixados.
Se te ajudou, marque como resposta.
Para usar textboxes seria mais ou menos assim:
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Width = 650
Me.Height = 520
PictureBox1.Image = Image.FromFile("C:\Users\Mariano\Desktop\Projetos\ProfileImage.jpg")
PictureBox1.Width = 90
PictureBox1.Height = 120
PictureBox1.Top = 0
PictureBox1.Left = 0
Timer1.Interval = 10000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If TextBox1.Text = "" Or TextBox2.Text = "" Then MsgBox("preencha o textbox1 com valores entre 0 e 540 e textbox2 com valores entre 0 e 360")
If CInt(TextBox1.Text) > 360 Or CInt(TextBox2.Text) > 540 Then MsgBox("preencha o textbox1 com valores entre 0 e 540 e textbox2 com valores entre 0 e 360")
PictureBox1.Top = CInt(TextBox1.Text)
PictureBox1.Left = CInt(TextBox2.Text)
End Sub
Private Sub TextBox__KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress, TextBox2.KeyPress
'aceita somente números nos textboxes
If Not IsNumeric(e.KeyChar) And e.KeyChar <> Chr(8) Then
e.KeyChar = Chr(0)
e.Handled = True
End If
End SubMARIANO1776
- Marcado como Resposta Flavio1957 terça-feira, 8 de dezembro de 2020 16:39
Todas as Respostas
-
-
-
Tente assim:
Se te ajudou, marque como resposta.
Public Class Form2
Dim Hpos As Integer = 0
Dim Wpos As Integer = 0
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Width = 650
Me.Height = 520
PictureBox1.Image = Image.FromFile("C:\Users\Mariano\Desktop\Projetos\ProfileImage.jpg")
PictureBox1.Width = 90
PictureBox1.Height = 120
PictureBox1.Top = 0
PictureBox1.Left = 0
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
PictureBox1.Left += 90
If PictureBox1.Left = 630 Then
PictureBox1.Left = 0
PictureBox1.Top += 120
If PictureBox1.Top = 480 Then PictureBox1.Top = 0
End If
End Sub
End ClassMARIANO1776
-
-
Boa noite.
O exemplo que dei foi usando o timer e com valores prefixados.
Se te ajudou, marque como resposta.
Para usar textboxes seria mais ou menos assim:
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Width = 650
Me.Height = 520
PictureBox1.Image = Image.FromFile("C:\Users\Mariano\Desktop\Projetos\ProfileImage.jpg")
PictureBox1.Width = 90
PictureBox1.Height = 120
PictureBox1.Top = 0
PictureBox1.Left = 0
Timer1.Interval = 10000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If TextBox1.Text = "" Or TextBox2.Text = "" Then MsgBox("preencha o textbox1 com valores entre 0 e 540 e textbox2 com valores entre 0 e 360")
If CInt(TextBox1.Text) > 360 Or CInt(TextBox2.Text) > 540 Then MsgBox("preencha o textbox1 com valores entre 0 e 540 e textbox2 com valores entre 0 e 360")
PictureBox1.Top = CInt(TextBox1.Text)
PictureBox1.Left = CInt(TextBox2.Text)
End Sub
Private Sub TextBox__KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress, TextBox2.KeyPress
'aceita somente números nos textboxes
If Not IsNumeric(e.KeyChar) And e.KeyChar <> Chr(8) Then
e.KeyChar = Chr(0)
e.Handled = True
End If
End SubMARIANO1776
- Marcado como Resposta Flavio1957 terça-feira, 8 de dezembro de 2020 16:39
-