So I have been trying to Google this, and haven't been able to find a solution, or found a proper way to even Google this issue I am having.
So let's say I am creating a form in Visual Studio. I have set the size of the form to be Width = 250, Height = 250
. I using the toolbox add a Textbox to the form that is as Location X = 25, Y = 25
with Width = 100
.
You all with me so far?
The load method for the form has the following code:
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim TextBox2 As New TextBox With {
.Location = New Point(25,25),
.Visible = True,
.Width = 100
}
Me.Controls.Add(TextBox2)
End Sub
The expected result when I run this program is to have 2 textboxes directly on top of each other, essentially making it look like 1 text box is on the form. But what is actually happening if I have the TextBox I placed on the form non-programmatically appearing where I placed it, and the TextBox I created in the Load method appearing offset from where it is suppose to.
So why is this happening? Is it a problem with how I am adding the element to the form?
EDIT: This is what my Form looks like when I run the above code:
EDIT 2:
To clarify I am not trying to figure out how to place one form element on top of another. I am trying to figure out why I am having a problem with placing any element at a specific location when trying to add the element programmatically.