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

KiXforms.NET Floating Toolbar 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: Sun Oct 16, 2005 9:15 pm    Post subject: KiXforms.NET Floating Toolbar Example Reply with quote

Things have slowed down with KFD, so I thought i would have a little fun and offer an example of a floating Toolbar.

In this example you will be able to left click and drag the Toolbar. You can leave it floating on top of the form or drag and dock it to the top, left, right or bottom.

The code that i use to move the Toolbar is basicly the same code i use in KFD, to be able to move/resize controls.

Code:
Break On
$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf

;region Main Form
$MainForm = $System.Form()
$MainForm.StartPosition = 1  ;FormStartPosition_CenterScreen
$MainForm.Size = $System.Size(608,434) ;(Width,Height)
$MainForm.Text = "Floating Toolbar"

$MainPanel = $System.Panel()
$MainPanel.Dock = 5  ;Fill
$nul = $MainForm.Controls.Add($MainPanel)

$MainSubPanel = $System.Panel()
$MainSubPanel.Dock = 5  ;Fill
$nul = $MainPanel.Controls.Add($MainSubPanel)

;Region Toolbar
$ToolbarPanel = $System.Panel()
$ToolbarPanel.Dock = 1  ;Top
$ToolbarPanel.Height = 40
$ToolbarPanel.Name = "toolbar"
$name = $ToolbarPanel.Name
$ToolbarPanel.MouseMove = "ControlMouseMove($name)"
$ToolbarPanel.MouseDown = "ControlMouseDown($name)"
$ToolbarPanel.MouseUp = "ControlMouseUp($name)"
$nul = $MainPanel.Controls.Add($ToolbarPanel)

$ToolbarHolderPanel = $System.Panel()
$ToolbarHolderPanel.Dock = 4  ;Right
$ToolbarHolderPanel.Width = $ToolbarPanel.Width - 15
$nul = $ToolbarPanel.Controls.Add($ToolbarHolderPanel)

$Toolbar = $System.Toolbar()
$Toolbar.ButtonSize = $System.Size(28,36) ;(Width,Height)
$Toolbar.Divider = 0  ;False
$nul = $ToolbarHolderPanel.Controls.Add($Toolbar)

;region Toolbar Buttons
$btn1 = $Toolbar.Buttons.Add($System.ToolBarButton("btn1"))
$btn1.ParitalPush = 0  ;False
$btn1.Pushed = 0  ;False
$btn1.Style = 1  ;PushButton
$btn1.Text = "btn1"

$btn2 = $Toolbar.Buttons.Add($System.ToolBarButton("btn2"))
$btn2.ParitalPush = 0  ;False
$btn2.Pushed = 0  ;False
$btn2.Style = 1  ;PushButton
$btn2.Text = "btn2"

$btn3 = $Toolbar.Buttons.Add($System.ToolBarButton("btn3"))
$btn3.ParitalPush = 0  ;False
$btn3.Pushed = 0  ;False
$btn3.Style = 1  ;PushButton
$btn3.Text = "btn3"
;endregion
;endregion

;region MainMenu
$MainMenu = $System.MainMenu()

$File = $MainMenu.MenuItems.Add($System.MenuItem("File"))

$Exit = $File.MenuItems.Add($System.MenuItem("Exit"))
$Exit.Click = "ExitForm()"

$MainForm.Menu = $MainMenu
;endregion

;region Statusbar
$Statusbar = $System.Statusbar()
$Statusbar.Text = "Ready"
$nul = $MainForm.Controls.Add($Statusbar)
;endregion

;region MainSubPanel
$RightPanel = $System.Panel()
$RightPanel.Dock = 5  ;Fill
$nul = $MainSubPanel.Controls.Add($RightPanel)

$MainSplitter = $System.Splitter()
$nul = $MainSubPanel.Controls.Add($MainSplitter)

$LeftPanel = $System.Panel()
$LeftPanel.Dock = 3  ;Left
$LeftPanel.Width = 168
$nul = $MainSubPanel.Controls.Add($LeftPanel)

