Form showing nothing. using CefSharp with Windows form in C# - c#

I am trying to show a webpage in a form using C#. I am using CefSharp to show the webpage (as I would like to test & learn how it works). But since I have worked only on inbuilt webbrowser, I have no idea how to get started with CefSharp(Finding it difficult to get any tutorials). I tried to write this code which executes but the form shows nothing in it. Where am I going wrong ?
Here is my Code :
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;
using CefSharp.WinForms;
namespace chrometest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Cef.Initialize(new CefSettings());
var test = new CefSharp.WinForms.ChromiumWebBrowser("http://www.google.com")
{
Dock = DockStyle.Fill,
};
this.Controls.Add(test);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Edit :
I tried to run the example from https://github.com/cefsharp/CefSharp/tree/cefsharp/41/CefSharp.WinForms.Example
When I try to build the solution, it shows a dialog box saying "Restoring Nuget Package cef.redist.x64 3.2454.1317" with a progresss bar which takes hell lot of time to complete but never completes and after sometime it hangs.
Please help what should I do to get the example running.

The CefSharp project has a few different examples as part of the main project.
Basic Example using Nuget
https://github.com/cefsharp/CefSharp.MinimalExample
More Advanced Examples
https://github.com/cefsharp/CefSharp/tree/cefsharp/41/CefSharp.WinForms.Example
When you installed the project using Nuget it should have opened a Readme.txt file, it contains a lot of useful information.
https://github.com/cefsharp/CefSharp/blob/cefsharp/41/NuGet/Readme.txt
In the context of WinForms there's a few tutorials
http://www.codeguru.com/columns/dotnet/if-you-like-it-put-an-html5-ui-on-it.html
http://thechriskent.com/2014/08/18/embedded-chromium-in-winforms/
For those reading this looking for WPF, there's
http://www.codeproject.com/Articles/881315/Display-HTML-in-WPF-and-CefSharp-Tutorial-Part
http://www.codeproject.com/Articles/887148/Display-HTML-in-WPF-and-CefSharp-Tutorial-Part
More Links
https://github.com/cefsharp/CefSharp.Tutorial
http://thechriskent.com/category/net/cefsharp/

Related

How to embed a R plot in a Winform in c#?

I am using R.NET to perform computation in my C# application and
now I'd like to display the results in a Winform.
Anyone could advise on how to embed a R plot in a winform using R.NET ?
I found the below post which seems outdated as I can't find any reference nor Nuget package for the RNETGraph namespace that they use. The link referenced in the post have also been archived.
display multiple R Embedded Graph in multiple panel winform c#
And I would like to avoid the ugly solution of saving the image and then loading it in a PictureBox as I need to change the plot dynamically according to user input.
Thanks
You can use Dieter Menne's RGraphHooks to display R's plot output in a graphical WinForms element (e.g. a Windows.Forms.Panel). RGraphHooks has a dependency to Dino Esposito's Win32 hooks library.
Usage of RGraphHooks is quite simple. See this blog post by Peter Dai Dinh for a small demo program.
What you basically do is, you attach an RGrapHook to a specific control in your WinForms GUI and then wrap your engine.Evaluate("plot(...)") in this hook:
RGraphAppHook cbt = new RGraphAppHook { GraphControl = panelForPlot };
cbt.Install();
engine.Evaluate("plot(rnorm(100))");
cbt.Uninstall();
I never got hold of R.NET - documentation just wasn't very clear.
There is another option, however. You can use the command line to transfer arguments from your C# application to your R.Script.
For example:
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 WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string strCmdText;
strCmdText = "Rscript.exe [directory here]\\script.R 10 arg2"; //what comes after script.R are the arguments you are passing.
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
}
}
Then, it is very easy to retrieve the arguments in the R Script. Just use:
args <- commandArgs(trailingOnly = TRUE)
var1 <- args[1] #Argument 1
var2 <- args[2] #Argument 2
Addendum: Please note, you should have your RScript.exe in the environment variables in order to get the above to work.

How to find a function of application with ollydbg?

