B4J Question [SOLVED] how can i drag with mouse borderless window ?

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
hello everyone !!
i would like to create some borderless window, and at the top I would like to add a Pane so I can click and drag the window, is this possible?

y46EL.gif
 

Sandman

Expert
Licensed User
Longtime User
Not sure if this matters to you, but if your app is meant to run mainly on Linux: All windows can be moved by simply pressing alt and dragging somewhere in the window. (Pretty great feature, by the way.)
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
you can play with the different events of the pane.

B4X:
private Sub mainpane_MouseDragged (EventData As MouseEvent)
    frm.WindowLeft = EventData.X
    frm.WindowTop = EventData.Y
End Sub
something like that
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
And if you want a borderless panel to follow a header panel..
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Pane1 As Pane
    Private Pane2 As Pane
    
    Private pointInPanelX As Float
    Private pointInPanelY As Float
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Private Sub Pane1_MouseDragged (EventData As MouseEvent)
    Pane1.Left = Pane1.Left + (EventData.X - pointInPanelX)
    Pane1.Top = Pane1.Top  + (EventData.Y - pointInPanelY)
    Pane2.Left = Pane1.Left
    Pane2.Top = Pane1.Top + Pane1.height
End Sub

Private Sub Pane1_MousePressed (EventData As MouseEvent)
    pointInPanelX = EventData.X
    pointInPanelY = EventData.Y
End Sub
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
And if you want a borderless panel to follow a header panel..
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Pane1 As Pane
    Private Pane2 As Pane
   
    Private pointInPanelX As Float
    Private pointInPanelY As Float
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Private Sub Pane1_MouseDragged (EventData As MouseEvent)
    Pane1.Left = Pane1.Left + (EventData.X - pointInPanelX)
    Pane1.Top = Pane1.Top  + (EventData.Y - pointInPanelY)
    Pane2.Left = Pane1.Left
    Pane2.Top = Pane1.Top + Pane1.height
End Sub

Private Sub Pane1_MousePressed (EventData As MouseEvent)
    pointInPanelX = EventData.X
    pointInPanelY = EventData.Y
End Sub

Have a bug , im trying using this code :
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
  
    Private Button1 As Button

    Private SystemMenu As Pane
    
    Private pointInPanelX As Float
    Private pointInPanelY As Float
    Dim GameForm As Form
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("game")
    GameForm = B4XPages.GetNativeParent(Me)
    GameForm.SetFormStyle("UNDECORATED")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Sub Button1_Click
    B4XPages.ShowPageAndRemovePreviousPages("mainpage")
    
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub

    Log("Game CloseRequest")
  
    ExitApplication
    Return True
  
End Sub

Private Sub SystemMenu_MouseDragged (EventData As MouseEvent)
    
    
    GameForm.WindowLeft = GameForm.WindowLeft + (EventData.X - pointInPanelX)
    GameForm.WindowTop = GameForm.WindowTop  + (EventData.Y - pointInPanelY)
    
    Log(GameForm.WindowLeft)
    Log(GameForm.WindowTop)
    
End Sub

Private Sub SystemMenu_MousePressed (EventData As MouseEvent)
    pointInPanelX = EventData.X
    pointInPanelY = EventData.Y
End Sub
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
The difference between the two sets of code is that you are modifying left and top of GameForm in the SystemMenu_MouseDragged event.

In the working code, the two are the same.

In other words...
B4X:
Private Sub SystemMenu_MouseDragged (EventData As MouseEvent)
   
   
    SystemMenu.WindowLeft = SystemMenu.WindowLeft + (EventData.X - pointInPanelX)
    SystemMenu.WindowTop = SystemMenu.WindowTop  + (EventData.Y - pointInPanelY)
   
    Log(SystemMenu.WindowLeft)
    Log(SystemMenu.WindowTop)
   
End Sub
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
Solved !! Thanks by you help . found this topic : TOPIC

B4X:
Sub SystemMenu_MousePressed (EventData As MouseEvent)
    downX = EventData.X
    downY = EventData.Y
End Sub

Sub SystemMenu_MouseDragged (EventData As MouseEvent)
    Dim jo As JavaObject = EventData
    B4XPages.GetNativeParent(Me).WindowLeft = jo.RunMethod("getScreenX", Null) - downX
    B4XPages.GetNativeParent(Me).WindowTop  = jo.RunMethod("getScreenY", Null) - downY
End Sub
 
Upvote 0
Top