Results 1 to 5 of 5

Thread: Pull object and its code from 1 form, and display it on another?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    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?

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    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?

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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"?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Pull object and its code from 1 form, and display it on another?

    Quote Originally Posted by TCarter View Post
    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:
    1. 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.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width