Solved

Problems positioning child window in a parent

Posted on 2011-02-26
2
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 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