none
Cast object to type System.String to System.Windows.Forms.IWin32Window? RRS feed

  • Question

  • Hello,

    I'm trying to create a DropDownMenuItem that, when clicked, shows the MAC address inside a textbox in the form2 (which opens when the DropDownMenuItem is selected.

        Private Sub MyMACAddressToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MyMACAddressToolStripMenuItem.Click
            Dim mac As String
            mac = getMacAddress()
            MessageBox.Show(mac)
        End Sub
    
        Function getMacAddress()
            Dim nics() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces()
            Return nics(1).GetPhysicalAddress.ToString
        End Function


    This is the working version of the code, this obviously opens a MessageBox. The reason why I want it in my own form (form2) is because I have created a custom theme for the project and the standard MessageBox does not conform to the theme.

    I've tried to see what happens when I modify the code (perhaps nonsensically) to:

    Dim mac As Windows.Forms.IWin32Window
    
    ...
    
    Form2.Show(mac)

    However this creates a runtime error.

    Is there any way to make a mac address appear in my form2 (or in a textbox in form2). Or is there any way in which I could change the design of a MessageBox quite drastically through the designer?

    Thanks for the help!

    Thursday, October 26, 2017 1:55 AM

Answers

  • Is there any way to make a mac address appear in my form2 (or in a textbox in form2). Or is there any way in which I could change the design of a MessageBox quite drastically through the designer?

    To create a custom message box, use the Dialog template available in the Project / Add Windows Form selection list.  Ad any required controls to the template, and set the required variable values.

    To populate a control in that form, create a custom constructor and pass the  value in the call to the constructor (which is what the MessageBox class does).
    https://vbdotnetblog.wordpress.com/forms/97-2/

    Casting is not involved.   It is not possible to comment on the error without the details of the error message or the line at which it occurs.

    Thursday, October 26, 2017 2:02 AM

All replies

  • Is there any way to make a mac address appear in my form2 (or in a textbox in form2). Or is there any way in which I could change the design of a MessageBox quite drastically through the designer?

    To create a custom message box, use the Dialog template available in the Project / Add Windows Form selection list.  Ad any required controls to the template, and set the required variable values.

    To populate a control in that form, create a custom constructor and pass the  value in the call to the constructor (which is what the MessageBox class does).
    https://vbdotnetblog.wordpress.com/forms/97-2/

    Casting is not involved.   It is not possible to comment on the error without the details of the error message or the line at which it occurs.

    Thursday, October 26, 2017 2:02 AM
  • Thanks a lot for the help! I'll go create a custom message box now.
    Thursday, October 26, 2017 2:06 AM