Results 1 to 7 of 7

Thread: Getting Parent Form's Property Values in a Child Form

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2012
    Location
    Las Vegas, NV
    Posts
    18

    Getting Parent Form's Property Values in a Child Form

    I have a custom form that I use instead of msgbox for a number of reasons. The initial reason was to keep the message centered on it's parent rather than the screen. There are many articles about this but I still have not found an elegant way to get access to the Parent's properties from inside the Child without passing them in (by one way or another).

    In the child form the me.parent, me.parentform are not instantiated and apparently can not be used.

    The point is to have this form be totally encapsulated with the logic being self contained. This is not an MDI child, and I do not want it to be due to the limitations on MDI children.

    My current workaround looks like this I use a ShowMsg Function in my MyMsgBox form which looks like this:

    VB.NET Code:
    1. Friend Function ShowMsg(ByVal MYParent As Form, _
    2.                             ByVal msg As String, _
    3.                    Optional ByVal s As MsgBoxStyle = MsgBoxStyle.OkOnly, _
    4.                    Optional ByVal Alignment As System.Windows.Forms.HorizontalAlignment = _
    5.                                           HorizontalAlignment.Center, _
    6.                    Optional ByVal ItIsDialog As Boolean = True, _
    7.                    Optional ByVal enCut As Boolean = False, _
    8.                    Optional ByVal eMBoxBRColor As Object = Nothing, _
    9.                    Optional ByVal eMBtxtBRColor As Object = Nothing) As MsgBoxResult
    10.  
    11.         m_Style = s
    12.         m_Msg = msg
    13.         m_Alignment = Alignment
    14.         m_EnableCut = enCut
    15.  
    16.         If eMBoxBRColor <> Nothing Then m_meBackroundColor = eMBoxBRColor
    17.         If eMBtxtBRColor <> Nothing Then m_txtBackroundColor = eMBtxtBRColor
    18.  
    19.         m_ParentWidth = MYParent.Width
    20.         m_ParentHeight = MYParent.Height
    21.         m_ParentTop = MYParent.Top
    22.         m_ParentLeft = MYParent.Left
    23.  
    24.         If ItIsDialog Then
    25.             ShowMsg = Me.ShowDialog
    26.         Else
    27.             Me.Show()
    28.         End If
    29.  
    30.     End Function

    The Call from the Parent looks like this

    VB.NET Code:
    1. MyMsgBox.ShowMsg( Me, "This is my Message")

    My question, Is there a more elegant way given the me.parent.properties seem to not be available in the child?
    Last edited by RayLNelson; Feb 20th, 2012 at 11:42 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width