I’m working in WPF .Net framework project, and I need rendering byte[] of database on a component on screen.. I can do this ? I tried webBrowser component, image component but didn’t work.
Example of my attempt: pdfParaExibir is a WebBrowser native component
private void RenderizarPdfEntrega(FileStream pdf)
{
//pdfParaExibir.NavigateToString(pdf.Name);
pdfParaExibir.Navigate(new System.Uri("about:blank"));
pdfParaExibir.Navigate(new System.Uri(#"C:\temp\teste\Luiz3.pdf"));
//pdfParaExibir.NavigateToString(#"C:\temp\teste\Luiz3.pdf");
}
I tried webBrowser component, image component but didn’t work.
My expectations is show the pdf file on screen without possibility of save on local machine.
Don't use a URI, call the method that accepts a string:
<WebBrowser x:Name="theBrowser" />
And then in code-behind:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.theBrowser.Navigate(#"c:\somefolder\yourfile.pdf");
}
}
Related
I want to use Google blockly in my C# Window Form. I'm using inbuilt Webbrowser in my application.
Here is Code :
namespace WbView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
WebBrowser browser = new WebBrowser();
browser.Navigate("https://blockly-demo.appspot.com/static/demos/interpreter/step-execution.html");
browser.Width = 800;
browser.Height = 600;
this.Controls.Add(browser);
}
}
}
When I'm running it first time I got Script Error like this
But After that I changed some Registry entries and it works according to modern browsers
Registry Entries
But the Problem is Now I'm unable to use mouse to drag and drop Blocks not even zoom in or zoom out what I can use is just the toolbox to show blocks and nothing else.
Does anyone faced this type of Problem?
What have I done:
1. I have used CefSharp and it was works perfectly. but CefSharp Supports only > .net v4.x.x but I want that my application supports min. .NET v3.5
I want that my Application support windows 7, 8, 10
What version of Windows do you need to support? If it's 1803 (this years April update) you can and should use this new/modern webview.
https://blogs.windows.com/msedgedev/2018/05/09/modern-webview-winforms-wpf-apps/
Programmatically adding WebView
After installing the NuGet package, you can add the WebView to your application like any other control. The WinForms version of the control is in the Microsoft.Toolkit.Win32.UI.Controls.WinForms namespace.
using Microsoft.Toolkit.Win32.UI.Controls.WinForms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Initialize WebView and add it to the Window's controls
var wvc = new WebView();
((ISupportInitialize)wvc).BeginInit();
wvc.Dock = DockStyle.Fill;
Controls.Add(wvc);
((ISupportInitialize)wvc).EndInit();
// You can also use the Source property
wvc.Navigate(new Uri("https://www.microsoft.com"));
}
Here is the Nuget: https://www.nuget.org/packages/Microsoft.Toolkit.Win32.UI.Controls/
Install-Package Microsoft.Toolkit.Win32.UI.Controls -Version 3.0.0
The browser component you are using right now is not good for modern web stuff.
is there's a way to use flash file inside WPF c# application with Transparent back ground ? i tried this
public Form1()
{
InitializeComponent();
getdata();
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
axShockwaveFlash1.Movie = #"c:\users\ahmed\documents\visual studio 2013\Projects\WindowsFormsApplication1\WindowsFormsApplication1\loading10.swf";
axShockwaveFlash1.Play();
}
and this
axShockwaveFlash1.BackgroundColor =0;
and many below ! any idea ? i still get back color behind the file .
You can't do it by code at runtime.
Solution : Set (WMode) transparency via menu in the component settings (in Designer).
Find similar options to as shown in VB picture below:
I wanted to automate filling of PDF forms.
So I created a WinForms project in VS2013, Added Adobe PDF Reader control, dragged control on to the form.
No errors. Control is displayed on the form.
However in the code of the form when I try to put in:
axAcroPDF1.LoadFile
The LoadFile method is not visible at all.
The project .NET target is set to 4.5.1. I even tried 4.5 and lower.
The AxHost wraps only the Active X Control. The LoadFile Method is a method from the COM Class from your Adobe Control.
You need to implement this via a InvokeMember:
public void LoadFile(string path)
{
this.GetOcx().GetType().InvokeMember("LoadFile", BindingFlags.InvokeMethod |
BindingFlags.OptionalParamBinding, null, this.GetOcx(), new object[1] { path });
}
where this is the AxHost control.
Hosting WPF in winform is explained here Walkthrough: Hosting a WPF Composite Control in Windows Forms. I explain the problem in the most simple way: just create a winform project. Then I create another project WPF User Control Library. On User control library I add one button and name it button1. Then in xaml.cs file i create one public function which looks like this:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public void SetText(string text)
{
button1.Content = text;
}
}
I add that project as a reference in winform so I can add control to my winform. In winform I add one button and create button onClick event. The code looks like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
wpfButton.SetText("asd 12_2_a_s");
}
}
And now the party begins. I compile the project and the final looks like that:
So if I click on left button, on right button there should show string looks like this: "asd 12_2_a_s". But, what is happening is always first "_" is missing. That I get this:
The primitive solution that problem is just to write doubles "__" wpfButton.SetText("asd 12__2__a__s");
And that works. But my question is: Is this is actual bug or I missing something?
The underscore in the text/content of a control is a character used to indicate the access key. You can escape it by using a double underscore __
"t__est"
Haven't tested this, but you also could use the # sign. #"t_est" will output t_est
EDIT: # Doesn't work for setting Text/Content Properties.
I am trying to open a WPF-window from a Windows Forms application. The Windows loads, and the functionality of the WPF-window is as it should be, but the images i added to some buttons in my WPF-window do not get shown. The build action property of the images has been set to "Resource". I am loading from the WinForm App with this code:
private void button1_Click(object sender, EventArgs e)
{
var wpfwindow = new WPF.View.MainWindow();
wpfwindow.Show();
}
What can i do to solve the problem?
In WinForms there is no WPF System.Windows.Application active, therefore 'pack' uri prefix is not recognized and resource images referenced as 'pack://some image uri' cannot be loaded.
Either register uri prefix:
if (!UriParser.IsKnownScheme("pack"))
{
UriParser.Register(new GenericUriParser
(GenericUriParserOptions.GenericAuthority), "pack", -1);
}
or try to create an instance of Application class