;region TreeView
$TreeView1 = $System.TreeView()
$TreeView1.Dock = 5  ;Fill
$nul = $LeftPanel.Controls.Add($TreeView1)

$TreeView1RootNode = $TreeView1.Nodes.Add($System.TreeNode("RootNode"))

$TreeView1Node0 = $TreeView1RootNode.Nodes.Add($System.TreeNode("Node0"))
$TreeView1Node1 = $TreeView1RootNode.Nodes.Add($System.TreeNode("Node1"))
$TreeView1Node2 = $TreeView1RootNode.Nodes.Add($System.TreeNode("Node2"))
$TreeView1Node3 = $TreeView1RootNode.Nodes.Add($System.TreeNode("Node3"))
$TreeView1Node4 = $TreeView1Node3.Nodes.Add($System.TreeNode("Node4"))
;endregion

;region ListView
$ListView1 = $System.ListView()
$ListView1.Dock = 5  ;Fill
$ListView1.View = $System.View_Details
$nul = $RightPanel.Controls.Add($ListView1)

$ListView1Column0 = $ListView1.Columns.Add($System.ColumnHeader("Item Column",100,$System.HorizontalAlignment_Left))
$ListView1Column1 = $ListView1.Columns.Add($System.ColumnHeader("Column A",100,$System.HorizontalAlignment_Center))
$ListView1Column2 = $ListView1.Columns.Add($System.ColumnHeader("Column B",100,$System.HorizontalAlignment_Right))

$ListView1Item00 = $ListView1.Items.Add($System.ListViewItem("Item 1"))
$ListView1Item01 = $ListView1.Items.Item(0).SubItems.Add($System.ListViewSubItem("Item 1A"))
$ListView1Item02 = $ListView1.Items.Item(0).SubItems.Add($System.ListViewSubItem("Item 1B"))

$ListView1Item10 = $ListView1.Items.Add($System.ListViewItem("Item 2"))
$ListView1Item11 = $ListView1.Items.Item(1).SubItems.Add($System.ListViewSubItem("Item 2A"))
$ListView1Item12 = $ListView1.Items.Item(1).SubItems.Add($System.ListViewSubItem("Item 2B"))

$ListView1Item20 = $ListView1.Items.Add($System.ListViewItem("Item 3"))
$ListView1Item21 = $ListView1.Items.Item(2).SubItems.Add($System.ListViewSubItem("Item 3A"))
$ListView1Item22 = $ListView1.Items.Item(2).SubItems.Add($System.ListViewSubItem("Item 3B"))
;endregion
;endregion

$MainForm.Show  ;Displays the Form


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

Function ControlMouseMove($name)

   Dim $ActiveControl,$CursorXY
   
   $ActiveControl = $MainForm.FindControl($name)
   If Not $ActiveControl
      Return
   EndIf
   $CursorXY = $MainPanel.PointToClient($MainPanel.MousePosition)
   If $ActiveControl.Dock = $System.DockStyle_Left Or $ActiveControl.Dock = $System.DockStyle_Right
      If ($CursorXY.y > ($ActiveControl.Top) And $CursorXY.y < ($ActiveControl.Top+15)) And ($CursorXY.x > ($ActiveControl.Left) And $CursorXY.x < ($ActiveControl.Right))
         $ActiveControl.Cursor = $System.Cursors.SizeAll
         If ($ActiveControl.MouseButtons & $System.MouseButtons_Left)
            $ActiveControl.MouseMove = "ControlMove()"
         EndIf
      Else
         $ActiveControl.Cursor = $System.Cursors.Default
      EndIf
   Else; $ActiveControl.Dock = $System.DockStyle_Top; Or $ActiveControl.Dock = $System.DockStyle_Bottom
      If ($CursorXY.x > ($ActiveControl.Left) And $CursorXY.x < ($ActiveControl.Left+15)) And ($CursorXY.y > ($ActiveControl.Top) And $CursorXY.y < ($ActiveControl.Bottom))
         $ActiveControl.Cursor = $System.Cursors.SizeAll
         If ($ActiveControl.MouseButtons & $System.MouseButtons_Left)
            $ActiveControl.MouseMove = "ControlMove()"
         EndIf
      Else
         $ActiveControl.Cursor = $System.Cursors.Default
      EndIf
   EndIf
   
