### Create movable non-modal undecorated Form

Create a movable Non-Modal Undecorated Form.
The form is created using the B4J Visual Designer.
Form Layout
The form style is set as UNDECORATED (in the Form code) with border properties: color (blue), width 2 and corner radius 2.
A View Label is placed at the top of the form with anchors horizontal both, vertical top. Left is 0, top is 0, right edge distance 0 and height 30. Background color blue. Text color white bold.
Buttons are placed at the top of the form overlying the label.
Each button has anchors horizontal right and vertical top, width and height are 30, top is 0 and the right edge distance starts at 0 for the first icon and incrementing by 30 for any additional icon.
No text is set, but as background property bitmapdrawable with an image file with gravity Center.
The background color is transparent, which can be set in the code using the CSSUtils library: CSSUtils.SetBackgroundColor(button, fx.Colors.Transparent)
The icons must be added via files window to the layout.
Form Code
The form code sets the form style, handles moving the form (using JavaObject) and show /close of the form.
`Private Sub Class_Globals
Private fx As JFX
Private frm As Form
Private lblFormTitle As Label
Private btnClose As Button
Private btnInfo As Button
Private taInformation As TextArea
' Move the Form: Define the X and Y position of the form as global
Private posX, posY As Double
End Sub`
'Initializes the form with the MainForm as owner.
`Public Sub Initialize(owner As Form)
frm.Initialize("frm", 300, 250)
frm.SetOwner(owner)
frm.SetFormStyle("UNDECORATED")
frm.RootPane.LoadLayout("FormNonModal")
lblFormTitle.Text = "Form Non-Modal"
CSSUtils.SetBackgroundColor(btnClose, fx.Colors.Transparent)
CSSUtils.SetBackgroundColor(btnInfo, fx.Colors.Transparent)
taInformation.Text = File.ReadString(File.DirApp, "Info.txt")
End Sub`
' If the mouse is pressed, store the X and Y pos in the globals
`Private Sub frm_MousePressed (EventData As MouseEvent)
posX = EventData.X
posY = EventData.Y
End Sub`
' If the mouse is dragged, set the global X and Y position to the getScreenX or Y API method
' Reference: https://docs.oracle.com/javase/8/docs/api/org/w3c/dom/events/MouseEvent.html
`Private Sub frm_MouseDragged (EventData As MouseEvent)
Dim joEvent As JavaObject = EventData
frm.WindowLeft = joEvent.RunMethod("getScreenX", Null) - posX
frm.WindowTop = joEvent.RunMethod("getScreenY", Null) - posY
End Sub`
`Public Sub showForm
frm.show
End Sub`
`Public Sub closeForm
frm.close
End Sub`
`Private Sub btnClose_Action
frm.close
End Sub`
`Private Sub btnInfo_Action
fx.Msgbox(frm, "B4J HowTo Form Non-Modal", "Information")
End Sub`
Call the Form
This is done in f.e. the MainForm.
`Sub Process_Globals
...
Private btnShowNonModalForm As Button
Private formNonModal As NonModalForm
...
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Main")
MainForm.SetFormStyle("UTILITY")
MainForm.Title = "B4J HowTo Form Non-Modal"
MainForm.Show
formNonModal.Initialize(MainForm)
End Sub`
`Sub AppClose
MainForm.Close
End Sub`
`Sub MainForm_CloseRequest (EventData As Event)
AppClose
End Sub`
`Sub btnShowNonModalForm_Action
formNonModal.showForm
End Sub`

Changed: 2018-06-07 09:13, Category: Forms, File: T6C195M1415.htm, ID: 1415