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

StatusBar with StatusBarInfoPanel and ProgressBar Example

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


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Fri Feb 16, 2007 10:44 pm    Post subject: StatusBar with StatusBarInfoPanel and ProgressBar Example Reply with quote

A few days ago a board member asked for an example of a 'StatusBar with StatusBarInfoPanel and ProgressBar', here it is:
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

;region Setup Varibles
Global $System,$MainForm
Dim $MainPanel,$nul,$StatusBar,$StatusBarInfoPnl,$ProgressBarPanel,$ProgressBar,$StartBtn

;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
;endregion Setup Varibles

;region MainForm
$MainForm = $System.Form()
$MainForm.StartPosition = $System.FormStartPosition_CenterScreen
$MainForm.Size = $System.Size(600,400) ;(Width,Height)
$MainForm.SizeChanged = 'OnFormSizeChange()'
$MainForm.Tag = $System.Size(310,200) ;(Width,Height)
$MainForm.Text = 'StatusBar / ProgressBar Example'

$MainPanel = $System.Panel()
$MainPanel.Dock = $System.DockStyle_Fill
$nul = $MainForm.Controls.Add($MainPanel)

;region Status Bar
$StatusBar = $System.StatusBar()
$StatusBar.ShowPanels = -1  ;True
$StatusBar.Name = 'StatusBar'
$nul = $MainForm.Controls.Add($StatusBar)

$StatusBarInfoPnl = $System.StatusBarPanel()
$StatusBarInfoPnl.AutoSize = $System.StatusBarPanelAutoSize_Spring
$StatusBarInfoPnl.BorderStyle = $System.StatusBarPanelBorderStyle_Sunken
$StatusBarInfoPnl.MinWidth = 100
$StatusBarInfoPnl.Text = 'Ready...'
$StatusBarInfoPnl.Width = 475
$nul = $StatusBar.Panels.Add($StatusBarInfoPnl)

$ProgressBarPanel = $System.StatusBarPanel()
$ProgressBarPanel.BorderStyle = $System.StatusBarPanelBorderStyle_Sunken
$ProgressBarPanel.Width = 102
$nul = $StatusBar.Panels.Add($ProgressBarPanel)

$ProgressBar = $System.ProgressBar()
$ProgressBar.Anchor = 9  ;Top,Right
$ProgressBar.Left = $StatusBar.Width-116
$ProgressBar.Height = 20
$ProgressBar.Name = 'ProgressBar'
$ProgressBar.Top = 2
$ProgressBar.Visible = 'False'
$nul = $StatusBar.Controls.Add($ProgressBar)
;endregion

$StartBtn = $System.Button()
$StartBtn.Anchor = $System.AnchorStyles_None
$StartBtn.Click = 'Start()'
$StartBtn.Name = 'StartBtn'
$StartBtn.Text = 'Start'
$nul = $MainPanel.Controls.Add($StartBtn)

$StartBtn.Center
$MainForm.Show  ;Displays the Form

While $MainForm.Visible
   $Nul = Execute($MainForm.DoEvents())
Loop
Exit 0
;endregion

Function AdvanceProgressBar($Step,Optional $Text)
  Dim $ProgressBar,$StatusBar,$StatusBarInfoPnl,$Count
   
   $ProgressBar = $MainForm.FindControl('ProgressBar')
   $StatusBar = $MainForm.FindControl('StatusBar')
   $StatusBarInfoPnl = $StatusBar.Panels.Item(0)
   $Count = $ProgressBar.Value
   If $Step = 0
    If $Text = ''
      $StatusBarInfoPnl.Text = ''
      Else
         $StatusBarInfoPnl.Text = $Text
    EndIf
    $ProgressBar.Value = 0
    $Count = 0
  Else
    $Count = $Count + $Step
    If $Count > 100
        $Count = 0
    EndIf
    $StatusBarInfoPnl.Text = $Text
    $ProgressBar.Value = $Count
    Sleep 0.1
  EndIf
EndFunction

