Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Qm3 How to add the Winform controls
#1
Hi,

I've seen several examples of WPF on forums

I want to know how to add the Winform controls and show the form in QM3?

For example, the following C# code describes, how to implement?

Thanks in advance for any advice and help
david
-----------------------------------------------------------------------------------------------------------------------------------------
1.Create a new Windows Forms project;
2.Add reference to EO.WebBrowser.dll. Note that you do not need to reference EO.WebBrowser.Wpf.dll;
3.Open Form "Form1" in design view;
4.Drag a PictureBox control onto the form;
5.From solution explorer, right click "Form1.cs" if you use C#, then click "View Code" from the context menu;
6.Add the following code to class Form1 to declare a WebView variable:

//Declare a new WebView object
private EO.WebBrowser.WebView m_WebView = new EO.WebBrowser.WebView();

7.Handle the Form's Load event and add the following code to initialize the WebView:

private void Form1_Load(object sender, EventArgs e)
{
    //Initialize the WebView using the PictureBox's window handle
    m_WebView.Create(pictureBox1.Handle);
    
    //Load Google's home page into the WebView
    m_WebView.Url = "www.quickmacros.com";
}
-----------------------------------------------------------------------------------------------------------------------------------------

C# code:
// script "WebView_OE.cs" /*/ role exeProgram; outputPath %folders.Workspace%\exe\WebView_OE; r %dll%\EO\EO.WebBrowser.dll; r %dll%\EO\EO.WebBrowser.WinForm.dll; /*/

private EO.WebBrowser.WebView WebView1 = new EO.WebBrowser.WebView();

//Todo: Add controls

private void Form1_Load(object sender, EventArgs e)
{
    //Initialize the WebView using the PictureBox's window handle
    m_WebView.Create(pictureBox1.Handle);
    
    //Load Google's home page into the WebView
    m_WebView.Url = "www.quickmacros.com";
}
#2
Better don't use Winforms. Will be problems with high DPI screens. And QM3 will never have classes or tools to work with winforms easier. And I can't help.

Winforms forms can be easily created without a designer. Look for examples on the Internet.
#3
Thanks for the reminder, it seems that Winform is a bit outdated

I found the WPF code for the control above, but using the code created by visual studio, the CS file and the XAML file are separate

Not a lot of code, I want to know how to achieve the same function in QM3.

Description of the operation in VS:

1.Open your WPF project; 
2.Add reference to EO dlls; 
3.Open a Window in XAML view; 
4.Add "eo" namespace prefix in your XAML file. Simply add the following attribute to your Window or UserControl 
For example, your Window element may look like this: 
XAML
<Window x:Class="Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:eo="http://schemas.essentialobjects.com/wpf/"
        Title="MainWindow" Height="250" Width="350">
Note the additional "eo" prefix added to the Window element. 

5.Add an "eo:WebControl" element to your Window: 
XAML
<eo:WebControl>
    <eo:WebControl.WebView>
        <eo:WebView x:Name="webView1">
        </eo:WebView>
    </eo:WebControl.WebView>
</eo:WebControl>

Then you can use webView1 in your code: 

//Load Google's homepage into the WebView
WebView1.Url = "www.google.com";

-------------------------------------------------------------------------------------------------------------------------------
C# code:
// script "WebView_OE_WPF.cs" /*/ role exeProgram; outputPath %folders.Workspace%\exe\WebView_OE_WPF; r %dll%\EO\EO.WebBrowser.dll; r %dll%\EO\EO.WebBrowser.WinForm.dll; r %dll%\EO\EO.Base.dll; r %dll%\EO\EO.WebEngine.dll; r %dll%\EO\EO.Wpf.dll; /*/


//Todo: Process xaml

//Load Google's homepage into the WebView
WebView1.Url = "www.google.com";
#4
Don't need XAML. Use code like in WebView2 example.
#5
I tried the code below and the Add method will prompt for the error 

b.Row(-1).Add(out WebView k);
Err:
<open "<0x100000034>|8|11">WebView_OE_WPF.cs(8,11): error CS0311: The type 'EO.WebBrowser.WebView' cannot be used as type parameter 'T' in the generic type or method 'wpfBuilder.Add<T>(out T, object, WBAdd)'. There is no implicit reference conversion from 'EO.WebBrowser.WebView' to 'System.Windows.FrameworkElement'.


C# code:
// script "WebView_OE_WPF.cs" /*/ role exeProgram; outputPath %folders.Workspace%\exe\WebView_OE_WPF; r %dll%\EO\EO.WebBrowser.dll; r %dll%\EO\EO.WebBrowser.WinForm.dll; r %dll%\EO\EO.Base.dll; r %dll%\EO\EO.WebEngine.dll; r %dll%\EO\EO.Wpf.dll; /*/

using EO.WebBrowser;

var b = new wpfBuilder("Window").WinSize(700, 600);

b.Row(-1).Add(out WebView k);
k.Url = new("https://www.quickmacros.com");
b.End();
if (!b.ShowDialog()) return;

QM3 creates the WPF dialog that doesn't require XAML code, which looks amazing,  Smile
Also, will QM3 have a WPF form designer? Like QM2?
#6
It means WebView isn't a WPF element. WPF elements are inherited from FrameworkElement.

For example, Button is a WPF element. When you start typing Button in the code editor, select Button in the list of completions. In the second popup window you'll see base classes. One of them is FrameworkElement. If there is no FrameworkElement, it's not a WPF element.

: ButtonBase : ContentControl : Control : FrameworkElement : UIElement : Visual : DependencyObject : DispatcherObject ...

Maybe WebView is a winforms control. Winforms controls can be used in WPF too, but indirectly, and it works not as good. Better look for a WPF element. Maybe it's in another namespace, not in EO.WebBrowser.

I don't have the EO library and can't help much.

____
Quote:will QM3 have a WPF form designer? Like QM2?
Maybe, but not soon. Now can be used the "WPF preview" feature.
#7
@Gintaras

Thanks for your guidance, I used the code below and finally succeeded  Smile

QM3 looks promising, using very little code but implementing more functionality

C# code:
// script "WebView_OE_WPF.cs" /*/ role exeProgram; outputPath %folders.Workspace%\exe\WebView_OE_WPF; r %dll%\EO\EO.Base.dll; r %dll%\EO\EO.WebEngine.dll; r %dll%\EO\EO.Wpf.dll; r %dll%\EO\EO.WebBrowser.Wpf.dll; r %dll%\EO\EO.WebBrowser.dll; /*/

using EO.Wpf;

var b = new wpfBuilder("Window").WinSize(1280, 720);

b.Row(-1).Add(out WebControl k);
k.WebView.Url = new("https://www.quickmacros.com");

b.End();
if (!b.ShowDialog()) return;


Forum Jump:


Users browsing this thread: 1 Guest(s)