There are three types of Coherent UI user controls available for .NET.
These are the Windows.Forms, WPF and GTK# BrowserViewControl
controls. The first two are available for Windows(Visual Studio) only, and the GTK# is for Linux(Mono).
The general usage pattern for these controls is to drag the control from the toolbox to your form area. Then (almost) everything is automagically working!
There are a few points that are worth noting:
UsesOwnUISystem
defines whether the control uses an UI System initialized with the default arguments.SetCoherentKey
to set the license key for Coherent UI. This must be done before initializing the controls. All samples have controls with this property set to true. What happens behind the scenes is that a single UI System is initialized and all controls with this property set to true use it. You can check each sample's code to see the proper place for calling the method.InitializeWithHelper
method. Generally, using an own UI System should suffice, unless you need some custom behavior, such as setting up custom log file.SetUpdateInterval
method.UISystemHelper
constructor.public
methods ProcessXXX(XXXEvent e)
, where XXX
is some event, e.g. MouseUp.OnXXX
methods.The samples using the Coherent UI controls represent a very basic browser. Basically, there is a navigation textbox and a single BrowserViewControl
, displaying HTML pages.
The BrowserViewControl
is in the Coherent.UI.Windows.Forms
namespace.
There's just a couple of lines of code in Form1.cs
that handle pressing Enter in the navigation textbox and set the focus to the control when the mouse is over it. Everything else works automatically as described above (the control has the UsesOwnUISystem
property set to true). Note that during re-sizes the control has to re-draw the whole page. If the user re-sizes the control continuously this might lead to some flicker. The control itself tries to minimize this and by default re-sizes its content less often than it receives the events themselves. This ususally leads to a smooth mix of scaling and subsequent proper resizing of the content. However the user can opt to disable the automatic content resizing by setting the AutoResize
property to false. In this way the user is now responsible for resizing the content. A good strategy to avoid any stretching and flickering is to remove any anchoring of the control with the Form and resize is manually when the ResizeEnd
event is triggered by the Form. In this way the control will remain unchanged during the re-size operation and then set its new size as soon as the user has finished re-sizing the Form. The WPF sample bundled shows a good strategy to implement re-size.
The BrowserViewControl
is in the Coherent.UI.Windows.Controls
namespace.
To add the control we define the coui namespace in MainWindow.xaml
as follows: xmlns:coui="clr-namespace:Coherent.UI.Windows.Controls;assembly=CoherentUINET"
. Then, we define the control instance by using <coui:BrowserViewControl ...properties... />
.
The code in MainWindow.xaml.cs
defines the event handlers for hovering above the control and pressing Enter in the textbox.
The BrowserViewControl
is in the Coherent.UI.Mono.Gtk
namespace.
The main source file is MainWindow.cs
. There are handlers for setting focus to the BrowserViewControl
when the mouse is over it, and an activation handler(the user pressed Enter) for the entry widget.
In the constructor we explicitly set the DisplayMode
property, since it may not show in the designer window in Mono. As stated in the code, Stretched
mode causes a performance penalty and using Unscaled
is recommended.
There are 2 ways of having a custom context in the WinForms controls.
BrowserViewContext
control, then drag it into your form. The control should appear at the bottom of the form editor, since it's non-renderable. If you select the control and open the Properties window you will see the available context settings that you can modify. When you're done configuring the context, select a view control and open its properties. The context you created will appear in the Context
dropdown so you can select it.Here's what the context settings look like:
These are the view control's properties and the context selection through the Properties pane:
MouseEnter
and focuses the control when it's fired. Finally, the control is added to the form.This is what the modified sample looks like after you add a new window and try to login in both forms:
There are 2 ways of having a custom context in the WPF controls.
and then set the Context of the BrowserViewControl
in the Properties windows. Note that the resource in the XAML code must be declared as StaticResource (and not DynamicResource for example) since the Context
property is not a DependencyProperty
.
An example XAML file may look like: