Class

WebImageViewer


Description

Displays a picture either from a project item, one assigned at runtime, SVG data or via a URL.

Methods

Name

Parameters

Returns

Shared

Close

CSSClasses

WebCSSClasses

ExecuteJavaScript

script As String

GotoURL

URL As String, inNewWindow As Boolean = False

SetFocus

Style

WebStyle

Assigns style As WebStyle

UpdateBrowser

Events

Name

Parameters

Returns

Closed

ContextualMenuSelected

hitItem As WebMenuItem

Hidden

Opening

Pressed

x As Integer, y As Integer

Shown

Enumerations

WebImageViewer.DisplayModes

DisplayModes

The various ways in which the image can be displayed inside the control.

Enum

Description

ScaleToFill

The image's aspect ratio is ignored and the image is stretched to fit within the bounds of the frame.

ScaleAspectFit

Scales the image until it fits entirely, maintaining aspect.

ScaleAspectFill

Scales the image until it fills the ImageView entirely, maintaining aspect.

Center

The image is centered within the frame.

Top

The image is positioned with its top at the top of the frame.

Bottom

The image is positioned with its bottom at the bottom of the frame.

Left

The image is positioned with its left at the left of the frame.

Right

The image is positioned with its right at the right of the frame.

TopLeft

The image is positioned with its top left at the top left of the frame.

TopRight

The image is positioned with its top right at the top right of the frame.

BottomLeft

The image is positioned with its bottom left at the bottom left of the frame.

BottomRight

The image is positioned with its bottom right at the bottom right of the frame.

Property descriptions


WebImageViewer.ContextualMenu

ContextualMenu As WebMenuItem

If you assign a WebMenuItem to the control, it will be displayed when the user right-clicks the control.

On a WebPage, you can disable/remove the default contextual menu by an empty WebMenuItem class object to this property.

This code populates a contextual menu in the Shown event of the control.

Var menu As New WebMenuItem

menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu

The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:

Select Case hitItem.Text
Case "One"
  MessageBox("One")
Case "Two"
  MessageBox("Two")
Case "Three"
  MessageBox("Three")
End Select

WebImageViewer.ControlID

ControlID As String

Identifies the control on a per session basis.

This property is read-only.


WebImageViewer.DisplayMode

DisplayMode As DisplayModes

Specifies the way the picture gets displayed using the DisplayModes enumeration.

Center the image within the frame:

Me.DisplayMode = WebImageViewer.DisplayModes.Center

WebImageViewer.Enabled

Enabled As Boolean

When True the WebControl is drawn enabled and responds to user action. When False, the control appears as disabled and does not respond to user actions.

In the case of WebTimer, when set to False this disables and stops the WebTimer. When set to True, it starts the WebTimer.

Disable a button when a check box value changes:

If AllowSaveCheckBox.Value Then
  SaveButton.Enabled = True
Else
  AllowSaveButton.Enabled = False
End If

WebImageViewer.Height

Height As Integer

The height (in pixels) of the control.


WebImageViewer.Image

Image As WebPicture

The picture to display.

