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.
Related
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();
}
I am working on C#.
I am creating application which takes input from multiple barcode reader via USB.So,i want to know that from which reader i am getting value
Bar code scanners work by letting the system think their input comes from the keyboard.
So, one way of doing this:
bar code scanners can be programmed to send pre- and or suffixes with every scan.
You could prefix every scan with the e.g. 'F12' key for one scanner and with the 'F11' key for the other scanner. In the main form of your application, in the keypreview event, you scan for 'F12' and 'F11' keys, and if one comes in, you pop up a modal dialog with a textbox that has the focus. The rest of the scanned characters will end up in the textbox of that dialog. If on top op that, you also program an 'Enter' keysequence as a suffix to the scanned code, it would automatically close that dialog (if the dialog is well built). One of the advantages of this pattern is that, if a code is not readable, you can press F11 or F12, and the dialog will pop up and you can manually type the number.
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?
How do I read a message of standard Win message box (Info)?
Using
SendMessage(this.HandleControl, WM_GETTEXT, builder.Capacity, builder);
I can only read the header of the message box or the text of the button, but not the message itself.
thanks.
Notes (from Q&A):
this.HandleControl is a handler to the message box window
Spy++ shows no child controls bar the button. That's what it made me thinking that Message Boxes have their own way of keeping text w/out using labels
It's a legacy app written with delphi, the button's class is TButton as per Spy++, but still there's no controls except of button inside the dialog window.
After checking a notepad window, both Image & Text are 'selectable', I guess my app doesn't use a std MessageBox. still, how do I go about extracting the text out of the thing? I can see that no labels in my delphi app can be selected by Spy++ Finder tool.
The message text is in a label control on the modal MessageBox dialog window. You have to get the window handle to the MessageBox dialog (win32 API FindWindow) then retrieve the window handle to the control (win32 API GetDlgItem) and then retrieve the text from that window win32 API GetWindowText).
EDIT --
TCHAR text[51] = {0};
HWND msgBox = ::FindWindow(NULL, TEXT("MessageBoxCaption"));
HWND label = ::GetDlgItem(msgBox, 0xFFFF);
::GetWindowText(label, text, sizeof(text)-1);
Try simulating a copy operation (Ctrl-C), then fetch the text from the clipboard: messageboxes allow copying the whole content that way (if they're properly done).
The OP commented that: that worked, thanks. I might end up with doing it that way. Ideally we wanted to keep our implementation focus independant, but choosing between a dedicated PC and OCR I'd probably go the first route.
Personally I've tested this in Delphi 6 and it comes out looking like this:
---------------------------
Confirm
---------------------------
You are about to close the program
WARNING: Are you sure?
---------------------------
Yes No
---------------------------
Note: This is based on an answer that was proposed by "Stefan" in the comments to the original Question
I need write a console application like as hiren boot screen:
alt text http://xahoithongtin.com.vn/Images/diembao/2006_10/Hiren2.jpg
User can input a arrow key or a number for choosing. When a menu item is selected, I will fill a background for the selected menu item.
Please give me some guideline or example. Thanks.
The console class has all the core functionality you need.
To set the cursor to any desired position you can use the Console.CursorLeft or Console.CursorTop properties. A little example is already posted here.
For the colors you can use the Console.BackgroundColor and Console.ForegroundColor.
With these properties you should be able to write all this stuff onto the screen. Afterwards you need to check the user input (KeyUp, KeyDown pressed). This can be done by checking the result of Console.ReadKey() method. By setting the boolean paramter to true you can prevent that the pressed character is displayed on the screen itself.
With this base functionality you should be able to write your own helper class to make all this stuff a little more comfortable.
There are several .NET based NCurses libraries around that make creation of console based interfaces easier:
Curses#
MonoCurses
CursesSharp