Richie19Rich77
(Seasoned Scripter)
2021-01-21 08:28 PM
KiXForms.Net TextBox KeyDown

Hi All,

Long time since I posted on here \:\) Writing a quick kixforms script to update a few fields in AD for our helpdesk.

I have a Textbox control for the username field and a Search button that performs a LDAP search. I want to call the search button click function when pressing "Enter" on the textbox.

I have done this before but cannot find any of my old scripts from years ago. I would have looked on the user upload scripts but the old KiXForms website is down.

Thanks in advance.

Rich


Mart
(KiX Supporter)
2021-01-22 11:54 AM
Re: KiXForms.Net TextBox KeyDown

Something like this?

 Code:
Break On
$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf
$nul = $System.Application.EnableVisualStyles

$Form1 = $System.Form()
$Form1.Left = 0
$Form1.StartPosition = 0  ;FormStartPosition_Manual
$Form1.Size = $System.Size(317,213) ;(Width,Height)
$Form1.Text = "Form1"
$Form1.Top = 0

$TextBox1 = $System.TextBox()
$TextBox1.KeyPress = "DoSearch(TXTBox)"
$TextBox1.Left = 70
$TextBox1.Text = "TextBox1"
$TextBox1.Top = 50
$nul = $Form1.Controls.Add($TextBox1)

$Button1 = $System.Button()
$Button1.Click = "DoSearch(Button)"
$Button1.Left = 110
$Button1.Text = "Button1"
$Button1.Top = 70
$nul = $Form1.Controls.Add($Button1)

$Form1.Show  ;Displays the Form

While $Form1.Visible
   $Nul = Execute($Form1.DoEvents())
Loop
Exit 0

Function DoSearch($source)
	If $source = "TXTBox" And $TextBox1.KeyPressEventArgs.KeyChar = Chr(13)
		? "Enter pressed in textbox. Searching....."
		;execute search function
	EndIf
	
	If $source = "Button"
		? "Clicked on button. Searching....."
		;execute search function
	EndIf
	
EndFunction


ChristopheM
(Hey THIS is FUN)
2021-01-30 04:15 PM
Re: KiXForms.Net TextBox KeyDown

Hello,

Based on Mart code, you can try something like that
 Code:
Break On
$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf
$nul = $System.Application.EnableVisualStyles
$nul = SetOption( "NoVarsInStrings", "ON" )

$Form1 = $System.Form()
$Form1.Left = 0
$Form1.StartPosition = 0  ;FormStartPosition_Manual
$Form1.ClientSize = $System.Size(240,100) ;(Width,Height)
$Form1.Name = "Form1"
$Form1.Text = "My Windows Form"
$Form1.Top = 0

$TextBox1 = $System.TextBox()
$TextBox1.KeyPress = "$=TextBox1OnKeyPressEvent()"
$TextBox1.Size = $System.Size(200,25) ; (Width,Height)
$TextBox1.Location = $System.Point( 20, 20)     ; x,y
$TextBox1.Name = "TextBox1"
$TextBox1.Text = "TextBox1"
$nul = $Form1.Controls.Add($TextBox1)

$Button1 = $System.Button()
$Button1.Click = "$=Button1OnClickEvent()"
$Button1.Size = $System.Size(95,25) ; (Width,Height)
$Button1.Location = $System.Point( 20, 50)     ; x,y
$Button1.Name = "Button1"
$Button1.Text = "Start Search"
$nul = $Form1.Controls.Add($Button1)

$BtnQuit = $System.Button()
$BtnQuit.Click = "$=BtnQuitOnClickEvent()"
$BtnQuit.Size = $System.Size(95,25) ; (Width,Height)
$BtnQuit.Location = $System.Point(125,50) ; (Width,Height)
$BtnQuit.Name = "BtnQuit"
$BtnQuit.Text = "Quit"
$BtnQuit = $Form1.Controls.Add($BtnQuit)

$Form1.Show  ;Displays the Form

While $Form1.Visible
   $Nul = Execute($Form1.DoEvents())
Loop
Exit 0

;-------------------------------------------------------------------------------
; Functions for event
;-------------------------------------------------------------------------------
Function TextBox1OnKeyPressEvent( )
	If $TextBox1.KeyPressEventArgs.KeyChar = Chr(13)
		$=DoSearch( $TextBox1 )
	EndIf
endfunction

Function Button1OnClickEvent( )
	$=DoSearch($Button1)
endfunction

Function BtnQuitOnClickEvent( )
	$form1.Hide()
endfunction

;-------------------------------------------------------------------------------
; Functions for processing
;-------------------------------------------------------------------------------
Function DoSearch( $obj )
	"Search started from " $obj.name ?
	"Searching..." ?

	;execute search function
EndFunction
I have separated functions for response to event and function for processing.


ChristopheM
(Hey THIS is FUN)
2021-01-30 04:18 PM
Re: KiXForms.Net TextBox KeyDown

Hello, Based on Mart code, here is on other solution :
 Code:
Break On
$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf
$nul = $System.Application.EnableVisualStyles
$nul = SetOption( "NoVarsInStrings", "ON" )

$Form1 = $System.Form()
$Form1.Left = 0
$Form1.StartPosition = 0  ;FormStartPosition_Manual
$Form1.ClientSize = $System.Size(240,100) ;(Width,Height)
$Form1.Name = "Form1"
$Form1.Text = "My Windows Form"
$Form1.Top = 0

$TextBox1 = $System.TextBox()
$TextBox1.KeyPress = "$=TextBox1OnKeyPressEvent()"
$TextBox1.Size = $System.Size(200,25) ; (Width,Height)
$TextBox1.Location = $System.Point( 20, 20)     ; x,y
$TextBox1.Name = "TextBox1"
$TextBox1.Text = "TextBox1"
$nul = $Form1.Controls.Add($TextBox1)

$Button1 = $System.Button()
$Button1.Click = "$=Button1OnClickEvent()"
$Button1.Size = $System.Size(95,25) ; (Width,Height)
$Button1.Location = $System.Point( 20, 50)     ; x,y
$Button1.Name = "Button1"
$Button1.Text = "Start Search"
$nul = $Form1.Controls.Add($Button1)

$BtnQuit = $System.Button()
$BtnQuit.Click = "$=BtnQuitOnClickEvent()"
$BtnQuit.Size = $System.Size(95,25) ; (Width,Height)
$BtnQuit.Location = $System.Point(125,50) ; (Width,Height)
$BtnQuit.Name = "BtnQuit"
$BtnQuit.Text = "Quit"
$BtnQuit = $Form1.Controls.Add($BtnQuit)

$Form1.Show  ;Displays the Form

While $Form1.Visible
   $Nul = Execute($Form1.DoEvents())
Loop
Exit 0

;-------------------------------------------------------------------------------
; Functions for event
;-------------------------------------------------------------------------------
Function TextBox1OnKeyPressEvent( )
	If $TextBox1.KeyPressEventArgs.KeyChar = Chr(13)
		$=DoSearch( $TextBox1 )
	EndIf
endfunction

Function Button1OnClickEvent( )
	$=DoSearch($Button1)
endfunction

Function BtnQuitOnClickEvent( )
	$form1.Hide()
endfunction

;-------------------------------------------------------------------------------
; Functions for processing
;-------------------------------------------------------------------------------
Function DoSearch( $obj )
	"Search started from " $obj.name ?
	"Searching..." ?

	;execute search function
EndFunction
I have separated functions for response to event and functions for processing.