|
|
|||||||
KiXforms.Net Learning Series - Getting started w/KiXforms.Net - Lesson 01 Guidelines:
KiXforms.Net Version Checker: Code: ;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: Code: ;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:
To Create the KiXforms Object use this code: 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. Code: 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: Code: $Form = $System.Form() By default the form is not visible, so you have to show the form: Code: $Form.Show 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: Code: 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. Code: Exit 0 Putting everything together we have just learned: Code: ;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: Code: $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: Code: $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: Code: $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. Code: $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. Code: $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: Code: $Form.StartPosition = $System.FormStartPosition_CenterScreen When the Form.StartPosition property is used there is no need for the Form.Top and Form.Left properties. Code: $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: Code: $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: Code: ;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 |