#192987 - 2009-03-18 06:04 PM
KiXforms.Net Learning Series - Getting started w/KiXforms.Net - Lesson 01
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
KiXforms.Net Learning Series - Getting started w/KiXforms.Net - Lesson 01
Guidelines:
- All scripter’s are welcome, Beginners to Masters.
- KiXforms.Net version 3.2.16.0 or newer should be used. To verify your version of KiXforms.Net, use KiXforms.Net Version Checker (found below).
- Use descriptive variable names to make it easier for yourself and others to follow what is happening.
- Other help can be found:
- 'KiXforms.chm'
- 'Kixforms.System.tlb'
- 'Scripted Resource (Base64) Development Kit'
- 'KiXforms Designer .NET 2.0 (Beta)'
- 'The Script Center Script Repository'
- 'KiXtart.org UDF library collection'
- Note: 'KiXforms.chm' can be found in KiXforms.Zip (KF.NET Development Build)
'Kixforms.System.tlb' can be found in your System32 directory after the installation of KiXforms.msi (found in 'KiXfomrs.zip'). To view 'Kixforms.System.tlb' use iTripoli Type Library Viewer. If you choose, you can create a shortcut to the ‘iTripoli Type Library Viewer' then, modify the shortcut target to: "C:\Program Files\iTripoli\Tools\TypeViewer.exe" Kixforms.System.tlb, then the shortcut will automatically open 'Kixforms.System.tlb'. Get Scripted Resource (Base64) Development Kit if you want or need it. Get KiXforms Designer .NET 2.0 (Beta) if you want or need it. Go to The Script Center Script Repository if you want or need to. Go to KiXtart.org UDF library collection if you want or need to. You can also modify UDFs found in 'KiXtart.org UDF library collection' if needed but make sure you comment on your changes.
- All code should be as though it were to be used in production.
- Code should set options to On.
- Error checking should be in place where needed.
- All variables including form and controls should be Dimmed.
- All UDFs should be self contained and all variables Dimmed.
- All code should be in code tags.
- When creating KiXforms the command console is not desired so use 'WKiX32.exe' not 'KiX32.exe'.
KiXforms.Net Version Checker:
;KiXforms.Net Version Checker
;Set Break to On if not in Logon Mode.
If Not @LogonMode
Break On
EndIf
;Set Code Options to On
Dim $SO
$SO=SetOption("NoMacrosInStrings", "ON")
$SO=SetOption("NoVarsInStrings", "ON")
$SO=SetOption("Explicit", "ON")
;Setup Variables.
Dim $System,$nul,$MainForm,$ProductVersionLabel,$ProductNameLabel
;Create 'Kixforms.System' Object.
$System = CreateObject("Kixforms.System")
;Verify the 'Kixforms.System' Object was created if not, notify and exit.
If Not $System
$nul= MessageBox("KiXforms.Net Not Initiated."+@CRLF+
"Please verify KiXforms.Net is installed."+@CRLF+
"This Script Will Now Close.","Error",16)
Quit()
EndIf
;Create Form and Controls.
$MainForm = $System.Form()
$MainForm.StartPosition = $System.FormStartPosition_CenterScreen
$MainForm.Size = $System.Size(338,83)
$MainForm.Text = "KiXforms.Net Version Checker"
$ProductVersionLabel = $System.Label()
$ProductVersionLabel.Dock = $System.DockStyle_Top
$ProductVersionLabel.Text = "Ver. "+$System.ProductVersion
$ProductVersionLabel.TextAlign = $System.ContentAlignment_MiddleCenter
$nul = $MainForm.Controls.Add($ProductVersionLabel)
$ProductNameLabel = $System.Label()
$ProductNameLabel.Dock = $System.DockStyle_Top
$ProductNameLabel.Text = $System.ProductName
$ProductNameLabel.TextAlign = $System.ContentAlignment_MiddleCenter
$nul = $MainForm.Controls.Add($ProductNameLabel)
;Show the Form
$MainForm.Show
;Loop to catch form events.
While $MainForm.Visible
$nul = Execute($MainForm.DoEvents())
Loop
Exit 0
Standard Code Set Options:
;region Set Code Options
;Set Break to On if not in Logon Mode.
If Not @LogonMode
Break On
EndIf
;Set Code Options to On
Dim $SO
$SO=SetOption("NoMacrosInStrings", "ON")
$SO=SetOption("NoVarsInStrings", "ON")
$SO=SetOption("Explicit", "ON")
;endregion Set Code Options
Objectives for Lesson 01:
- Create a form script with KiXforms.Net.
- Learn how to Initiate the KiXforms Object.
- Learn how to Verify the KiXforms Object was created.
- Learn about the Form.Show property
- Learn about the Form.Visible property
- Learn about the DoEvents() function
- Learn about the Form.Text property
- Learn about the Form.Top property
- Learn about the Form.Left property
- Learn about the Form.Height property
- Learn about the Form.Width property
- Learn about the Form.Size property
- Learn about the Form.StartPosistion property.
- Learn about the KiXforms Object Application.EnableVisualStyles
Create:
- A user intuitive, sizable form that centers it's self upon startup.
To Create the KiXforms Object use this code:
$System = CreateObject("Kixforms.System")
Once the KiXforms Object is created, you should Verify that it truly exists, this can be done with a simple ‘If Endif’ statement. If it does not exist a ‘MessageBox()’ Function can return the failure message to the user. This can be helpful to tell you that there is a good chance that KiXforms.Net is not installed on the computer in question.
If Not $System
$nul = MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.", "Error", 16)
Quit()
EndIf
To create a basic Form a few things are needed after the KiXforms Object is created: You need to create the Form:
By default the form is not visible, so you have to show the form:
The Form is the core of all KiXorms events, if it does not exist nothing can happen on the form. Events are processed 1 at a time thru the Form.DoEvents function. On a form you will likely have many events that you will need to look and code for. The Form.DoEvents function is a one time function, so if you want to deal with all the events that might come along you have to constantly execute the Form.DoEvents function. We don't want to process any events if the form is not visible. That being said a simple 'While Loop' statement will get us what we are looking for:
While $Form.Visible
$Nul = Execute($Form.DoEvents())
Loop
If the Form is closed we want to exit cleanly we can do this with a simple 'Exit 0' statement.
Putting everything together we have just learned:
;Standard Code Set Options
;region Set Code Options
;Set Break to On if not in Logon Mode.
If Not @LogonMode
Break On
EndIf
;Set Code Options to On
Dim $SO
$SO = SetOption("NoMacrosInStrings", "ON")
$SO = SetOption("NoVarsInStrings", "ON")
$SO = SetOption("Explicit", "ON")
;endregion
;region Setup Variables
Dim $System, $nul
Dim $Form
$System = CreateObject("Kixforms.System") ;Creates the KiXforms Object
If Not $System ;Verifies the KiXforms Object was created
$nul = MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.", "Error", 16) ;Notifies the user if not created
Quit()
EndIf
;endregion
;region Main Form
$Form = $System.Form() ;Creates the Form
$Form.Show ;Displays the Form
While $Form.Visible
$Nul = Execute($Form.DoEvents()) ;Checks for KiXforms Events
Loop
Exit 0
;endregion
By default the form Title Bar is blank, no Text. To add text to it use the Form.Text property like this:
$Form.Text = "Form Example"
By default when the form is created, it will be displayed in the top left corner of the screen. If you execute the sample form code, close it, execute it again over and over the form will cascade from the top left to the bottom right of the screen.
To place the form at a consistent place every time it is shown, use the Form.Top and Form.Left properties:
$Form = $System.Form() ;Creates the Form
$Form.Left = 100
$Form.Text = "Form Example"
$Form.Top = 100
$Form.Show ;Displays the Form
You can change the Forms position by modifying these values. These values are the number of pixels counted across and down from the top left of the screen, growing from left to right and top to bottom.
By default the form Height is 300 and the form Width is 300. To Alter these use the Form.Height and Form.Width properties:
$Form = $System.Form() ;Creates the Form
$Form.Height = 400
$Form.Left = 100
$Form.Text = "Form Example"
$Form.Top = 100
$Form.Width = 600
$Form.Show ;Displays the Form
Like the Form.Top and Form.Left properties, Form.Height and Form.Width are in pixels. Change these values to increse or decrease the size of the form.
You don't have to use the Form.Height and Form.Width to affect a change in the size of the form. You can also use the Form.Size property. Unlike the other properties it is defined by the KiXforms Object Size property like this.
$Form.Size = $System.Size(600, 400) ;(Width,Height)
When the Form.Size property is used there is no need for the Form.Height and Form.Width property.
$Form = $System.Form() ;Creates the Form
$Form.Left = 100
;$Form.Size = $System.Size(600, 400) ;(Width,Height)
$Form.Text = "Form Example"
$Form.Top = 100
$Form.Show ;Displays the Form
While $Form.Visible
$Nul = Execute($Form.DoEvents()) ;Checks for KiXforms Events
Loop
Exit 0
If you want the form to always be centered on the screen, use the Form.StartPosition property. Like the Form.Size property it is defined by the KiXforms Object like this:
$Form.StartPosition = $System.FormStartPosition_CenterScreen
When the Form.StartPosition property is used there is no need for the Form.Top and Form.Left properties.
$Form = $System.Form() ;Creates the Form
$Form.StartPosition = $System.FormStartPosition_CenterScreen
$Form.Size = $System.Size(600, 400) ;(Width,Height)
$Form.Text = "Form Example"
$Form.Show ;Displays the Form
People use different operating systems like Windows XP and Windows Vista. The Visual look of these operating systems are different. If you use the code as is, it will look like Windows XP even on Windows Vista. To accommodate for these different looks we use the KiXforms Object Application.EnableVisualStyles like this:
$nul = $System.Application.EnableVisualStyles
This will allow WinXP to look like XP and WinVista to look like Vista.
The Final code will look like this:
;Standard Code Set Options
;region Set Code Options
;Set Break to On if not in Logon Mode.
If Not @LogonMode
Break On
EndIf
;Set Code Options to On
Dim $SO
$SO = SetOption("NoMacrosInStrings", "ON")
$SO = SetOption("NoVarsInStrings", "ON")
$SO = SetOption("Explicit", "ON")
;endregion
;region Setup Variables
Dim $System, $nul
Dim $Form
$System = CreateObject("Kixforms.System") ;Creates the KiXforms Object
If Not $System ;Verifys the KiXforms Object was created
$nul = MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.", "Error", 16) ;Notifies the user if not created
Quit()
EndIf
$nul = $System.Application.EnableVisualStyles
;endregion
;region Main Form
$Form = $System.Form() ;Creates the Form
$Form.StartPosition = $System.FormStartPosition_CenterScreen
$Form.Size = $System.Size(600, 400) ;(Width,Height)
$Form.Text = "Form Example"
$Form.Show ;Displays the Form
While $Form.Visible
$Nul = Execute($Form.DoEvents()) ;Checks for KiXforms Events
Loop
Exit 0
;endregion
|
Top
|
|
|
|
Moderator: NTDOC, ShaneEP, Mart, Radimus, Glenn Barnas, Jochen, Allen
|
0 registered
and 718 anonymous users online.
|
|
|