EndFunction

Function ControlMouseDown($name)

   Dim $ActiveControl,$CursorXY
   
   $MovingControl = 0
   
   $ActiveControl = $MainForm.FindControl($name)
   If Not $ActiveControl
      Return
   EndIf
   
   If Not($ActiveControl.MouseButtons & $System.MouseButtons_Left)
      Return
   EndIf
   
   $ActiveControl.Cursor = $System.Cursors.Default
   $CursorXY = $MainPanel.PointToClient($MainPanel.MousePosition)
   
   If $ActiveControl.Dock = $System.DockStyle_Left Or $ActiveControl.Dock = $System.DockStyle_Right
      If ($CursorXY.y > ($ActiveControl.Top) And $CursorXY.y < ($ActiveControl.Top+15)) And ($CursorXY.x > ($ActiveControl.Left) And $CursorXY.x < ($ActiveControl.Right))
         $ActiveControl.Cursor = $System.Cursors.SizeAll
         $ActiveControl.BringToFront
         $MovingControl = $ActiveControl
         $MovingDelta = $MovingControl.PointToClient($MovingControl.MousePosition)
         $MovingControlLeft = $MovingControl.Left
         $MovingControlTop = $MovingControl.Top
         $MovingControl.Dock = $System.DockStyle_None
         $MovingControl.Left = $MovingControlLeft
         $MovingControl.Top = $MovingControlTop
         $MovingControl.Height = 40
         $MovingControl.Width = 130
         $ToolbarHolderPanel.Dock = $System.DockStyle_Right
         $ToolbarHolderPanel.Width = $ToolbarPanel.Width - 15
         $Toolbar.Dock = $System.DockStyle_Top
      Else
         $ActiveControl.Cursor = $System.Cursors.Default
      EndIf
   Else; $ActiveControl.Dock = $System.DockStyle_Top; Or $ActiveControl.Dock = $System.DockStyle_Bottom
      If ($CursorXY.x > ($ActiveControl.Left) And $CursorXY.x < ($ActiveControl.Left+15)) And ($CursorXY.y > ($ActiveControl.Top) And $CursorXY.y < ($ActiveControl.Bottom))
         $ActiveControl.Cursor = $System.Cursors.SizeAll
         $ActiveControl.BringToFront
         $MovingControl = $ActiveControl
         $MovingDelta = $MovingControl.PointToClient($MovingControl.MousePosition)
         $MovingControlLeft = $MovingControl.Left
         $MovingControlTop = $MovingControl.Top
         $MovingControl.Dock = $System.DockStyle_None
         $MovingControl.Left = $MovingControlLeft
         $MovingControl.Top = $MovingControlTop
         $MovingControl.Height = 40
         $MovingControl.Width = 130
         $ToolbarHolderPanel.Dock = $System.DockStyle_Right
         $ToolbarHolderPanel.Width = $ToolbarPanel.Width - 15
         $Toolbar.Dock = $System.DockStyle_Top
      Else
         $ActiveControl.Cursor = $System.Cursors.Default
      EndIf
   EndIf
   
EndFunction

