Solved

Problems positioning child window in a parent

Posted on 2011-02-26
2
299 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import a txt file into a DataGridView and TextBox 20 62
VB.Net WebRequest Code from JSON curl 7 85
Code enhancement 4 32
Access/Visual Basic Question 3 41
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 …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 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