Let's say i released the application below.
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello World!","Message Box");
}
}
}
Now here is my questions:
How to find the function of button which is responsible to show
message box after pressing the button with ollydbg?
How to disable the button click ?
Notes:this must be done with ollydbg only. Assume that i don't have access to the code.
A step-by-step example would be greatly appreciated.
Using Olly or IDA is a lot of work for nothing.
Use .NET Reflector for decompilation(there is 14-day trial) and download Reflexil plugin to be able to modify code.
Finding the place should not be too hard since you have decompiled sourcecode.
If you cannot find the place you can try one of these:
Connect reflector to Visual studio
Export source code and just run it from Visual studio
If code is obfuscated I cannot help you there, you just must start playing with it till you defeat obfuscation
With Reflexil addon you can simply delete/modify the function
Why not use IDA? You can "easily" nop out the function.

C# winform, App Crashing after using the Video/Audio classes from the Microsoft.DirectX.AudioVideoPlayback dll

I'm working with some Audio files in my app (mp3, wav, ..etc)
I was using the Audio Class from the Microsoft.DirectX.AudioVideoPlayback dll
so first I had to download the dll, after doing so, I went to Add Reference
then I browsed to the dll location, and added it
I also installed the DirectX 9.0 Web Setup
Now, i don't get any problem with just saying: Audio aud;
but if I do something like this:
Audio aud = new Audio(path);
or
Video vid = new Video(path);
if I press Ctrl+F5 the app will crash immediately, If i try to debug, I just can't see the debugging cursor, and if i keep pressing F10 nothing ever happens ..
I put it in a try/catch block, it didn't threw an exception ..
so what's goin on ?
how can i fix this ?
I even tried to make a whole new app, here's the whole code, there's nothing really in it:
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 Microsoft.DirectX.DirectSound;
using Microsoft.DirectX.AudioVideoPlayback;
using Microsoft.DirectX;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Audio aud = new Audio("C:\\Users\\vexe\\Desktop\\Songs\\Kimosabe.mp3");
}
}
}
Any help would be appreciated ..
Thanks in advance ..
add this code to your project:
using Microsoft.DirectX.DirectSound
using Microsoft.DirectX

linking a new windows form with an existing project in c#

I have a c# problem. I have created a project called 'classproject' and I have added several forms to project successfully and successfully ran the program, but there is this other windows form that I just added and when I double-clicked on the form, it took me to the code view and brought out this:
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;
namespace WindowsFormsApplication1
{
public partial class demo : Form
{
public demo()
{
InitializeComponent();
}
private void demo_Load(object sender, EventArgs e)
{
}
}
}
Now, my challenge is that the name of the project is meant to show by default after the namespace as in "namespace classproject" instead of "namespace WindowsFormsApplication1". Please can anyone help me out, what am I meant to do because have tried everything possible. Even if I change the name myself its still going to flag error... someone please help me as soon as possible.
I'm not sure exactly what your issue is. If you change the namespace manually in the code to classproject it should be fine. What error are you talking about? You would also need to change the designer code file as well (probably called demo.Designer.cs).
Just a side note as well. Standard naming convention for C# is to use Pascal-case (as in ClassProject).
You must change namespace in ALL files that was generated by Visual Studio. You can do it manually, or just set cursor on "WindowsFormsApplication1", press F2 and enter new name.
Optionaly you can also change namespace in project properties on Application tab - then all new files added to project will also have namespace that you set there.

WPF User Control Error

I've search the forum, but I coundn't find anything that quite satisfied me.
In Microsoft Visual Studio 2010, when I try to add a WPF User Control I get this error:
"Value cannot be null. Parameter name: objectType"
Then when I want to select the hosted content, I get this error :
"An error occured trying to add references for type 'PolyPuttZe.GameCanvas', or finding the type. Make sure the project references are correct."
I followed this tutorial : http://www.switchonthecode.com/tutorials/wpf-tutorial-using-wpf-in-winforms
Thanks!
EDIT:
This is the code I wrote :
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 System.Windows.Forms.Integration;
namespace PolyPuttZe
{
public partial class Game : Form
{
public Game()
{
InitializeComponent();
}
}
}
Here's a more useful answer for the next person that has this issue - you need to create your WPF user control and build the solution first. Then open/create the form and add an Element Host and set it to your control. This is likely what the accepted answer means as starting over would work as well if you create the WPF control first.

Categories

Resources