Pull object and its code from 1 form, and display it on another?
ok, I might be going about this all wrong, but i've been reading up on some stuff, and am venturing into stuff i've never dealt with before.
example: when people do things like, dim xxx as new form1
then xxx.show...how do you design that xxx form? and get the objects placed where you want it?
Anyways, is it possible to say...
Design an object on form2. Say Panel, populate it the way I want it. Code it the way I want it.
Then, say on form1, i push a button, and it will display the panel(on form2) on form1?
Re: Pull object and its code from 1 form, and display it on another?
You cannot use the control of 1 form into the other.
You will have to create new controls and set their properties ditto to the ones in form1.
Here is an example... Please amend as applicable...
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim picBox As New PictureBox
With picBox
'~~> Set the image
.Image = Image.FromFile("C:\MyPic.bmp")
'~~> Set the releant location and size as per the Picturebox in form 1
'~~> I have taken 50 and 90 as an example
.Location = New System.Drawing.Point(50, 50)
.Size = New Size(90, 90)
End With
'~~> Add to the Controls collection
Me.Controls.Add (picBox)
End Sub
I would suggest reading on 'Creating controls at Runtime"
Hope this helps...
Re: Pull object and its code from 1 form, and display it on another?
if you meant to have that as a link..it didnt work.
I appreciate it.
but i guess the question is, if i add the things like say... label, and i needed to add a code to the "iftextchanged" field or whatever..how would i do that?
Re: Pull object and its code from 1 form, and display it on another?
No it is not a link. You will have to search vbforums and google to understand on how to create controls at runtime.
What is "iftextchanged"?
Re: Pull object and its code from 1 form, and display it on another?
Quote:
Originally Posted by
TCarter
if you meant to have that as a link..it didnt work.
I appreciate it.
but i guess the question is, if i add the things like say... label, and i needed to add a code to the "iftextchanged" field or whatever..how would i do that?
I'm also a little confused on exactly what you're asking. So, let's say you have 2 labels. One label, Label1, is on Form1. The other label is on Form2 and is called Label2.
If you want to make the Text of Label2, the same as Label1, then you could just easily do this in Form2's Load event:
VB.NET Code:
Label2.Text = Form1.Label1.Text
So, when Form2 loads, the text is the same. Now, there are a few things that you might need to know about this, but we'll get to those later if this is what you need. Otherwise, we might need a bit of clarification.
But, koolsid is right. The control will have to already be on the new form or you will have to create it in code.