KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Generate Controls dynamically during runtime via a template

 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
mercury
KiXforms Regular
KiXforms Regular


Joined: 10 Aug 2005
Posts: 50

PostPosted: Sat May 13, 2006 4:32 pm    Post subject: Generate Controls dynamically during runtime via a template Reply with quote

Hi Shawn,

Is it possible to generate controls dynamically during runtime via a template?

for example:
Code:

$nul = GenerateControl("ComboBox","Column01","Status",5,25)


Function GenerateControl($Type,$Name,$Paramter1,$Paramter2,$Paramter3)
   
   ;Template
   
   $Type($Name) = $System.$Type()
   $Type($Name).Text = $Paramter1
   $Type($Name).Left = $Paramter2
   $Type($Name).Top = $Paramter3
   $nul = $Container.Controls.Add($Type($Name))
   
EndFunction
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat May 13, 2006 4:44 pm    Post subject: Reply with quote

hehee, funny you asked about this - I just added this feature to kf.classic. But in the short-term, for kf.net, could do something like this (depending on your NoVarsInStrings settings etc):

Code:

Break On

$System = CreateObject("Kixforms.System")

$Form = $System.Form()

$Control = MakeControl("ComboBox")
$Control.Center()

$Form.Center
$Form.Show
While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function MakeControl($Type)

 Dim $Control

 $= Execute("$$Control = $$Form.Controls.Add($$System.$Type)")

 $MakeControl = $Control

EndFunction
Back to top
View user's profile Send private message
Les
KiXforms Aficionado
KiXforms Aficionado


Joined: 24 Dec 2003
Posts: 317

PostPosted: Sat May 13, 2006 5:51 pm    Post subject: Reply with quote

I guess the new novars compliancy rule over at korg doesn't apply here eh? :p
_________________
The Repro Man
Stealing for a living!
Back to top
View user's profile Send private message
mercury
KiXforms Regular
KiXforms Regular


Joined: 10 Aug 2005
Posts: 50

PostPosted: Sat May 13, 2006 6:35 pm    Post subject: Reply with quote

Excellent!

..... Well that is until I realized that I want to create multiple controls at once. They would need different names that were also created dynamically.

Then I thought, why not an array of controls?

Smile

Code:
Break On

$System = CreateObject("Kixforms.System")

$Form = $System.Form()

Dim $Control[10]

For $x = 1 to 10
   $Control[$x] = MakeControl("ComboBox")
   $Control[$x].Left = 5
   $Control[$x].Top = $x * 21
Next

$Form.Center
$Form.Show
While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function MakeControl($Type)

 Dim $Control

 $= Execute("$$Control = $$Form.Controls.Add($$System.$Type)")

 $MakeControl = $Control

EndFunction


Last edited by mercury on Sat May 13, 2006 8:59 pm; edited 1 time in total
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat May 13, 2006 8:36 pm    Post subject: Reply with quote

Quote:

I guess the new novars compliancy rule over at korg doesn't apply here eh? :p


Oh-oh merc, we been caught. ;0)
Back to top
View user's profile Send private message
mercury
KiXforms Regular
KiXforms Regular


Joined: 10 Aug 2005
Posts: 50

PostPosted: Sat May 13, 2006 9:01 pm    Post subject: Reply with quote

Damn Shawn, you're not teaching me bad habbits are you!? Wink
Back to top
View user's profile Send private message
Les
KiXforms Aficionado
KiXforms Aficionado


Joined: 24 Dec 2003
Posts: 317

PostPosted: Sat May 13, 2006 10:10 pm    Post subject: Reply with quote

THe only "habit" you will find shawn in is (as described in 6 a, http://dictionary.reference.com/search?r=2&q=habit ) is sheep's clothing. Razz

ba a a a ad shawn.

_________________
The Repro Man
Stealing for a living!
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat May 13, 2006 11:33 pm    Post subject: Reply with quote

lol, well at least we dimmed our udf var:

Dim $Control

That has to count for something.
Back to top
View user's profile Send private message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Mon May 15, 2006 5:49 pm    Post subject: Reply with quote

tell us how you can do this in kf classic Very Happy
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon May 15, 2006 7:18 pm    Post subject: Reply with quote

I was just refering to that new way of creating controls, using the Control.Add("type") method, like this:

Code:

Break On

$System = CreateObject("Kixtart.System")

$Form = $System.Form()
$Form.Text = "Controls"
$Form.ClientWidth = 640
$Form.ClientHeight = 480

$StatusBar = $Form.Controls.Add("StatusBar")
$StatusBar.Text = "Ready"

$SplitContainer = $Form.Controls.Add("SplitContainer")
$SplitContainer.Dock = "Fill"
$SplitContainer.Panel1.BorderStyle = 2
$SplitContainer.Panel2.BorderStyle = 2

$SmallClasses =
"Button","CheckBox","ComboBox","GroupBox","HyperLink","Label","Panel","PictureBox",
"ProgressBar","RadioButton","ToolButton","TrackBar","TextBox","RichTextBox"

$LargeClasses =
"ListBox","ListView","TabControl","TreeView"

/*"GridView"*/


$Top = 5
$Left = 10

For Each $Class In $SmallClasses

 $Label = $SplitContainer.Panel1.Controls.Add("Label")
 $Label.Width = 80
 $Label.Height = 25
 $Label.Left = $Left
 $Label.Top = $Top
 $Label.Text = $Class + ":"

 $Control = $SplitContainer.Panel1.Controls.Add($Class)
 $Control.Width = 100
 $Control.Height = 20
 $Control.Left = $Label.Right + 10
 $Control.Top = $Label.Top
 $Control.Text = $Control.Name
 
 $Top = $Label.Bottom + 5

Next


$Top = 10
$Left = 10

For Each $Class In $LargeClasses

 $Label = $SplitContainer.Panel2.Controls.Add("Label")
 $Label.Width = 80
 $Label.Height = 50
 $Label.Left = $Left
 $Label.Top = $Top
 $Label.Text = $Class + ":"

 $Control = $SplitContainer.Panel2.Controls.Add($Class)
 $Control.Width = 100
 $Control.Height = 50
 $Control.Left = $Label.Right + 10
 $Control.Top = $Label.Top
 $Control.Text = $Control.Name
 
 $Top = $Label.Bottom + 5

Next


$Form.Center
$Form.Show

While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function ButtonClick()
 ?"Text=" $System.Version
EndFunction
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group