Function Start()
   Dim $ProgressBar,$StartBtn,$Array,$Step
   
   $Array = 'Step 1','Step 2','Step 3','Step 4','Step 5','Step 6','Step 7','Step 8','Step 9','Step 10'
   
   $ProgressBar = $MainForm.FindControl('ProgressBar')
   $ProgressBar.Visible = 'True'
   $StartBtn = $MainForm.FindControl('StartBtn')
   $StartBtn.Enabled = 'False'
   For Each $Step in $Array
      AdvanceProgressBar(10,$Step)
      Sleep 0.5
   Next   
   $StartBtn.Enabled = 'True'
   AdvanceProgressBar(0,'Ready...')
   $ProgressBar.Visible = 'False'
EndFunction

Function OnFormSizeChange()
   Dim $MainForm_Size
   ;Retrieve the original 'MainForm.Size' from 'MainForm.Tag'
   $MainForm_Size = $MainForm.Tag
   If $MainForm.Width < $MainForm_Size.Width And Not($MainForm.WindowState = 1)
    $MainForm.Width = $MainForm_Size.Width
  EndIf
  If $MainForm.Height < $MainForm_Size.Height And Not($MainForm.WindowState = 1)
    $MainForm.Height = $MainForm_Size.Height
  EndIf
EndFunction

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Feb 17, 2007 12:11 am    Post subject: Reply with quote

Boy, I learn something new every day around here. Didn't know one could do that. Nice.

-Shawn
Back to top
View user's profile Send private message
masken
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 14 Mar 2003
Posts: 202
Location: Gothenburg, Sweden

PostPosted: Sat Feb 17, 2007 11:09 am    Post subject: Reply with quote

Really nice! Comes to direct use for me Smile

ps
Shouldn't we make a "KiXforms.NET Sample code" forum and collect all of these things in? Just samples of different things like buttons, listviews, toolbars etc?
Back to top
View user's profile Send private message MSN Messenger
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Sat Feb 17, 2007 1:19 pm    Post subject: Reply with quote

masken that is a grand idea, i second that motion
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Feb 17, 2007 4:21 pm    Post subject: Reply with quote

I third that motion. Great idea. Will talk to Rod about.
Back to top
View user's profile Send private message
masken
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 14 Mar 2003
Posts: 202
Location: Gothenburg, Sweden

PostPosted: Sat Mar 03, 2007 6:06 pm    Post subject: Reply with quote

benny (or shawn), I don't quite get how to work with "dynamic widths" with the Status Bar. I understand that the leftmost text-part panel is auto-sized and that the initial width really doesn't make a difference.

But what I don't get is the correlation between $ProgressBarPanel.Width = 102 and $ProgressBar.Left = $StatusBar.Width-116. Where's the width of the status bar itself specified, and why doesn't the numbers match up? Wink I suspect it's because of the little tab in the bottom right corner of the form?
Back to top
View user's profile Send private message MSN Messenger
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Sat Mar 03, 2007 10:14 pm    Post subject: Reply with quote

The reason is that the $ProgressBarPanel.Width has a graphical overlay that makes the inturnal dimentions a little smaller, so the $ProgressBarPanel.Width is set a little wider so the standard size of the $ProgressBar (100) will fit nicely inside (it is not realy inside but rather layed over the top).

The $StatusBar.Width can change because the form is sizable. The 116 is the width of the standard ProgressBar (100) + the resize form corner. Because the form is sizable and the $ProgressBarPanel.Left will change with the width of the Form you have to work with the $ProgressBar.Left so that you can always place the $ProgressBar where it belongs.

With $ProgressBar.Left = $StatusBar.Width-116 equation, the $StatusBar.Width is used like a variable. It will always go and get the Width of the Statusbar to calculate $ProgressBar.Left.

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
masken
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 14 Mar 2003
Posts: 202
Location: Gothenburg, Sweden

PostPosted: Sun Mar 04, 2007 3:52 pm    Post subject: Reply with quote

Alrighty, thanks alot m8, think I got hold of it now Smile
Back to top
View user's profile Send private message MSN Messenger
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