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.
Related
I'm facing the following issue during setting up tooltips on a WinForms / C# desktop application (using .NET Framework version 4.5).
Application has hundreds of form elements where I would like to display a tooltip.
Current implementation as the following:
I have one toolTip object on my main form
Language file has been loaded and saved in an array
There is a method which suppose to assign the tooltip texts to the different elements accordingly by calling the SetToolTip method on the toolTip object.
E.g.
toolTip.SetToolTip(backBtn, LocalizationFile[0]);
toolTip.SetToolTip(myTextBox, LocalizationFile[1]);
It works fine, tooltips are displayed correctly.
As soon as I reach ca. 30 calls it stops working.
Calling ~30 times SetToolTip method to setup the required tooltips, cause to completely stop displaying the tooltips.
The previously worked tooltip texts are not getting display anymore.
There is no exception or any error message.
Can you please explain me why the toolTip object just stops displaying the texts after calling the SetToolTip method several times? Is there any workaround out there to apply in such cases?
EDIT-1
Following workaround works, but I'm still unsure what is the original problem.
I have created a method to call SetToolTip on the toolTip object, after calling the method, I re-create the toolTip instance using the "new" operator. That solves the issue. However as I want to disable anytime the tooltips on my application I also store all the references in a List. On that list I can iterate over to enable / disable all toolTip references according to what the user wants.
Basically there is a button to toggle the tooltips.
Do you have any idea, why this actually solves the original issue?
List<ToolTip> storeToolTipReferences = new List<ToolTip>(); //store tooltip references
//method begin called to set the tooltip on a control, store the reference of the tooltip and create a new instance
private void SetMyToolTip(Control ctrl, string toolTipText)
{
toolTip.SetToolTip(ctrl, toolTipText);
storeToolTipReferences.Add(toolTip);
toolTip = new ToolTip();
}
//called as the application loads or the user changes the language
private void SetAppLanguage(string[] LocalizationText)
{
storeToolTipReferences.ForEach(e => e.RemoveAll());
SetMyToolTip(ctrl1, LocalizationText[1]);
SetMyToolTip(ctrl2, LocalizationText[2]);
SetMyToolTip(ctrl3, LocalizationText[3]);
.....
}
//logic for tooltip enable/disable in my application
storeToolTipReferences.ForEach(t => t.Active = tooltip_control.Checked);
Thank you!
Hope somebody could give me some advice or point me into some direction.
Im using CefSharp Browser Control in an application, one if the things that im struggling with is when i click on Image Hyperlinks (or any hyperlinks for that matter) it shows a Windows Form where the image is displayed, i fiddled around in the RequestHandler on the OnBeforeBrowse method and added the following:
if (ValidateURL(request.Url))
{
System.Diagnostics.Process.Start(request.Url);
return true;
}
return false;
Where the ValidateURL does some REGEX checks.
What i have noticed is that a Windows Form (Blank Windows Form) still opens up and the image on my Browser (expected).
Where can i double check to not show the blank Windows Form, or hide it?
Version:
Chromium 39.0.2171.95 CEF: r2069, CefSharp: 39.0.2.0
Regards
Jean
I am developing an Outlook plugin using add-in-express. I have added an adxOlFormsManager there. Which contains a Forms collection named ‘adxOlFormsCollectionItem1’. I have set the form class name to as “FlowOutlook.Plugins.Chat.ChatExplorerPane”. Yes, ChatExplorerPane is my ADXOlForm.
I implement a custom event for the my ADXOlform using following code:
private void AddinModule_AddinStartupComplete(object sender, EventArgs e)
{
try
{
var currentChatTypeForm = AddinModule.CurrentInstance.adxOlFormsCollectionItem1.FormInstances(0) as ChatExplorerPane;
currentChatTypeForm.OnChatTypeSelected += currentChatTypeForm_OnChatTypeSelected;
}
catch (Exception ex)
{
Debug.DebugMessage(2, "AddinModule : Error in AddinModule_AddinStartupComplete() : " + ex.Message);
}
}
My Problem is :
If I explorer layout as “RightSubpane” this works fine. But after I changing the explorer layout as dock right (using Properties window), adxOlFormsCollectionItem1.FormInstanceCount is 0. (Which means “currentChatTypeForm” will be null).
What I am supposed to do :
private void ChangeExplorerLayout(AddinExpress.OL.ADXOlForm form)
{
if (form == null) return;
form.XXX = AddinExpress.OL.ADXOlExplorerLayout.DockRight;
}
I wrote above method to change the explorer layout by code. I hope I may be able to call that safely inside AddinModule_AddinStartupComplete, after initializing my custom method. But I need to know the code for replacing ‘XXX’ to complete the method and have a try.
Please advice me to change explorer layout as dock right according to my requirements.
Kushan Randima.
Below is a citation from the manual - see section Accessing a Form Instance in the PDF file in the folder {Add-in Express}\Docs on your development PC.
It is essential that Add-in Express panes are built on the windowing of the host application, not on the events of the application's object model. This means that getting an instance of an Add-in Express pane in a certain event may result in getting null (Nothing in VB.NET) if the call is issued before the pane is shown or after it is hidden. For instance, it is often the case with WindowActivate/WindowDeactivate in Excel, Word, and PowerPoint.
...
So, you may encounter a problem if your add-in retrieves a pane instance in an event above. To bypass this problem, we suggest modifying the code of the add-in so that it gets notified about a pane instance being shown or hidden (instead of getting the pane instance by handling the events above). Use the ADXBeforeTaskPaneShow event of the task pane class (Excel, Word, and PowerPoint) and the ADXOlForm.ADXBeforeFormShow (Outlook) event to be notified about the specified pane instance being shown. When the form becomes hidden, you'll get ADXOlForm.ADXAfterFormHide (Outlook) and the ADXAfterTaskPaneHide event of the task pane class (Excel, Word, and PowerPoint).
That is, instead of getting a form instance in the AddinStartupcomplete event, you can handle the ADXOlForm.ADXBeforeFormShow event.
Hope this helps.
Im programming in WPF (C#) in VS2012
I tried to use this:
How do you click a button in a webbrowser control?
To click button on webbrowser but
.GetElementById gives me an error.
I add: using System.Windows.Forms; and assembly them, but it don't change anything for me.
I think im gonna have a problem with this as well: .InvokeMember("click");
All I've found on the web is that:
http://www.telerik.com/help/wpf/m_telerik_windows_documents_formatproviders_html_parsing_dom_idocument_getelementbyid.html
But I don't know exactly how i can assembly that to VS2012, bcus there are no build in API references in VS2012.
You can use Windows Forms WebBrowser instead of WPF WebBrowser host in WindowsFormHosted control in the WPF app and then you can access those members.
// reference :
/// https://gist.github.com/sphingu/5781036
----------------------------------------------------
// Using WebBrowser for Crowling in WPF
----------------------------------------------------
<WebBrowser Cursor="Arrow" Name="MyBrowser" LoadCompleted="MyBrowser_OnLoadCompleted" />
----------------------------------------------------
// useful methods of WebBrowser
----------------------------------------------------
MyBrowser.Navigate(new Uri("http://google.com"));
private void MyBrowser_OnLoadCompleted(object sender,NavigationEventArgs e)
{
...
// return source of loaded page in WebBrowser
var document=(IHTMLDocument3) MyBrowser.Document;
//Get Element and set its value
document.getElementById("userName").setAttribute("value","myusername");
//get Button on page and fire its click event
document.getElementById("btnSubmit").click();
// Invoke javascript function on page loaded on WebBrowser
MyBrowser.InvokeScript("submitform",param1,param2,...);
//get data from table in page
_innerHtmldata =
((IHTMLDocument3) MyBrowser.Document).getElementById("datatable")
.innerHTML;
}
I am using
System.Windows.Forms.WebBrowser
control in C# for displaying some pages. I want to do some custom work when the user clicks on a url of a page which does not exist.
Basically I want to set some values when the browser displays the following message
The page cannot be displayed
The page you are looking for is currently unavailable. The Web site might be experiencing technical difficulties
How can I get the status so that I can differenciate between a page loaded and error page?
If you cast WebBrowser to the underlying ActiveX implementation, you can access the NavigateError event.
Note: You'll need to add a reference to SHDocVw. Confusingly, this is in the COM tab with the name "Microsoft Internet Controls" with a path of c:\windows\system32\ieframe.dll
private void button1_Click(object sender, EventArgs e)
{
//Note: you need to wait until the ActiveXInstance property is initialised.
var axWebBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
axWebBrowser.NavigateError += axWebBrowser_NavigateError;
webBrowser1.Url = new Uri("http://www.thisisnotavaliddomain.com");
}
void axWebBrowser_NavigateError(object pDisp, ref object URL, ref object Frame, ref object StatusCode, ref bool Cancel)
{
//handle your error
}
You can use the CreateSink method on the WebBrowser control to access the NavigateError event of the underlying WebBrowser ActiveX control. The System.Windows.Forms.WebBrowser control is a managed wrapper for the WebBrowser ActiveX control, but it does not wrap all of the functionality of that ActiveX control. The NavigateError event is available on the unmanaged ActiveX web browser control. CreateSink will allow you to extend the functionality of the System.Windows.Forms.WebBrowser control so you can handle the NavigateError event.
From the documentation:
This method is useful if you are familiar with OLE development using
the unmanaged WebBrowser ActiveX control and you want to extend the
functionality of the Windows Forms WebBrowser control, which is a
managed wrapper for the ActiveX control. You can use this
extensibility to implement events from the ActiveX control that are
not provided by the wrapper control.
MSDN has a full example here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.createsink.aspx