I was using the .Net WebBrowser object but don't like the messy way the compatibility mode works. So I switched to CEFSharp object.
However, the object doesn't display in my form. I looked at the Example Winform project with CEFSharp but it doesn't seem to display it in a winform but runs it as a separate application which isn't want i want.
I figure I am missing some obvious method or property that must be set initially. In the code below I have what I am using for CEFSharp and you will see two lines commented out which is what I was using for .Net WebBrowser that worked.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp.WinForms;
namespace GoogleSiren
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ChromiumWebBrowser myBrowser = new ChromiumWebBrowser("http://wwww.cnn.com");
//WebBrowser myBrowser = new WebBrowser();
//myBrowser.Navigate("http://www.cnn.com");
myBrowser.Location = new Point(200, 200);
myBrowser.Size = new Size(500, 300);
this.Controls.Add(myBrowser);
}
}
}
Try setting the Size and Location as part of the constructor:
ChromiumWebBrowser myBrowser = new ChromiumWebBrowser("http://wwww.cnn.com")
{
Location = new Point(200, 200),
Size = new Size(500, 300)
};
this.Controls.Add(myBrowser);
My code was missing Cef.Initialize() call. Once I added that it worked fine.
Related
I am trying to pass a string my function in Windows Form Application in order to invoke InteropAssembly.dll from a LabVIEW script. The script takes a string for opening image and do some process and then return 2 different images. But I am getting the error The type 'LVBaseRefnum' is defined in an assembly that is not referenced. You must add a reference to assembly 'NationalInstruments.LabVIEW.RefnumTypes'. I have checked the forum and so and found this . But it was posted quite long time ago and still no valid answer. Have you ever encounter this error any solution? Thanks in advance and my code as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using InteropAssembly;
namespace testLabview
{
public partial class Form1 : Form
{
private object img1;
private object img2;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.pictureBox1 = null;
this.pictureBox2 = null;
string text = this.textBox1.ToString();
LabVIEWExports.test(text, out Image img1, out Image img2);
this.pictureBox1.Image = img1;
this.pictureBox2.Image = img2;
}
}
}
the code is working perfectly but after publishing it just doesn't open.
I created a page to test graphics, however as the webbrowser C# does not work, as it starts in IE I tried to use Cefsharp but it is not going either,the error that appears to me is Cefsharp.Core.Runtime.dll, the version I am using of cefsharp is 94.4.11. but the problem is that when I use it by Visual Studio 2022 it works but when I do the compilation and I publish it to generate the executable it doesn't just give an error or it doesn't even open
using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace cefteste
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
criarcef(panel1,p);
}
ChromiumWebBrowser p;
private void Form1_Load(object sender, EventArgs e)
{
}
private void criarcef(Panel panel, ChromiumWebBrowser chromium)
{
/*CefSettings settings = new CefSettings();
settings.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/GPMDP";
settings.WindowlessRenderingEnabled = true;
settings.CefCommandLineArgs.Add("enable-smooth-scrolling", "1");
settings.CefCommandLineArgs.Add("enable-overlay-scrollbar", "1");
settings.CefCommandLineArgs.Add("enable-npapi", "1");
CefSharp.Cef.Initialize(settings);*/
chromium = new ChromiumWebBrowser("C:/Users/Bill/Downloads/index(1).html");
chromium.LoadingStateChanged += (sender, args) => {
if (args.IsLoading == false)
chromium.ExecuteScriptAsync("document.oncontextmenu = function() { return false; };");
};
panel.Controls.Add(chromium);
chromium.Dock = DockStyle.Fill;
}
}
}
I can't play play video with Emgu CV
It's show error
Unable to create capture from 184.avi
Here is the code:
public partial class Form1 : Form
{
//Set the name of pop-up window
String winname = "First Window";
Timer My_Time = new Timer();
int FPS=30;
Capture _capture;
public Form1()
{
InitializeComponent();
//Frame Rate
My_Timer.Interval = 1000 / FPS;
My_Timer.Tick += new EventHandler(My_Timer_Tick);
My_Timer.Start();
_capture = new Capture("184.avi"); // Error this line
}
private void My_Timer_Tick(object sender, EventArgs e)
{
imageBox.Image = _capture.QueryFrame().ToBitmap();
}
I use windows 8 x64 and install emgucv-windows-universal-cuda 2.4.10.1940 It have no opencv_ffmpeg.dll in bin. So I install opencv-2.4.11 and copy all dll from OpenCV bin to paste in Debug in my project. I paste 184.avi to Debug too. But when I run it show error like this. How to play video with Emgu CV?
Your code works fine. I think the problem is that you have not imported the video file to Visual Studio. So try importing the video file to visual studio and also set the properties to copy always. You can see below that i have imported the A.avi file and set it's properties to copy always.
And think you can just use imageBox.Image = _capture.QueryFrame(); instead of imageBox.Image = _capture.QueryFrame().ToBitmap();because you don't need to convert to bitmap with ImageBox.
The code i used is same as yours.
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.CV.Features2D;
using Emgu.CV.Util;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{//Set the name of pop-up window
String winname = "First Window";
Timer My_Time = new Timer();
int FPS = 30;
Capture _capture;
public Form1()
{
InitializeComponent();
//Frame Rate
My_Time.Interval = 1000 / FPS;
My_Time.Tick += new EventHandler(My_Timer_Tick);
My_Time.Start();
_capture = new Capture("A.avi"); // Error this line
}
private void My_Timer_Tick(object sender, EventArgs e)
{
imageBox.Image = _capture.QueryFrame();
}
}
}
You can just provide full path instead of just the file name.
You do not have the video file in the same folder as your program exe.
If you place video file just next to your program exe, it should also work.
I am trying to call javascript using OpenWebKitSharp from WinForms with .NET 4
Here is the code I am trying to use.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WebKit;
using WebKit.Interop;
using WebKit.JSCore;
using webkitForm.Properties;
namespace webkitForm
{
public partial class Form1 : Form
{
WebKitBrowser webKitSharpBrowser = new WebKitBrowser();
public Form1()
{
InitializeComponent();
this.Controls.Add(webKitSharpBrowser);
webKitSharpBrowser.Width = 600;
webKitSharpBrowser.Height = 400;
}
private void button1_Click(object sender, EventArgs e)
{
webKitSharpBrowser.Preferences.AllowPlugins = true;
webKitSharpBrowser.UseJavaScript = true;
webKitSharpBrowser.Navigate("http://sandbox.icontact.com");
webKitSharpBrowser.GetScriptManager.EvaluateScript("alert('An alert from C#!');"); //Call javascript?
}
}
}
I can't get javascript to fire for anything... there must be something that I am missing.
Thanks in advance.
Well, it seems like it can't be done the way you want to:
if you are using .NET 4, calling a function is possible by using:
<webkitbrowser>.GetScriptManager.CallFunction("name", new Object[] { arg1, arg2, ...});
If you want to use .NET 2 you can use:
<webkitbrowser>.StringByEvaluatingJavaScriptFromString("name(arguments)")
- Open Webkit Sharp Issues
I tested your code, it IS working, but calling the alert function only triggers an event (WebKitBrowser.ShowJavaScriptAlertPanel), you are responsible for handling that event and showing a message or updating a label, or anything else.
For example:
Browser.ShowJavaScriptAlertPanel += Browser_ShowJavaScriptAlertPanel;
and then handle the event:
private void Browser_ShowJavaScriptAlertPanel(object sender, WebKit.ShowJavaScriptAlertPanelEventArgs e)
{
MessageBox.Show(e.Message);
}
There is a post in here about that ...but it doesn't work for me. I have added a system.speech.dll that I found in the internet but i cannot use System.speech , because it doesn't appear.
Error 1 The type or namespace name 'SpeechRecognizer' could not be found (are you missing a using directive or an assembly reference?)
Error 2 The type or namespace name 'SpeechRecognizedEventArgs' could not be found (are you missing a using directive or an assembly reference?)
I have used this code. I am using Windows Vista 64
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SpeechLib;
using System.Threading;
namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{
SpeechRecognizer rec = new SpeechRecognizer();
public Form1()
{
InitializeComponent();
rec.SpeechRecognized += rec_SpeechRecognized;
}
void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
lblLetter.Text = e.Result.Text;
}
private void Form1_Load(object sender, EventArgs e)
{
var c = new Choices();
// Doens't work must use English words to add to Choices and
// populate grammar.
//
//for (var i = 0; i <= 100; i++)
// c.Add(i.ToString());
c.Add("one");
c.Add("two");
c.Add("three");
c.Add("four");
c.Add("Five");
c.Add("six");
c.Add("seven");
c.Add("eight");
c.Add("nine");
c.Add("ten");
// etc...
var gb = new GrammarBuilder(c);
var g = new Grammar(gb);
rec.LoadGrammar(g);
rec.Enabled = true;
}
}
}
I agree with James Ogden. Also, you should add a "using" statement:
using System.Speech.Recognition
Or, fully qualify your class names.
1) You need to add a reference to System.Speech in your project
2) You shouldn't have had to find 'System.Speech.dll' on the Internet, it should be in .Net 3 (or 3.5, but get 3.5 anyway unless you've a compelling reason not to)
Edit:
You might want to look here:
http://dotnet.org.za/beta/archive/2008/01/06/system-speech-recognition.aspx
Check that you have a language engine matching the language you have configured in Vista. See http://support.microsoft.com/kb/934377
While not directly applicable to the above question - it is worth noting that the Speech SDK will not nessecarily be availible on each clients machines. While Vista includes a speech recognizer, XP does not. A possible way to correct this is to get the XP users to install the Speech SDK, which includes one. The other is to add Office 2003 (not 2007) as a dependency.
Im having problem about SpeechRecognizer class on Windows XP. sometimes it works but sometimes it doesnot work, and need to restart pc. on windows 7 its working fine. I think its some problem in speech engine itself, cause when I run my application several times it stops working.
Im using this code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SpeechLib;
using System.Threading;
namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{
SpeechRecognizer rec = new SpeechRecognizer();
public Form1()
{
InitializeComponent();
rec.SpeechRecognized += rec_SpeechRecognized;
}
void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
lblLetter.Text = e.Result.Text;
}
private void Form1_Load(object sender, EventArgs e)
{
var c = new Choices();
c.Add("one");
c.Add("two");
c.Add("three");
c.Add("four");
c.Add("Five");
c.Add("six");
c.Add("seven");
c.Add("eight");
c.Add("nine");
c.Add("ten");
// etc...
var gb = new GrammarBuilder(c);
var g = new Grammar(gb);
rec.LoadGrammar(g);
rec.Enabled = true;
}
}
}