none
Powershell script to create Exchange Online window and panel RRS feed

  • Question

  • Hi,

    I have written below script to create Exchange online button after clicking ps1 file.

    There after want to display a panel.

    For this script has been written as below but it is not hitting the break point.

    Please let me know to proceed ahead.

      

    [reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")
    [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")



    # CREATE FORM



    $form = New-Object Windows.Forms.Form

    #SET FORM TITLE
    $currlocation=get-location
    $form.text = "Office365 Admin Tool v1.2"
    $form.Size = New-Object Drawing.Point 1000,800

      

    # Message Exchange Online View BUTTON

    # Create Button and set text and location


    #region ExchangeOnlineViewButton
    $ExchangeOnlineViewButton = New-Object Windows.Forms.Button
    $ExchangeOnlineViewButton.text = "Exchange Online"
    $ExchangeOnlineViewButton.Size = New-Object Drawing.Point 200,30
    $ExchangeOnlineViewButton.Location = New-Object Drawing.Point 5,55



    $ExchangeOnlineViewButton.add_click({

    })
    #endregion ExchangeOnlineViewButton

    #region ExchangeOnlinePanel
    $ExchangeOnlinePanel = New-Object Windows.forms.panel
    $ExchangeOnlinePanel.Size = New-Object Drawing.Point 700,500
    $ExchangeOnlinePanel.Location = New-Object Drawing.Point 230,5
    $ExchangeOnlinePanel.BorderStyle = "FixedSingle"
    #endregion ExchangeOnlinePanel

    $form.controls.add($ExchangeOnlinePanel)

    Regards,

    Sudheer


    Thanks & Regards, Sudheer

    Thursday, March 28, 2019 2:21 PM

All replies

  • 2 things i can see wrong with it you need something like

    $form.ShowDialog()

    to show the form and also you not adding the button control you created to the form (or any container)

    If your getting an error when running the script make sure you post the error text

    Cheers
    Glen

    Friday, March 29, 2019 5:09 AM
  • Hi Glen,

    Thanks for the reply.

    I have added the 2 lines as below still i am not able to see the Exchange Online button.

    Please let me know if I am missing anything here

    $form.controls.add($ExchangeOnlineViewButton) 

    $form.ShowDialog()

    Regards,

    Sudheer


    Thanks & Regards, Sudheer

    Friday, March 29, 2019 5:27 AM
  • You need to add the button to the Panel not the Form eg

    eg 

    $ExchangeOnlinePanel.controls.add($ExchangeOnlineViewButton)
    $form.controls.add($ExchangeOnlinePanel)
    $form.ShowDialog()


    Friday, March 29, 2019 5:37 AM
  • Hi Glen,

    After making the changes as below still the button is coming up

    # DISPLAY DIALOG

    #region ExchangeOnlinePanel
    $ExchangeOnlinePanel = New-Object Windows.forms.panel
    $ExchangeOnlinePanel.Size = New-Object Drawing.Point 700,500
    $ExchangeOnlinePanel.Location = New-Object Drawing.Point 230,5
    $ExchangeOnlinePanel.controls.add($ExchangeOnlineViewButton)
    #endregion ExchangeOnlinePanel

    # Message Exchange Online View BUTTON

    # Create Button and set text and location

     
    #region ExchangeOnlineViewButton
    $ExchangeOnlineViewButton = New-Object Windows.Forms.Button
    $ExchangeOnlineViewButton.text = "Exchange Online"
    $ExchangeOnlineViewButton.Size = New-Object Drawing.Point 200,30
    $ExchangeOnlineViewButton.Location = New-Object Drawing.Point 5,55

     

    $ExchangeOnlineViewButton.add_click({

    $ExchangeOnlineViewButton.backcolor = "LightBlue"

    $ExchangeOnlinePanel.Show()

    })
    #endregion ExchangeOnlineViewButton


    #$form.controls.add($ExchangeOnlineViewButton) 
    $form.controls.add($ExchangeOnlinePanel)
     

    $form.ShowDialog()

    Regards,

    Sudheer


    Thanks & Regards, Sudheer

    Friday, March 29, 2019 7:35 AM
  • Hi,

    I am able to achieve using the below script.

    # Create the label control and set text, size and location

    $MailFlowlabel = New-Object Windows.Forms.Label
    $MailFlowlabel.Location = New-Object Drawing.Point 20,20
    $MailFlowlabel.Size = New-Object Drawing.Point 250,30
    $MailFlowlabel.text = "Mail Flow"

    $button = New-Object Windows.Forms.Button
    $button.text = "Exchange Online"
    $form.controls.add($button)

    $form.ShowDialog()

    Regards,

    Sudheer


    Thanks & Regards, Sudheer

    Friday, March 29, 2019 10:03 AM