In a windows store app project , I have a pdftron.PDF.PDFViewCtrl MyPDFViewCtrl
I then have a button that when I tap, I call a method that should be used to print the document loaded to the MyPDFViewCtrl
I tried with something like this:
private void Print_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
pdftron.PDF.PDFPrintManager MyPrintManager;
MyPrintManager = pdftron.PDF.PDFPrintManager.GetInstance();
Windows.ApplicationModel.Resources.ResourceLoader loader = ResourceLoader.GetForCurrentView("Printing");
MyPrintManager.SetResourceLoader(loader);
MyPrintManager.UnRegisterForPrintingContract();
MyPrintManager.AddStandardPrintOption(Windows.Graphics.Printing.StandardPrintTaskOptions.MediaSize);
MyPrintManager.AddStandardPrintOption(Windows.Graphics.Printing.StandardPrintTaskOptions.Orientation);
MyPrintManager.AddUserOptionPageRange();
MyPrintManager.RegisterForPrintingContract(docpdf, docpdf.GetDocInfo().GetTitle());
}
But when I press the button nothing happens.
Am I doing it wrong?
Related
I have a windows webview2 application where we are automating 3rd party website with too many nested iframes and I want to execute javascript in a particular iframe. I want to know how get CoreWebView2Frame instance for the particular iframe using WebView2. Microsoft documentation didn't help.
I am looking for an example or a documentation to work with CoreWebView2Frame Class and shows how to execute javascript in a particular iframe by using CoreWebView2Frame.ExecuteAsync().
I have gone throught the this thread but it's too difficult for me to understand.
You can get a CoreWebView2Frame by handling FrameCreated event and use it later.
Example:
In the following example, the WebView2 browses this Uri, then we find the iframe inside the page, and store it for later use. Later when the user clicks on a button on the WinForms app, using ExecuteScriptAsync method of the iframe, we click on a link inside the iframe programmatically.
To do so, drop a WebView2 and a Button on the form. Handle Load event of the form and Click event of the button and modify the code like this:
//using Microsoft.Web.WebView2.Core;
CoreWebView2Frame sampleFrame;
private async void Form1_Load(object sender, EventArgs e)
{
webView21.Source = new Uri(
"https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_link_test");
await webView21.EnsureCoreWebView2Async();
webView21.CoreWebView2.FrameCreated += CoreWebView2_FrameCreated;
}
private void CoreWebView2_FrameCreated(object? sender,
CoreWebView2FrameCreatedEventArgs e)
{
if (e.Frame.Name == "iframeResult")
{
sampleFrame = e.Frame;
}
}
private async void button1_Click(object sender, EventArgs e)
{
if (sampleFrame != null && sampleFrame.IsDestroyed() == 0)
{
await sampleFrame.ExecuteScriptAsync(
"document.getElementsByTagName('a')[0].click();");
}
}
Now if you click on the button, the link which is inside the iframe will be clicked.
In windows application, I want to show for example my pc name when I use toolStripStatusLabel and code like:
private void toolStripStatusLabel2_Click(object sender, EventArgs e)
{
string CurrentMachineName = Environment.MachineName;
toolStripStatusLabel2.Text = CurrentMachineName;
}
after I just build this application show that type not show pc name
but if I click to pc name that time show my pc name
after click show pc name
but I need to show when my from load after auto load my pc name
I am using C# with windows application.
Move you code to form_Load event instead of label_Click , e.g.
private void Form1_Load(object sender, EventArgs e)
{
toolStripStatusLabel2.Text = Environment.MachineName;
}
as it is obvious from _Click name - this event will be fired after specific control would be clicked
And _Load - on control initialization
To print document I have created separate WindowsApplication and each time I want to print any document I call that application with path as parameter and Print application have below code:
public static void Print(string path)
{
WebBrowser wb = new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
wb.Navigate(path);
}
public static void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser wb = (WebBrowser)sender;
if (wb.ReadyState.Equals(WebBrowserReadyState.Complete))
{
((SHDocVw.WebBrowser)wb.ActiveXInstance).PrintTemplateTeardown += Print_PrintTemplateTeardown;
wb.ShowPrintDialog();
}
}
void Print_PrintTemplateTeardown(object pDisp)
{
_Application.Exit();
}
When I call Print aaplication, using "WebBrowser" control it loads document and show Print Dialog using "wb.ShowPrintDialog();".
On Print Dialog when I click Print or Cancel I got PrintTemplateTeardown event where I asks Application to Exit (To close application).
Now I want to remove "SHDocVw" dependency from my Print Application due to some security issue while installing on client's machine through Internet.
If I remove "SHDocVw", is there any alternate event or solution available that achknowledge me that PrintDialog is closed?
I'm making Windows universal app using Visual Studio 2013. I'm trying to accomplish something like in this article.
On the main page I have many pictures. After clicking on one of these pictures the user goes to another page, which has a check box.
After user checkes the check box, I have to change the image on main page.
I don't know if this code is correct, but I'm doing something like this for second page
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
points.Text = (Convert.ToInt32(points.Text) + 4).ToString();
var currentCheckBoxItem = sender as CheckBox;
if (currentCheckBoxItem.IsChecked == true)
{
otra.bedre1.Source = (new Uri("ms-appx:///Assets/complete.png", UriKind.Absolute));
// }
But this is code for mainpage where can choose task:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
bedre1.Source = ImageSource;
}
Any ideas?
You would need to store the name and Checkstatus as fields inside SQlite database so that its available even after the app is closed. So you would need to do some research on it.
I want to click event button in webbrowser object.
Button is clicked I want to reach out and write the code? For example, the login button is clicked on the webbrowser object in the pop-up on the site to capture the event and would like to write the code?
I write an example for you(how get event clicked button):
private void Form1_Load(object sender, EventArgs e)
{
//Or navigate to your url
webBrowser1.DocumentText = "<html><body><button id=\"btn1\" type=\"button\">Click Me!</button><button id=\"btn2\" type=\"button\">Click Me!</button></body></html>";
}
Call Click event:(when page loaded)
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.Click += new HtmlElementEventHandler(Document_Click);
}
Get Active Element When User click on document
void Document_Click(object sender, HtmlElementEventArgs e)
{
//Check Element is Button
if (webBrowser1.Document.ActiveElement.TagName == "BUTTON")
{
if (webBrowser1.Document.ActiveElement.Id== "your button id")
{
//Do someting
}
}
}
If I understand correctly, you're using the WebBrowser control in C# WinForms and you would like to fire an event when a button is clicked.
The control doesn't have a click event, but the Document does. To do this you can use WebBrowser.Document.Click event and then loop through the HTML elements to find the one that was clicked.
web.Document.Click += new HtmlElementEventHandler(Document_Click);
This link will help also: webbrowser-control-get-element-by-type