Window
From Xojo Documentation
Supported Platforms Project Types: Desktop Platforms: macOS, Windows, Linux |
Any window. A window can be converted to a ContainerControl by changing its Super Class to ContainerControl. However, you cannot change the default window to a ContainerControl.
Properties | |||||||||||||||||||||||||||||||||||
|
Methods | ||||||||||||||||||||||||
|
Class Constants
The following class constants of the DragItem class can be used to specify the value of the Action parameter of the DragEnter, DragExit, and DragOver events.
Class Constant | Description |
---|---|
DragActionDefault | Default action. |
DragActionCopy | Copy the dragged item. |
DragActionMove | Move the dragged item. |
DragActionLink | Link the dragged item. |
Notes
Window constructors are called after the window and its controls are created, but before the Open events are called. If you are initializing Window properties, you should do so using the Open event handler rather than the Constructor. Using the Constructor could result in property changes you make being overwritten by the built-in Window initializations.
Understanding Sheet Windows
A "Sheet window" is the official name for drop-down dialog boxes that were introduced with macOS, where they often used in place of modal dialog boxes. Sheet windows behave as such only on OS X. On other platforms, they behave as ordinary movable modal dialog boxes.
A Sheet window behaves like a Modal dialog window, except that the animation makes it appear to drop down from the parent window's Title bar. It can't be moved from that position and it puts the user interface in a modal state. The user must respond to the choices presented in the Sheet window.
A Sheet window can be displayed by calling the ShowModalWithin method. If SheetWindow is defined as a Sheet window and MainWindow is a Document window, then the statement:
will show the Sheet window using the calling window (in this case, MainWindow) as the Parent window.
Note that the above works because SheetWindow has its ImplicitInstance property set to True.
You can also use your own instance like this:
Custom Cursors
The MouseCursor property controls the appearance of the pointer when it is over the window, provided the MouseCursor property of the Application class is Nil. If you also want the pointer to change to another shape when it is over a control within the window, you must either assign the new value to the Window's MouseCursor property or temporarily set the window's MouseCursor property to Nil and the control's MouseCursor property to the desired cursor. See the section on the MouseCursor class for an example.
You can assign a MouseCursor using the library of cursors in the Cursors module.
Examples
This example sets the background color of the window to grey, provided the HasBackgroundColor property is set to True.
This example increases the width of the window by 20 pixels.
This example changes the title of the window.
The Resizing Event Handler
This example resizes three TextFields on the form in the Resizing event.The three TextFields are aligned horizontally. As the user stretches or shrinks the window, the TextFields' widths change proportionally.
Var field1Size, field2Size, field3Size As Integer
// subtract 40 pixels for the space between the
// three fields and on left and right side of the window
availableSpace = Me.Width - 40
// calculate the size of each field based on a percentage
field1Size = availableSpace * 0.6 // 60 percent
field2Size = availableSpace * 0.3 // 30 percent
field3Size = availableSpace * 0.1 // 10 percent
// Set the field widths
TextField1.Width = field1Size
TextField2.Width = field2Size
TextField3.Width = field3Size
// reposition the fields based on the new sizes
TextField2.Left = TextField1.Left + TextField1.Width + 10
TextField3.Left = TextField2.Left + TextField2.Width + 10
Contextual Menu Example
The following example shows how to present and handle a contextual menu in a window using the ConstructContextualMenu and ContextualMenuAction event handlers.
The following code in a ConstructContextualMenu event builds a simple contextual menu. The parameter base (a MenuItem) is passed in as a parameter and you add your contextual menu to it:
base.Add(New MenuItem("Export"))
Return True // display the contextual menu
The following Select statement in the ContextualMenuAction event handler inspects the selected menu item, which is passed in as the selectedItem (a MenuItem) parameter.
Case "Import"
MessageBox("You chose Import")
Case "Export"
MessageBox("You chose export")
End Select
Return True
DrawInto Example
This example draws the contents of a window into a Graphics object. For example, add a second window to a new project (Window2) and set its Visible property to False. Add a variety of controls to Window2. In the Paint event of Window1, use this code to draw the second window into the first window:
The contents of Window2 are drawn into Window1.
Accessing Controls and Properties in Other Windows
When changing a window property from another window, there are two possible approaches you can take. If you have only one instance of the window you need to reference, you can use the window's object name as a reference. For example, if you had a window called window1 that had a TextField called TextField1 and you wanted to assign the value "Fred" to the text property of that TextField, you would using the following syntax:
If you have multiple instances of the same window class open at the same time, then a reference to the target window must be included as in this example where a new window is opened and its window title changed. "anotherWindow" is a window class in the Project.
Handling Drag and Drop
For an explanation of handling drag and drop, see the Control class and the DragItem class.
See Also
Window function; MessageDialog class.