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:
Friend Function ShowMsg(ByVal MYParent As Form, _ ByVal msg As String, _ Optional ByVal s As MsgBoxStyle = MsgBoxStyle.OkOnly, _ Optional ByVal Alignment As System.Windows.Forms.HorizontalAlignment = _ HorizontalAlignment.Center, _ Optional ByVal ItIsDialog As Boolean = True, _ Optional ByVal enCut As Boolean = False, _ Optional ByVal eMBoxBRColor As Object = Nothing, _ Optional ByVal eMBtxtBRColor As Object = Nothing) As MsgBoxResult m_Style = s m_Msg = msg m_Alignment = Alignment m_EnableCut = enCut If eMBoxBRColor <> Nothing Then m_meBackroundColor = eMBoxBRColor If eMBtxtBRColor <> Nothing Then m_txtBackroundColor = eMBtxtBRColor m_ParentWidth = MYParent.Width m_ParentHeight = MYParent.Height m_ParentTop = MYParent.Top m_ParentLeft = MYParent.Left If ItIsDialog Then ShowMsg = Me.ShowDialog Else Me.Show() End If End Function
The Call from the Parent looks like this
VB.NET Code:
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?


Reply With Quote
)


