Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problems positioning child window in a parent

Posted on 2011-02-26
2
Medium Priority
?
339 Views
Last Modified: 2012-05-11
Hi there,

OK this one has me completely stumped. I have a parent container with which I can open a number of child windows within it.  All my other windows open at the top left corner.

Although I go through a bit of gymnastics to obtain the size of the window I have used the line:

Me.Location = New Point(0, 0)

Instead it displays down and to the right. If I close it and then open it again it displays further down and further right...

I have used the same process for the other child windows and they open correctly at the top left corner...

So, any ideas?

Simon


Public Sub setFormWidth() Implements accountINTERFACE.IfrmAccountDisplay.setFormWidth
        Try

            If Me.WindowState <> formWindowState.Maximized Then

                Dim totalWidth = 0
                Dim MaxWidth = 0
                Dim maxRows = 0
                Dim assetMaxWidth = 0
                Dim liabilityMaxWidth = 0
                Dim equityMaxWidth = 0
                Dim revenueMaxWidth = 0
                Dim expenseMaxWidth = 0

                Dim ToDo = 0
                Dim ds As System.Drawing.Graphics = CreateGraphics()

                maxRows = Math.Max(maxRows, dgvAssets.RowCount)
                maxRows = Math.Max(maxRows, dgvLiabilities.RowCount)
                maxRows = Math.Max(maxRows, dgvEquity.RowCount)
                maxRows = Math.Max(maxRows, dgvRevenue.RowCount)
                maxRows = Math.Max(maxRows, dgvExpenses.RowCount)

                Do While ToDo < maxRows

                    If ToDo < dgvAssets.RowCount Then

                        assetMaxWidth = Math.Max(assetMaxWidth, ds.MeasureString(dgvAssets.Rows(ToDo).Cells("acc_name").Value, Font).Width)

                    End If

                    If ToDo < dgvLiabilities.RowCount Then

                        liabilityMaxWidth = Math.Max(liabilityMaxWidth, ds.MeasureString(dgvLiabilities.Rows(ToDo).Cells("acc_name").Value, Font).Width)

                    End If

                    If ToDo < dgvEquity.RowCount Then

                        equityMaxWidth = Math.Max(equityMaxWidth, ds.MeasureString(dgvEquity.Rows(ToDo).Cells("acc_name").Value, Font).Width)

                    End If

                    If ToDo < dgvRevenue.RowCount Then

                        revenueMaxWidth = Math.Max(revenueMaxWidth, ds.MeasureString(dgvRevenue.Rows(ToDo).Cells("acc_name").Value, Font).Width)

                    End If

                    If ToDo < dgvExpenses.RowCount Then

                        expenseMaxWidth = Math.Max(expenseMaxWidth, ds.MeasureString(dgvExpenses.Rows(ToDo).Cells("acc_name").Value, Font).Width)

                    End If

                    ToDo += 1

                Loop

                'Now determine the extra width needed if there are vertical scroll bars present.
                If (dgvAssets.DisplayRectangle.Width < dgvAssets.ClientRectangle.Width) Then

                    assetMaxWidth = assetMaxWidth + SystemInformation.VerticalScrollBarWidth

                ElseIf (dgvLiabilities.DisplayRectangle.Width < dgvLiabilities.ClientRectangle.Width) Then

                    liabilityMaxWidth = liabilityMaxWidth + SystemInformation.VerticalScrollBarWidth

                ElseIf (dgvEquity.DisplayRectangle.Width < dgvEquity.ClientRectangle.Width) Then

                    equityMaxWidth = equityMaxWidth + SystemInformation.VerticalScrollBarWidth

                ElseIf (dgvRevenue.DisplayRectangle.Width < dgvRevenue.ClientRectangle.Width) Then

                    revenueMaxWidth = revenueMaxWidth + SystemInformation.VerticalScrollBarWidth

                ElseIf (dgvExpenses.DisplayRectangle.Width < dgvExpenses.ClientRectangle.Width) Then

                    expenseMaxWidth = expenseMaxWidth + SystemInformation.VerticalScrollBarWidth

                End If

                If assetMaxWidth < 150 Then assetMaxWidth = 150
                If liabilityMaxWidth < 150 Then liabilityMaxWidth = 150
                If equityMaxWidth < 150 Then equityMaxWidth = 150
                If revenueMaxWidth < 150 Then revenueMaxWidth = 150
                If expenseMaxWidth < 150 Then expenseMaxWidth = 150


                assetMaxWidth = Fix(assetMaxWidth)
                liabilityMaxWidth = Fix(liabilityMaxWidth)
                equityMaxWidth = Fix(equityMaxWidth)
                revenueMaxWidth = Fix(revenueMaxWidth)
                expenseMaxWidth = Fix(expenseMaxWidth)

                assetSplitterDistance = assetMaxWidth + 44
                liabilitiesSplitterDistance = liabilityMaxWidth + 44
                equitySplitterDistance = equityMaxWidth + 44
                revenueSplitterDistance = revenueMaxWidth + 44
                expenseSplitterDistance = expenseMaxWidth + 44

                Me.Width = assetSplitterDistance + liabilitiesSplitterDistance + equitySplitterDistance + revenueSplitterDistance + expenseSplitterDistance + 20
                formWidth = Me.Width

                spcAssets.SplitterDistance = assetSplitterDistance
                spcLiabilities.SplitterDistance = liabilitiesSplitterDistance
                spcEquity.SplitterDistance = equitySplitterDistance
                spcRevExp.SplitterDistance = revenueSplitterDistance - 4

                Me.Location = New Point(0, 0)

                'Me.MaximumSize = New System.Drawing.Size(Me.Width, Me.MdiParent.DisplayRectangle.Height - 195)
                'Me.MinimumSize = New System.Drawing.Size(Me.Width, Me.MdiParent.DisplayRectangle.Height - 195)

                'Clean up the drawing surface
                ds.Dispose()

            End If

            loadedAgain = True

        Catch ex As Exception

            manageWindowsViewError("accountTASK", "frmAccountDisplay", "displayAccountsInDGV", ex)

        End Try

    End Sub

Open in new window

Screen-displays-down-and-to-the-.png
0
Comment
Question by:si2030
2 Comments
 
LVL 33

Accepted Solution

by:
jppinto earned 2000 total points
ID: 34991206
_frmChildForm.MdiParent = Me.MdiParent
_frmChildForm.StartPosition = FormStartPosition.Manual
_frmChildForm.Location = System.Drawing.Point(0,0)
_frmChildForm.Show()
0
 

Author Closing Comment

by:si2030
ID: 34992725
This actually did work although I am not quite sure why I needed to include formstartpoint.manual to make this happen...

                Me.StartPosition = FormStartPosition.Manual
                Me.Location = New Point(0, 0)

Thanks :)
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

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…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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