Accessing Form Controls from a function

Welcome Forums General PowerShell Q&A Accessing Form Controls from a function

This topic contains 1 reply, has 1 voice, and was last updated by

1 year, 5 months ago.

  • Author
  • #80936

    Points: 0
    Rank: Member

    I am trying to write to a textbox from a function. Can you please help me to do that.
    I am not sure how this line should be >>> $Form.Controls.textbox.Text = "test" < <<<

      Function fnc_Generate_Form {

      Add-Type -AssemblyName System.Windows.Forms
      Add-Type -AssemblyName System.Drawing

      $Form = New-Object system.Windows.Forms.Form
      $Form.StartPosition = "CenterScreen"
      $Form.Topmost = $True
      $Form.size = New-Object System.Drawing.Size(200,200)
      $Form.Text = "DBA Assist"
      $Form.DataBindings.DefaultDataSourceUpdateMode = 0

      $textbox = New-Object System.Windows.Forms.TextBox
      $textbox.Location ='10,10'
      $textbox.Size = '100,100'

      $WriteToTextBox = New-Object System.Windows.Forms.Button
      $WriteToTextBox.Location = New-Object System.Drawing.Size(35,100)
      $WriteToTextBox.Size = New-Object System.Drawing.Size(120,23)
      $WriteToTextBox.Text = "Write To TextBox"

      #Add Button event
      fnc_WriteToTextBox $Form



      Function fnc_WriteToTextBox
      { Param($Form)

      $Form.Controls.textbox.Text = "test"



  • #80939

    Points: 0
    Rank: Member

    Ok, So i have a solution , but hoping someone replies with something better

      Function fnc_WriteToTextBox
      { Param($Form, $textbox)

      #$Form.Controls.textbox.Text = "test"
      $textbox.Text = "test"


The topic ‘Accessing Form Controls from a function’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort