I have a Controls.ItemsControl (actually a HelixViewport3D) and would like to add it inside a Forms.UserControl.
I already tried this.Controls.Add(new HelixViewport3D());
Where this is a derivative from UserControl
however this resulted in an error HelixToolkit.Wpf.HelixViewport3D' to 'System.Windows.Forms.Control. Which makes sense given that they don't inherit anything from one another. Is there a sort of wrapper class in these situations?
using HelixToolkit.Wpf;
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;
public partial class HelixForm : Form
{
public HelixForm()
{
InitializeComponent();
var _3Dcntr = new HelixViewport3D();
this.Controls.Add(_3Dcntr);//doesn't work
//what we worked out so far
var elemHost = new ElementHost();
}
}
I have also noticed that it's supposed to be possible to host a WPF in a winform using ElementHost.Child but adding this variable/function cannot be found in my example code(missing something?), System.Windows.Forms.Integration.ElementHost tells me that System.Windows.Forms.Integration is missing.
Hosting WPF Composite Control in Winform
Mixing WPF in a Winforms app is not recommended but Microsoft provides a ElementHost in WindowsFormsIntegration namespace.
Here is a more indepth demo of them working
Mixing WPF and Winforms
(sorry for the simple answer I have not mixed them before.)
Related
I am building a form where i can drag and drop button controls.
I followed the tutorial from this link but the code generates an error difficult for me to debug.
Syntax Error
Error code CS1030, "The name 'Helper' does not exist in the current
context
I have tried adding and removing namespaces, using System and using System.Drawing but the same error code is still present.
In a much more extensive code like the actual example, Helper.ControlMover does work, and it is very easy to use. What exactly am i missing in the code below?
Thank you for your time and help.
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 MovingControls
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Helper.ControlMover.Init(this.button1);
}
}
}
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/
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
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.
I'm bit new at this so excuse me if my question is a bit novice. I'm designing a Windows form application to basically replace an old excel spreadsheet then email system(not that its much of a system). After the forms are filled out the answers are saved in terms of public variables, which is fine since it's a small program. Im having trouble referencing my variable from another windows form. Basically, I would like to have the filled out form close and a new "review" window pop up. I'm just using labels that will be show what the value of the variable is. If it was in the same class it wouldn't be a problem but im using two different forms that are partial classes of the same namespace. A bit of code:
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OPS_PictureLoader
{
public partial class Points_Screen : Form
{
public int DevJobStandardsTotal = 0;
And the label I would like to show a "0"(or whatever the program has added to 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;
namespace OPS_PictureLoader
{
public partial class Review : Form
{
public Review()
{
InitializeComponent();
label14.Text = DevJobStandardsTotal;
Again, thanks and feel free to tell me Im totally wrong :D
You need to pass the instance of the first form to the second form's constructor:
public Review(Points_Screen owner)
{
InitializeComponent();
label14.Text = owner.DevJobStandardsTotal;