Update PDF in windows form without losing focus - c#

I'm developing a PDF creator using Windows Forms application in Visual Studio Community 2017. I'm using MigraDoc to generate PDFs and they are directly created by a series of data inserted by the user in textboxes.
The page for inserting and displaying the data is the same, because I want a real time update of the PDF document preview. To display the PDF I'm using an axAcroPDF element obtained in the COM section after the installation of Adobe Reader.
In order to update the PDF document I have written a class that simply introduces the new elements (I use a Leave event trigger on textboxes to call the update) and load the new PDF file inside the axAcroPDF element:
axAcroPDF1.LoadFile(filename);
The problem is the fact that each time I insert new data in one of the textboxes and the leave event is triggered it is like the entire form is reloaded and I lose focus on the textbox I was writing on (data inserted remains but the focus gets totally lost and the writing cursor is not preserved). This happens to the other textboxes if I click on another one or if I use tab to move to the next one. Notice that the PDF is correctly updated. Is there any method to avoid this problem and update the PDF section without losing focus on textboxes? Is it also possible doing that on a changetext event listener for those textboxes?
Here is an extract of the code use. The function updateText is called when a changetext event is detected on the textbox:
private void updateText(object sender, EventArgs e)
{
updateDocument();
axAcroPDF1.LoadFile(filename);
TextBox s = (TextBox)sender;
s.Focus();
}

Related

PDF995 set Product code to create 2 documents

I have a c# method that needs to create two documents separately using PDF995. The simplified version:
public void PrintDocuments(PrintDocument report1, PrintDocument report2) {
PrintUtility.SetPDF995Key(); // Method to set the product code in the registry.
report1.Print(); // PDF995 "Save as" dialog box appears here.
PrintUtility.SetPDF995Key();
report2.Print();
}
In order to create a document and avoid having all the PDF995 advertising banners appear, I first have to set the Product Code as a Registry item. However as soon as you click on Save in the PDF995 Save File Dialog, the product key is blanked out, which means I would have to set the Product Code again to create the second document.
The problem is, the Save File dialog box is displayed as an asynchronous / modeless dialog box, which means that the code which creates the second document is reached before the user has had a chance to click on Save for the first one.
So now, even though the Product Code is set a second time, clicking on Save for the first document will blank it out, and because the program has already passed the call to the PrintUtility.SetPDF995Key() method before printing the second one, it will still be blank when the second Save File Dialog appears and so I get the annoying "Trial version" banners.
So is there any way around this? e.g. is there a way to make the Save As dialog Modal, or an event when "Save" is clicked that can be fired so I can call PrintUtility.SetPDF995Key() immediately, or some way of permanently setting the Product Code or something else?

SetAttribute not working in WebBrowser Control

I am developing automation windows application in C# using web browser control.
To set the values to the controls, I am using SetAttribute property.
It works fine for all the controls but the text box which consist watermarking
For example
The following is my coding
WebBrowser.Document.GetElementById("ctl00_Content1_dob_txbx").SetAttribute("value", "09/17/1976");
While running the application, the textbox holds the value like watermarking
For example
while clicking the submit button the date getting vanish. How can I set the date in the watermarking text box?
How can I achieve the following output
Note:
In the website the Watermark achieved by ajax WatermarkExtender
I have found the solution
I have set the value in WebBrowser_ProgressChanged event now its works fine
private void automationWebBrowser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
{
if (automationWebBrowser.Document.GetElementById("ctl00_Content1_dob_txbx") != null)
automationWebBrowser.Document.GetElementById("ctl00_Content1_dob_txbx").SetAttribute("value", "09/17/1976");
}

How to SAVE edited Treeview node text in C# Visual Studio 2010

I am trying to edit treeview node names in a treeview (they become editable on a button click ) and then I want them to remain saved (if I exit and enter the aplication again, the new, edited names should be displayed), BUT they always revert to the original name(text) on program reentering.
private void button1_Click(object sender, EventArgs e)
{
treeView1.LabelEdit = true;
}
Questions is how to make the new treeview node names be saved after editing, so when I enter the aplication again they don't reset to the old ones.
You can use the event on application shutdown to manually iterate over the TreeView and save the data to a file. Then when you applications starts again read them and populate the TreeView.
You cannot edit your project by modifying the developped program runtime.

word interop onpreviewclosed event

Scenario:
Existing winforms application with embedded word using dsoframer
Problem:
When user hits preview and exits preview, the fields are showing the codes like '{FORMTEXT}' instead of the actual values. When I click on print options on print preview, the 'Show field codes instead of their values' option is disabled. Don't know why.
I am looking to achieve previewclosed event so I can iterate through the fields and set the field.ShowCodes to false.
The print options are not relevant to what the user sees when print preview exits. Word has no event that triggers for print preview. But you don't need to iterate through the fields to ensure that field codes are not displaying. Use:
Document.ActiveWindow.View.ShowFieldCodes = False
Is there a way to override the functionality of the preview exit? Then you can send a callback before you exit the preview.

Tree View / File View Control for C#

I have been looking for a C# tree control for displaying a file system that has the following capabilities:
Select a starting directory. I don't always want to start at a "default" top directory level.
The ability to grab an event when the user double clicks on a file in the tree. I want to handle opening the file within my application.
I have been looking at this C# File Browser. Unfortunately, I have not been able to figure out how to do meet my second need. (If anybody can clear that up for me, I would like that even better.) Thanks for any help.
Hi I've looked at the C# File Browser and Find a way to handle your 2nd requirement. You could try adding ItemActivate event on the fileView control (under Browser User Control of the FileBrowser project) and get the selected item(s) when handling it. ItemActivate event is triggered on every double click of an item. Here is the sample code:
private void fileView_ItemActivate(object sender, EventArgs e)
{
//Loop thru all selected items
foreach (ListViewItem item in ((BrowserListView)sender).SelectedItems)
{
//Do your stuuf here. MessageBox is only used for demo
MessageBox.Show(item.Text);
}
}
Edit by Original Question Writer: To see all of the source, look at the code posted by cipriansteclaru in the comments section of the FileBrowser. You have to actually edit the FileBrowser source to gain this functionality (which is what this answer was demonstrating).

Categories