Visual Basic 2010 question.

Discussion in 'Programming General' started by Ginger.James, Aug 13, 2012.

Visual Basic 2010 question.
  1. Unread #1 - Aug 13, 2012 at 3:04 PM
  2. Ginger.James
    Joined:
    Aug 6, 2012
    Posts:
    70
    Referrals:
    0
    Sythe Gold:
    0

    Ginger.James Member
    Banned

    Visual Basic 2010 question.

    Okay, this may seem like a stupid/basic question but I'm designing my own program in Visual basic (derp) and I'm wondering if I could have a 'form within a form', for example instead of clicking a button on the main user interface and it redirecting you to another form, is they're anyway where I could click that button and a form could appear in the main user interface?

    Putting it in this order might be better for some of you to understand

    [Open program]
    [Main UI - Form1]
    [Click button - removes Main UI and redirects you to form2]

    That's what happens now


    This is what I want

    [Open program]
    [Main UI - Form1]
    [Click button - keeps main UI in the background but form2 appears to the side]

    Hopefully it doesn't sound to confusing,
    I appreciate any replies, if there is a source code for this.

    Thanks
     
  3. Unread #2 - Aug 14, 2012 at 1:41 PM
  4. Sw1ft Kyle
    Joined:
    Aug 5, 2012
    Posts:
    90
    Referrals:
    0
    Sythe Gold:
    0

    Sw1ft Kyle Member

    Visual Basic 2010 question.

    Its called an MDI container. Parent containers and child forms. See below:

    Unless otherwise noted, all this will go into the respective form's load event.

    Go to form1 and in the properties list to the right set IsMdiContainer = True.

    Since Form1 is your main form, each subsequent form will be named like I have shown here. (note: you can name whatever you want.)

    Place this in Form1_Load (Handles myBase.Load) <- that event
    Code:
    form2.MdiParent = Me
    form3.MdiParent = Me
    form4.MdiParent = Me 'this tells all other forms that the MDI parent container is ME (form1)
    Make sure you assign Form1 as the parent for EACH new form you make or it wont register correctly.

    ALTERNATIVELY, in each "child" form's load event you can put:

    Code:
    MdiParent = Form1 '(or whatever your MDI parent is named)
    I just think its easier to keep all the code centralized and put it in the Form1_Load event like I said above.

    Lastly, to show the forms when you want them to, do NOT use:

    Code:
    FormX.ShowDialog()
    That will make it the topmost and wont let you click to other forms within the container until it is closed. Instead, use:

    Code:
    FormX.Show()
    To close each form you can use:

    Code:
    FormX.Hide()
    Which will just hide the form and remember its location that you dragged it to within the MDI container (best option). Alternatively you can always use:

    Code:
    FormX.Close()
    ***************************

    Those are the basics. To get more advanced you can make 2 forms appear at once at the click of a button and arrange them side by side regardless of where they appear. Also, I think this will solve your forms appearing over other forms.

    To make a new form appear next to the previous one do this:

    In the button click event for whatever button is supposed to make the new form appear put: (lets assume the first form is FormA and that the new one you want to appear beside it is FormB)

    Code:
    FormB.Show()
    
    Then in the new form's (FormB) load event, put this:

    Code:
    Me.Location = New Point(FormA.Location.X + FormA.Width, FormA.Location.Y)
    "Point" is represented in (X, Y) coordinates from the top left of the form. If you want the form to appear 50x50 pixels into the MDI container you would type:

    Code:
    Me.Location = New Point(50, 50)
    LocationX and Y get the locations of the top left of the form, to make it snap to the formA's right side you would add the width to the X to move it over that many pixels.

    Inversely, if you wanted it to appear to the left you would need to reverse which form's dimensions you reference. For the left instead, use:

    Code:
    Me.Location = New Point(FormA.Location.X - Me.Width, FormA.Location.Y)
    This will put it "formB's width" to the left (X axis) of formA.

    To keep it locked there as you move either form around would require either loops to update the X,Y locations or a timer event to update (set to 10ms or less for smoothness)





    Really hope that helped you.
     
  5. Unread #3 - Aug 14, 2012 at 3:32 PM
  6. Blupig
    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant

    Blupig BEEF TOILET
    $5 USD Donor

    Visual Basic 2010 question.

    I don't know if that's what he means.
    If I'm correct, you want to display the content and controls from form2 on the same form as form1, just without form1's content and controls? If that's the case, just use panels.

    Panel1 - Contains all your shit from form1
    Panel2 - Contains all your shit from form2

    Panel1.Visible = False
    Panel2.Visible = True

    Etc.
     
  7. Unread #4 - Aug 14, 2012 at 3:38 PM
  8. Sw1ft Kyle
    Joined:
    Aug 5, 2012
    Posts:
    90
    Referrals:
    0
    Sythe Gold:
    0

    Sw1ft Kyle Member

    Visual Basic 2010 question.

    I took form within a form to be MDI containers. Thats essentially what they are. lol

    I see what you mean tho blu, now I'm wondering if I typed all that for nothing...

    Here's something I have made already:

    [​IMG]

    Like that Ginger?
     
  9. Unread #5 - Aug 14, 2012 at 5:16 PM
  10. Ginger.James
    Joined:
    Aug 6, 2012
    Posts:
    70
    Referrals:
    0
    Sythe Gold:
    0

    Ginger.James Member
    Banned

    Visual Basic 2010 question.

    Yes!! Thank you swift, exactly what was I looking for.

    Thanks, Swift and Blupig. :)
     
  11. Unread #6 - Aug 16, 2012 at 12:26 AM
  12. Sw1ft Kyle
    Joined:
    Aug 5, 2012
    Posts:
    90
    Referrals:
    0
    Sythe Gold:
    0

    Sw1ft Kyle Member

    Visual Basic 2010 question.


    =) no problem. Hope the program comes out alright. yw:p
     
< Listbox items on Form1 show on Form2 Textboxes | DynaMac- Dynamic Macro Software for Java >

Users viewing this thread
1 guest


 
 
Adblock breaks this site