| 
| 
| 
| #213969 - 2021-01-21 08:28 PM  KiXForms.Net TextBox KeyDown |  
| Richie19Rich77   Seasoned Scripter
 
       
   Registered:  2002-08-16
 Posts: 624
 Loc:  London, England
 | 
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
 |  
| Top |  |  |  |  
| 
| 
| #213971 - 2021-01-30 04:15 PM  Re: KiXForms.Net TextBox KeyDown
[Re:  Richie19Rich77] |  
| ChristopheM   Hey THIS is FUN
 
       
 Registered:  2002-05-13
 Posts: 311
 Loc:  STRASBOURG, France
 | 
Hello,
 Based on Mart code, you can try something like that
 I have separated functions for response to event and function for processing.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
_________________________Christophe
 |  
| Top |  |  |  |  
| 
| 
| #213972 - 2021-01-30 04:18 PM  Re: KiXForms.Net TextBox KeyDown
[Re:  Mart] |  
| ChristopheM   Hey THIS is FUN
 
       
 Registered:  2002-05-13
 Posts: 311
 Loc:  STRASBOURG, France
 | 
Hello, Based on Mart code, here is on other solution :I have separated functions for response to event and functions for processing.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
_________________________Christophe
 |  
| Top |  |  |  |  
 Moderator:  ShaneEP, Mart, Radimus, Jochen, Allen, Glenn Barnas
 
 | 
| 
 
| 0 registered
and 360 anonymous users online. 
 | 
 |  |