Move Controls .Net
This is a demo project on how to move controls on windows form . I have introduced it using vb.net . To move controls on windows form it requires to deal with x-coordinate and y-coordinate of that controls . X-cordinate tell the control distance from x-axis origin point and y-coordinate tells the distance from y-axis origin.
MOVE Controls on windows form .NET
So to move the control on .NET we will increment the x-coordinate and y-coordinate of that control according to how much distance we want to move the controls and also according to which direction you want to move the control
Design :-
Code:Code For Move Controls .NET Project Public Class Form1 //For "->" to move Right Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = Val(TextBox1.Text) + 10 Dim x_intercept = Val(TextBox1.Text) If ComboBox1.SelectedIndex = 0 Then If Not TextBox1.Text = "" Then PictureBox1.Location = New Point(x_intercept) End If End If If ComboBox1.SelectedIndex = 1 Then If Not TextBox1.Text = "" Then Label4.Location = New Point(x_intercept) End If End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox1.Text = PictureBox1.Location.X TextBox2.Text = PictureBox1.Location.Y End Sub //For "Up" to move Up Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox2.Text = Val(TextBox2.Text) + 10 Dim y_intercept = Val(TextBox2.Text) Dim x_intercept = Val(TextBox1.Text) If ComboBox1.SelectedIndex = 0 Then If Not TextBox2.Text = "" Then PictureBox1.Location = New Point(x_intercept, y_intercept) End If End If If ComboBox1.SelectedIndex = 1 Then If Not TextBox2.Text = "" Then Label4.Location = New Point(x_intercept, y_intercept) End If End If End Sub //For "<-" to move Towards left Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox1.Text = Val(TextBox1.Text) - 10 Dim x_intercept = Val(TextBox1.Text) If ComboBox1.SelectedIndex = 0 Then If Not TextBox1.Text = "" Then PictureBox1.Location = New Point(x_intercept) End If End If If ComboBox1.SelectedIndex = 1 Then If Not TextBox1.Text = "" Then Label4.Location = New Point(x_intercept) End If End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click TextBox2.Text = Val(TextBox2.Text) - 10 Dim y_intercept = Val(TextBox2.Text) Dim x_intercept = Val(TextBox1.Text) If ComboBox1.SelectedIndex = 0 Then If Not TextBox2.Text = "" Then PictureBox1.Location = New Point(x_intercept, y_intercept) End If End If If ComboBox1.SelectedIndex = 1 Then If Not TextBox2.Text = "" Then Label4.Location = New Point(x_intercept, y_intercept) End If End If End Sub //For "Down" to move Down Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If ComboBox1.SelectedIndex = 0 Then Label4.Visible = False PictureBox1.Visible = True End If If ComboBox1.SelectedIndex = 1 Then Label4.Visible = True PictureBox1.Visible = False End If End Sub End Class




Reply With Quote