JPEG and PNG image formats are supported. If you load an SVG (using the SVGData property, the Picture property will be blank.

The following example in the Opening event of a WebImageViewer displays a picture that was added to the project:

Me.Image = RedDog

WebImageViewer.Indicator

Indicator As Indicators

The color scheme for the control.


WebImageViewer.Left

Left As Integer

The position of the left side of the WebUIControl in pixels, relative to the web page.


WebImageViewer.LockBottom

LockBottom As Boolean

Determines whether the bottom edge of the control should stay at a set distance from the bottom edge of the parent control, if there is one, or the owning web page.


WebImageViewer.LockHorizontal

LockHorizontal As Boolean

LockHorizontal overrides LockLeft and LockRight. It allows you to proportionally lock a control's position to the center of its parent control (or web page).

For example, if you place a control in the center of the page and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.


WebImageViewer.LockLeft

LockLeft As Boolean

Determines whether the left edge of the control should stay at a set distance from the left edge of the parent control, if there is one, or the owning web page.


WebImageViewer.LockRight

LockRight As Boolean

Determines whether the right edge of the control should stay at a set distance from the right edge of the parent control, if there is one, or the owning web page.


WebImageViewer.LockTop

LockTop As Boolean

Determines whether the top edge of the control should stay at a set distance from the top edge of the parent control, if there is one, or the owning web page.


WebImageViewer.LockVertical

LockVertical As Boolean

LockVertical overrides LockTop and LockBottom. It allows you to proportionally lock a control's position to keep it centered within the parent control or web page.

For example, if you place a control in the center of the page, and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.


WebImageViewer.Name

Name As String

The name of the control.

This property is read-only.


WebImageViewer.PanelIndex

PanelIndex As Integer

If the control has been placed on a WebTabPanel or WebPagePanel control, this is the panel (page/tab) that the control is on. If the control is not on a panel, it returns -1.

The first panel is numbered zero. If the control has been placed on a panel of a WebTabPanel or WebPagePanel control, it returns the panel number. If the control is not on a WebPagePanel or WebTabPanel, it returns -1. If you change the PanelIndex to a nonexistent panel, the control will disappear until you give it a PanelIndex value that corresponds to a panel that exists.

If you are looking to change the currently selected panel (page/tab), use SelectedPanelIndex.

This code displays the panel index of the control that is on the page.

MessageBox(Me.SelectedPanelIndex.ToString)

WebImageViewer.Page

Page As WebPage

Identifies the web page that contains the control.

This property is read-only.


WebImageViewer.Parent

Parent As WebView

Used to get the control's parent control or page. If the parent control is a WebContainer, then it returns the WebContainer. If it is on a WebPage, it returns the WebPage.

This property is read-only.


WebImageViewer.SVGData

SVGData As String

If this property contains SVG-formatted data, it will be drawn into the WebImageViewer at runtime.

The SVG picture is not drawn in the Layout Editor.


WebImageViewer.TabIndex

TabIndex As Integer

The WebImageViewer's control's position in the Tab Order. The control with a TabIndex of 0 is the first WebUIControl to get the focus when the page opens in the browser.

This example sets the control's TabIndex.

Me.TabIndex = 2

WebImageViewer.Tooltip

Tooltip As WebToolTip

Text of a message displayed as a tooltip.

The tip is displayed when the user places the mouse on the control and leaves it there.

This code in the Shown event of a Button sets the tooltip:

Me.Tooltip = "Save changes"

WebImageViewer.Top

Top As Integer

The top of the control in local coordinates relative to the web page.


WebImageViewer.URL

URL As String

The URL from which the picture should be downloaded and drawn in the WebImageViewer.

If the picture does not draw in the Layout Editor, it is likely that the website from which the picture originates is blocking the ability to access it from anywhere except the website itself.


WebImageViewer.Visible

Visible As Boolean

If True, the control is drawn. If False, it's not.

Hide a control based on a checkbox setting:

If ShowEmailCheckbox.Value Then
  EmailField.Visible = True
Else
  EmailField.Visible = False
End If

WebImageViewer.Width

Width As Integer

The width (in pixels) of the web control.

This code in the Shown event handler increases the size of the control:

Me.Width = Me.Width + 50

Method descriptions


WebImageViewer.Close

Close

Removes the control from the page.


WebImageViewer.CSSClasses

CSSClasses

Returns the instance of WebCSSClasses for this control allowing you to add CSS classes to and remove CSS classes from the control.


WebImageViewer.ExecuteJavaScript

ExecuteJavaScript(script As String)

Executes the JavaScript passed. The JavaScript passed can call a JavaScript function in a WebPageSource control.

The Xojo web framework uses EcmaScript 6 which is more strict than previous versions of JavaScript. For more details, see the EcmaScript 6 documentation.

This code in the Pressed event of a Button displays an alert using JavaScript:

Me.ExecuteJavaScript("alert('Hello!');")

This code will select the text in a WebTextField (or WebTextArea):

WebTextField1.ExecuteJavascript("document.getElementById('" + _
  WebTextField1.ControlID + "_inner').select();")

WebImageViewer.GotoURL

GotoURL(URL As String, inNewWindow As Boolean = False)

Opens the passed URL in place of the current web page or downloads a file. If InNewWindow is True, the browser is asked to open the URL in a new window.

If the browser has popup windows disabled and InNewWindow is True, the method silently fails and the page is not shown.

If InNewWindow is False, the running web app is replaced with the specified URL. If you want to display an external web site within your web app, use the WebHTMLViewer control.

Display a web site in a new popup window:

Me.GotoURL("http://www.wikipedia.org", True)

WebImageViewer.SetFocus

SetFocus

Sets the focus to the Control.

This code checks for a required value when a button is pressed:

If UserNameField.Text.IsEmpty Then
  MessageBox("Please enter your UserName.")
  UserNameField.SetFocus
  Return
End If

WebImageViewer.Style

Style As WebStyle

Returns the WebStyle for the control.


Style(Assigns style As WebStyle)

Assigns the style to the control.

In this example, in any event of the control, set the text to bold:

Var style As New WebStyle
style.Bold = True
Me.Style = style

WebImageViewer.UpdateBrowser

UpdateBrowser

Forces the current values of the control to be sent to the browser.

This method is useful when you are computing values in a loop and wish to update the browser immediately rather than wait until the current method ends.

This code iterates through a RowSet of database rows, updates a ProgressBar and then forces the updated ProgressBar to be sent to the browser via UpdateBrowser.

ProgressBar1.MaximumValue = SalesData.RowCount
For Each row As DatabaseRow in SalesData
 AnalyzeSales(row)
 ProgressBar1.Value = ProgressBar1.Value + 1
 ProgressBar1.UpdateBrowser
Next

Event descriptions


WebImageViewer.Closed

Closed

The control has been removed from the browser either because the page has closed or the control's Close method was called.


WebImageViewer.ContextualMenuSelected

ContextualMenuSelected(hitItem As WebMenuItem)

Called when a contextual menu item is selected. This selected item is contained in hitItem.

This code populates a contextual menu in the Opening event of a WebToolbar:

Var menu As New WebMenuItem

menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu

The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:

Select Case hitItem.Text
Case "One"
  MessageBox("One")
Case "Two"
  MessageBox("Two")
Case "Three"
  MessageBox("Three")
End Select

WebImageViewer.Hidden

Hidden

The control is about to become no longer visible. This could be because the page is being closed, is being replaced as the foreground page by another page or because the control or a parent control's Visible property has been set to False.

Note

This event is equivalent to the DesktopWindow.Deactivated event in a desktop app.


WebImageViewer.Opening

Opening

The control has been created and the page is opening but has not been sent to the browser yet.

The Opening event handler can be used to initialize non-visual properties and settings for controls.

In most cases, you should use the Shown event to initialize controls.


WebImageViewer.Pressed

Pressed(x As Integer, y As Integer)

The user pressed on the control at the coordinates passed.


WebImageViewer.Shown

Shown

The control has appeared on the currently displayed page. This could be because its parent page just finished loading, its parent page has come to the foreground or the control is now visible having been previously invisible because it or its parent control's Visible property has been set to True.

Use the Shown event for initializing your controls or doing anything that would interact with other controls or user interface elements on the web page instead of the Opening event.

Note

This event is the web equivalent to the DesktopWindow.Activated event.

This code in the Shown event of a WebListBox adds 2 rows with 3 columns:

Me.RemoveAllRows
Me.AddRow("Row 1", "Bob", "Roberts")
Me.AddRow("Row 2", "Barb", "Reynolds")

This example sets the text of a label:

If Session.LoggedIn Then
  Me.Text = "Welcome!"
Else
  Me.Text = "Welcome, " + Session.UserName
End If

Notes

The WebImageViewer appears as a rectangular area on a WebPage in the Web Page Layout Editor. If no image is assigned, then a placeholder icon is displayed in the center. If an image from your project is specified, it is shown in both the Layout Editor and the built application. The WebPage Layout Editor cannot render SVG data in the IDE.


Manipulating the picture

You cannot directly manipulate the Image property as it is actually a Image, not a regular Picture object. What you must do instead is create a new Picture using the Image property as the source, manipulate the new picture then assign it back to the Image property to update it. The Picture property will automatically convert a WebPicture into a Picture and back again.

Here is an example:

Var p As Picture = New Picture(ImageViewer1.Width, ImageViewer1.Height)
p.Graphics.DrawPicture(ImageViewer1.Picture, 0 ,0)
p.Graphics.DrawingColor = Color.Red
p.Graphics.FillRectangle(0, 0, 100, 100) ' Change the Picture
ImageViewer1.Picture = p ' Automatically converts Picture to WebPicture

Optimizing your use of pictures

Pictures that are stored in properties of objects that are sent to the browser (like properties of web pages and controls) are cached locally on the client web browser. If you are always displaying the same picture on a page (or different pages), you can significantly improve performance by caching your picture so that it is not repeatedly sent to the web browser.

For example, if you are creating a custom button control using a subclass of an WebImageViewer control, you could store the two images (normal and pressed states) in two picture properties of the ImageView subclass so that those pictures are only sent to the browser once.

On the app itself (the server side), using a URL does not keep the file in memory. Using a WebFile or WebPicture does keep the file in memory, unless you point it to a file on disk.


VerticalAlign and horizontalAlign values

Use these class constants with the VerticalAlign and HorizontalAlign properties.

Alignment

Value

Default (middle)

0

Top

1

Middle

2

Bottom

3

Sample code

This example displays a picture (FunnyCat) that has been added to your project:

ImageViewer1.Picture = FunnyCat

Compatibility

Web projects on all supported operating systems.