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

Help to remove picturebox objects

 
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting
View previous topic :: View next topic  
Author Message
acmp
KiXforms Dabbler
KiXforms Dabbler


Joined: 22 Mar 2007
Posts: 12

PostPosted: Thu Jun 12, 2008 8:06 am    Post subject: Help to remove picturebox objects Reply with quote

Here's the thing,

I have a simple form that reads some numbers and turns them into a bar chart by using pictureboxes to make the bars.

This works well. Then I need to change them for some new data. This is where the problems start.

If I hide them with .visible=false, reset them, then show them, they start to lose their fill colour (same thing happens if I don't hide them) after around 5-9 iterations. So I want to remove the bars, then re-create them.

Here's some code...

Code:
For $i = 0 to $ub
   $val=CDbl($bars[$i])
   Select
      Case $val > $red
         $barcol = 255, 20, 20
      Case $val > $amber
         $barcol = 200, 200, 20
      Case 1
         $barcol = 50, 255, 50
   EndSelect
   $ = Execute("$$bar" + $i + " = $$GroupBox1.Controls.PictureBox()")
   $height = CInt(((CDbl($bars[ $i ]) - $small) * $adjust) + 10)
   $ = Execute("$$bar" + $i + ".size = $$inc, $$height")
   $ = Execute("$$bar" + $i + ".location = (10 + ($$i * $$inc)), 390 - $height")
   $ = Execute("$$bar" + $i + ".tooltip = ' '+FormatNumber($$bars[ $$i ],0,0,0,3)")
   $ = Execute("$$bar" + $i + ".backcolor = $$barcol")
   $ = Execute("$$bar" + $i + ".visible = true")
Next


I pass the array of Bars and set the $red/$amber to limits to change the bar colour.

I keep the ubound for the array in a var so that I can address the bars next time through to remove them, currently I'm just doing $ = Execute('$$bar' + $j + '.visible=false') but this doesn't work well after a few iterations.

I've been playing with .remove and .clear but can't work it out.

Help?
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Thu Jun 12, 2008 3:18 pm    Post subject: Reply with quote

I would suggest you stick with a pre-defined (pre-built) number of pictureboxes - instead of re-creating them (and overlapping them) everytime the data changes. Here's a quick example, of what I mean - it uses control arrays instead of "executing" just cause it easier for (me) to wrap my mind around them ...

Code:

Break On

$System = CreateObject("Kixtart.System")

$Form = $System.Form()
$Form.Width = 640
$Form.Height = 480

$GroupBox = $Form.GroupBox()
$GroupBox.Left = 10
$GroupBox.Top = 10
$GroupBox.Width = $Form.ClientWidth - 20
$GroupBox.Height = $Form.ClientHeight / 2
$GroupBox.Text = "Bar Chart"

Global $Bars[10]

Global $Data[5]
$Data[0] = 40,50,60,25,80,90,65,40,100,60,60
$Data[1] = 60,55,50,45,50,50,90,90,90,30,90
$Data[2] = 60,30,50,50,20,80,85,95,90,95,75
$Data[3] = 30,25,30,35,40,35,35,25,20,80,22
$Data[4] = 30,25,30,35,40,45,50,55,60,65,70
$Data[5] = 80,75,70,65,60,20,50,45,40,35,30

$CurrentIndex = 0

$NextButton = $Form.Button()
$NextButton.Left = 10
$NextButton.Top = $GroupBox.Bottom + 5
$NextButton.Text = "Next Chart>"
$NextButton.OnClick = "NextButton_Click()"

CreateBarChart()

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

Exit 0

Function NextButton_Click()

 $i = 0

 For Each $Value in $Data[$CurrentIndex]
  $Bars[$i].Top = $Value
  $Bars[$i].Height = $GroupBox.ClientHeight - $Bars[$i].Top - 20
  Select
   Case $Value < 25
    $Bars[$i].BackColor = "Red"
   Case $Value < 75
    $Bars[$i].BackColor = "Yellow"
   Case 1
    $Bars[$i].BackColor = "PaleGreen"
  EndSelect
  $i = $i + 1
 Next

 $CurrentIndex = $CurrentIndex + 1
 If $CurrentIndex > UBound($Data)
  $CurrentIndex = 0
 Endif

EndFunction

Function CreateBarChart()

 $Left = 10

 For $i = 0 To UBound($Data[0])
  $Bars[$i] = $GroupBox.PictureBox()
  $Bars[$i].Left = $Left
  $Bars[$i].Top = 20
  $Bars[$i].Width = 40
  $Bars[$i].Height = $GroupBox.ClientHeight - 40
  $Bars[$i].BackColor = "PaleGreen"
  $Left = $Bars[$i].Right + 10
 Next

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: Thu Jun 12, 2008 3:21 pm    Post subject: Reply with quote

Other suggestions - your idea to hide then reshow them would work well here - and I would suggest using Labels instead of Pictureboxes - they're probably faster and less resource hungry.
Back to top
View user's profile Send private message
acmp
KiXforms Dabbler
KiXforms Dabbler


Joined: 22 Mar 2007
Posts: 12

PostPosted: Thu Jun 12, 2008 7:19 pm    Post subject: Reply with quote

I like the idea of an array object containing the object, not thought of that.

I'll give it a go and see how it behaves. I really didn't like using the execute command, looks like bad code to me.
Back to top
View user's profile Send private message
acmp
KiXforms Dabbler
KiXforms Dabbler


Joined: 22 Mar 2007
Posts: 12

PostPosted: Fri Jun 13, 2008 9:44 am    Post subject: Reply with quote

I've implemented the array idea. I looks and feels a lot better than the execute code, thanks.

With picture boxes it behaves the same as before Sad

I have changed them to labels though and it works fine Smile

Though I'm happy with the form working I'd be happier if I could remove the unwanted elements properly rather than just hiding them. The reason is that the data strings are of different lengths and so the number of bars I want change. I can live with it though

I did try to redim the array then refresh the form but it remembers the bars even though they don't appear to exist in the code.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting 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