[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

URGENT - Form Inside Panel, Problems resizing content correctly

Posted on 2006-04-19
11
Medium Priority
?
379 Views
Last Modified: 2008-03-06
Experts,
    Rather than using MDI I've opted to load forms inside of a panel for presentation purposes. My program is nearly complete, however I'm having issues when my form gets resized. My main form "frmPropertyTracker" has a panel on it called "pnlMainContent" and then within that panel I am displaying the new forms based upon the users selection. I used the following code that I found on EE and it has worked great except when I resize frmPropertyTracker the form displayed inside the panel stays maximized and does not resize the content accordingly. Ideally I would like it resize based on the size of the panel... if anyone can help I would apprecaite it!!

Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer

    Private Sub btnLeaseSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeaseSearch.Click
           Dim frmPropertyTrackerLeases As New frmPropertyTrackerLeases
           SetParent(frmPropertyTrackerLeases.Handle.ToInt32, pnlFormContainer.Handle.ToInt32)
           frmPropertyTrackerLeases.WindowState = FormWindowState.Maximized
           frmPropertyTrackerLeases.Show()    
    End Sub

The other issue I'm having with this code is that I would like to know how to close down other open forms before I run the code above so that I don't have 500 forms floating around in memory. Thanks in advance to anyone that can help...

Jason
0
Comment
Question by:Yeavis
  • 4
  • 4
  • 3
11 Comments
 

Author Comment

by:Yeavis
ID: 16495108
Oopss... I realize that the panel names don't match... please disregard that.
0
 
LVL 4

Expert Comment

by:broadbent
ID: 16495791
I understand the problem as follows.
You have a panel - pnlMainContent and you wish to display various forms within it, presumably when some button or other is pressed.
I assume these forms don't have borders.
Effectively you have tabpages, so why not use a tab control?
0
 

Author Comment

by:Yeavis
ID: 16498007
Say I implemented the tab control, how much customization could I do as far as appearance? What I'm looking for is something that fits right into the form without adding bulking edges or visual styles. The method I have in place now works beautifully but as I mentioned I have this issue. If you could code up and example of a simliar situation (where it all fits inside a panel) then I would be happy to consider using the tab control. I'm new to vb.net and I haven't played with the tab control in previous versions of vb either...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Expert Comment

by:broadbent
ID: 16498203
I don't like the tabcontrol only because it doesn't let me use a transparent background, but writing your own is quite difficult.
That apart, iot is a very standard implementation for applications, and you should at least try it.
Open a completely new project and on the blank form add the tabcontrol. Play with it!
0
 
LVL 5

Accepted Solution

by:
maralans earned 2000 total points
ID: 16500346
Another alternative would be to use User Controls rather than regular forms.

Private Sub lblDelInst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblDelInst.Click
        Dim tempObject As New ucPropertyTrackerLeases      ' Create an object of the user control.
        pnlFormContainer.Controls.Clear()                              ' Clear anything that the panel is displaying.
        pnlFormContainer.Controls.Add(tempObject)              ' Add the control to the panel which will automatically display it.
0
 
LVL 5

Expert Comment

by:maralans
ID: 16500450
Open a new project.  Put 2 buttons and a panel on form1.  Add 2 user controls making the backgroud colors different colors and paste the following code to try.

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim tempObject As New UserControl1    ' Create an object of the user control.
        Panel1.Controls.Clear()                              ' Clear anything that the panel is displaying.
        Panel1.Controls.Add(tempObject)              ' Add the control to the panel which will automatically display it.
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim tempObject As New UserControl2     ' Create an object of the user control.
        Panel1.Controls.Clear()                              ' Clear anything that the panel is displaying.
        Panel1.Controls.Add(tempObject)              ' Add the control to the panel which will automatically display it.
    End Sub
End Class
0
 

Author Comment

by:Yeavis
ID: 16501423
I like the user control idea... but is there a way I could maximize the control in the panel?
0
 
LVL 4

Expert Comment

by:broadbent
ID: 16501597
Use mycontrol.Dock = DockStyle.Fill
0
 
LVL 5

Expert Comment

by:maralans
ID: 16502009
If your playing with the above example, a simple way is to make your user control the same size as the panel. Then if you want to keep the user control contained in the panel use:

Panel1.Dock = DockStyle.Right
0
 

Author Comment

by:Yeavis
ID: 16502411
Awesome! I have been beating my head on this for a couple days and now it works like a charm. I appreciate all your help...
0
 
LVL 5

Expert Comment

by:maralans
ID: 16502579
I know the feeling all too well.  Glad it works for you.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question