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

Drag-n-Drop TreeView Node

 
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: Thu Mar 19, 2009 7:09 pm    Post subject: Drag-n-Drop TreeView Node Reply with quote

Woot!
Shawn recently added a new method to KiXforms.Net 3.2.16 , so rush over and get your new version now!

The New Method is GetNodeAt()

With this new Method you can do kewl stuff like this:
Code:

;region Setup Variables
Break On
$System = CreateObject("Kixforms.System")
If Not $System
  $nul = MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.", "Error", 16)
  Quit()
EndIf
$nul = $System.Application.EnableVisualStyles

Global $MovingDelta

$TreeViewNodeArray = Split('Node 0,Node 1,Node 2,Node 3,Node 4', ',')
;endregion

;region Main Form
$Form = $System.Form()
$Form.StartPosition = 1  ;FormStartPosition_CenterScreen
$Form.Size = $System.Size(400, 300) ;(Width,Height)
$Form.Text = "Drag-n-Drop TreeView Node"

$TreeView = $System.TreeView()
$TreeView.Dock = 3  ;Left
$TreeView.MouseDown = "CheckForRightMouseClick($$System.Sender)"
$nul = $Form.Controls.Add($TreeView)

For Each $Node in $TreeViewNodeArray
  $TreeViewNode = $TreeView.Nodes.Add($System.TreeNode($Node))
Next

$TreeView.BeginUpdate
$TreeView.SelectedNode = $TreeView.Nodes.Item(0)
$TreeView.Tag = $TreeView.SelectedNode
$TreeView.EndUpdate

$Form.Show  ;Displays the Form

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

;region TreeView Functions
Function CheckForRightMouseClick($Sender)
  $Button = $Sender.MouseDownEventArgs.Button
  $CursorXY = $Sender.PointToClient($Sender.MousePosition)
 
  If $Button = $System.MouseButtons_Left
    $Node = $Sender.GetNodeAt($CursorXY.x, $CursorXY.y)
    If $Node
      $TreeView.SelectedNode = $Node
      $TreeView.Tag = $Node
      $TreeView.BeginUpdate
      $TreeViewNode.Tag = $TreeView.SelectedNode
      $TreeViewNode = $System.Label()
      $TreeViewNode.AutoSize = -1  ;True
      $TreeViewNode.BackColor = $TreeView.BackColor
      $TreeViewNode.BorderStyle = 1  ;FixedSingle
      $TreeViewNode.MouseMove = "ControlMove($$System.sender)"
      $TreeViewNode.MouseUp = "ControlMouseUp($$System.sender)"
      $TreeViewNode.Text = $TreeView.SelectedNode.Text
      $TreeViewNode.TextAlign = 16  ;MiddleLeft
      $TreeView.SelectedNode.Remove
      $TreeView.EndUpdate
      $nul = $Form.Controls.Add($TreeViewNode)
     
      $CursorXY = $Sender.PointToClient($Sender.MousePosition)
      $TreeViewNode.Top = $CursorXY.y - ($TreeViewNode.Height /2)
      $TreeViewNode.Left = $CursorXY.x - ($TreeViewNode.Width /2)
      $TreeViewNode.BringToFront
      $MovingDelta = $TreeViewNode.PointToClient($TreeViewNode.MousePosition)
    EndIf
  EndIf
EndFunction

Function ControlMove($Sender)
  If $Sender And ($Sender.MouseButtons & $System.MouseButtons_Left)
    $pt1 = $Form.PointToClient($Form.MousePosition)
    If ($pt1.x - $MovingDelta.x) >= 0
      $Sender.Left = $pt1.x - $MovingDelta.x
    EndIf
    If ($pt1.y - $MovingDelta.y) >= 0
      $Sender.Top = $pt1.y - $MovingDelta.y
    EndIf
    $Node = $TreeView.GetNodeAt($Sender.Left, $Sender.Top)
    $TreeView.SelectedNode = $Node
  EndIf
EndFunction

Function ControlMouseUp($Sender)
  $Node = $TreeView.Tag
  If $Sender.Left > $TreeView.Left And $Sender.Left < $TreeView.Right And $Sender.Top > $TreeView.Top And $Sender.Top < $TreeView.Bottom
    $nul = $TreeView.Nodes.Insert($TreeView.SelectedNode.Index, $Node)
  EndIf
  $Sender.Dispose
EndFunction
;endregion

_________________
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
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