Page 1 of 1 1
Topic Options
#213969 - 2021-01-21 08:28 PM KiXForms.Net TextBox KeyDown
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 623
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
#213970 - 2021-01-22 11:54 AM Re: KiXForms.Net TextBox KeyDown [Re: Richie19Rich77]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4665
Loc: The Netherlands
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


Edited by Mart (2021-01-22 02:57 PM)
Edit Reason: Little update. Added button to click.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213971 - 2021-01-30 04:15 PM Re: KiXForms.Net TextBox KeyDown [Re: Richie19Rich77]
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 307
Loc: STRASBOURG, France
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.
_________________________
Christophe

Top
#213972 - 2021-01-30 04:18 PM Re: KiXForms.Net TextBox KeyDown [Re: Mart]
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 307
Loc: STRASBOURG, France
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.
_________________________
Christophe

Top
Page 1 of 1 1


Moderator:  ShaneEP, Mart, Radimus, Jochen, Allen, Glenn Barnas 
Hop to:
Shout Box

Who's Online
0 registered and 154 anonymous users online.
Newest Members
vertage, dimi575, Drecksnacken, Nlill, webtools321
17735 Registered Users

Generated in 0.048 seconds in which 0.019 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org