Function ControlMouseUp($name)
   
   $ActiveControl = $MainForm.FindControl($name)
   $ActiveControl.Cursor = $System.Cursors.Default
   $MovingControl.Cursor = $System.Cursors.Default
   Select
      Case $MovingControl.Top <= 3                                       ;Top
         $MovingControl.Left = 0
         $MovingControl.BorderStyle = $System.BorderStyle_None
         $MovingControl.SendToBack
         $MovingControl.Dock = $System.DockStyle_Top
         $ToolbarHolderPanel.Dock = $System.DockStyle_Right
         $ToolbarHolderPanel.Width = $ToolbarPanel.Width - 15
         $Toolbar.Dock = $System.DockStyle_Top
      Case $MovingControl.Top > 3 And $MovingControl.Left <= 3            ;Left
         $MovingControl.Left = 0
         $MovingControl.BorderStyle = $System.BorderStyle_None
         $MovingControl.SendToBack
         $MovingControl.Dock = $System.DockStyle_Left
         $ToolbarHolderPanel.Dock = $System.DockStyle_Bottom
         $ToolbarHolderPanel.Height = $ToolbarPanel.Height - 15
         $MovingControl.Width = 28
         $Toolbar.Dock = $System.DockStyle_Left
      Case $MovingControl.Top >= $MainPanel.Bottom - 45                  ;Bottom
         $MovingControl.Top = 0
         $MovingControl.BorderStyle = $System.BorderStyle_None
         $MovingControl.SendToBack
         $MovingControl.Dock = $System.DockStyle_Bottom
         $ToolbarHolderPanel.Dock = $System.DockStyle_Right
         $ToolbarHolderPanel.Width = $ToolbarPanel.Width - 15
         $Toolbar.Dock = $System.DockStyle_Top
      Case $MovingControl.Left > $MainPanel.Width - 50                  ;Right
         $MovingControl.Top = 0
         $MovingControl.BorderStyle = $System.BorderStyle_None
         $MovingControl.SendToBack
         $MovingControl.Dock = $System.DockStyle_Right
         $ToolbarHolderPanel.Dock = $System.DockStyle_Bottom
         $ToolbarHolderPanel.Height = $ToolbarPanel.Height - 15
         $MovingControl.Width = 28
         $Toolbar.Dock = $System.DockStyle_Right
   EndSelect
   $MovingControl.MouseMove = "ControlMouseMove($name)"
   $MovingControl = 0
   
EndFunction

Function ControlMove()
   
   If $MovingControl And ($MovingControl.MouseButtons & $System.MouseButtons_Left)
      $MovingControl.BorderStyle = $System.BorderStyle_FixedSingle
      $pt1 = $MainPanel.PointToClient($MainPanel.MousePosition)
      $MovingControl.Cursor = $System.Cursors.SizeAll
      If ($pt1.x - $MovingDelta.x) >= 0
         $mX = $pt1.x - $MovingDelta.x
      EndIf
      If ($pt1.y - $MovingDelta.y) >= 0
         $mY = $pt1.y - $MovingDelta.y
      EndIf
      $MovingControl.Left = $mX
      $MovingControl.Top = $mY
   EndIf
   
EndFunction

Function ExitForm()
   $MainForm.Close
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
ntdoc
KiXforms Supporter
KiXforms Supporter


Joined: 05 Mar 2003
Posts: 77
Location: Mouse Country

PostPosted: Wed Nov 09, 2005 10:00 am    Post subject: Reply with quote

Benny,

Tried your example but couldn't get it to work as you described. After clicking the crap out of the form it did finally give an error and quit.


ERROR : Error in expression.!
Script: C:\Download\float.kix
Line : 236
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
benny69
KiXforms Advocate
KiXforms Advocate


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

PostPosted: Thu Nov 10, 2005 12:59 pm    Post subject: Reply with quote

hmmm, with the toolbar docked to the top, and you place the mouse to the left of the toolbarbuttons does the cursor change to sizeall?
_________________
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
ntdoc
KiXforms Supporter
KiXforms Supporter


Joined: 05 Mar 2003
Posts: 77
Location: Mouse Country

PostPosted: Fri Nov 11, 2005 4:55 am    Post subject: Reply with quote

Hmmm... I'm sorry maybe I missed how you move it. Thought I could just click on it and move it.

Will give it a try again tomorrow.
Back to top
View user's profile Send private message Visit poster's website AIM Address 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