WinForms printing: how can I access the progress dialog? - winforms

When printing in Windows forms, or doing a print preview, a dialog is displayed with text like
Page [P] of [DOC]
where [P] is page number and [DOC] is the name of the document. The dialog also contains a button to allow the user to cancel the print job.
How can I change the text displayed? What I would prefer is text like
Page [P] of [Pages]
where [Pages] is the total number of pages, to give the user an indication how long it will take to print all pages. If possible I would also like to show a progress bar, because when a print job is started, I know exactly how many pages will be printed.

I did this:
Derive your own class from PrintDocument, handling all printing
Set the print controller to a new StandardPrintController (no dialog displayed then)
Display your own dialog, e.g. display and close in OnBeginPrint and OnEndPrint, update in OnPrintPage
If I remember correctly, there was no way to change the text, and since the default dialog is not localizable, we could not use it. It works fine with what I wrote above though.

Related

Can't properly force a component on-screen with scrollComponentToVisible

On a given form, we replace one component with another.
The original component is a series of TextFields, and the new form is some informational text and a button. We hide the first one, and show the second one (the UI designer has both Containers within the form).
I tried using scrollRectToVisible with various values but it didn't seem to make any difference with the scrolling.
continueButtonContainer.setHidden(false);
f.forceRevalidate();
Button continueButton =
(Button)StateMachine.GetInstance().findByName("ButtonContinue", f);
f.scrollComponentToVisible(continueButtonContainer);
f.scrollComponentToVisible(continueButton);
I'm expecting the continue button to be near the top of the screen.
If the screen was scrolled before displaying the continue button, the button ends up right at the bottom of the screen (it was below the bottom of the screen before I put in the scrollComponentToVisible line(s).
After the user scrolls the screen, the button goes up to where it needs to be, and stays there.
If the screen is not scrolled, the button appears where it should be.
I know I can probably add some invisible containers underneath the button and force them onto the screen, but I would rather have a slightly more robust solution.
There are a few issues with this. First you are using forceRevalidate which should be used in very rare cases.
Second it seems that you are invoking this on a Form, this is a bit misleading. While it seems that:
f.add(myCmp);
Adds a component to the form it is really a synonym to:
f.getContentPane().add(myCmp);
That's important because you need to invoke the scrollComponentToVisible on the scrollable container which will actually do the work and ideally be the direct parent of said component. I'm assuming it's the content pane in your case but it depends on layout etc.
The last part is letting the layout do its job. If you are invoking this before the form is showing this might not work. Notice that doing it after a call to show is meaningless as the form might take time with transitions. You can use a show listener or override the laidOut callback method to perform things like this.

DotNetNuke Nested Controls Redirection Method

Any DNN developers out there who have figured this out?
I have a user control (ascx) (DotNetNuke extension) with 4 user controls. There are buttons on the first view form to access the others.
When you access another control, you can access other controls from that control. I'm looking for the best way to redirect the user back to the previous control the user was on regardless of the 'level' of the control.
Here's an example.
1) First view form: People list
Buttons available:
2) User Addresses
3) User Downloads
4) User Videos
5) Another user related module
Let's say I choose 2) User Addresses
On that user control I have buttons to 3, 4 and 5
If I want to return to the first view control (1), I simply use DotNetNuke.Nvigation.NavigateURL and pass in the parameter of the user I was querying about. That works fine.
But now instead of going back to 1 I choose to go to 3) User Downloads
When the user hits the 'Return' button to go to the previous screen (not the browser back button; this is a button on my form) I want to go back to 2) User Addresses, not back to the first view control (1).
I've tried adding the first view control as another control in the same extension, and using EditURL to call it, but the screen shows up blank on redirect (except for the DNN menu etc).
How do I redirect a user to the previous control, not the first control of the module?
If this doesn't make sense, let me know and I'll try to explain it better.
Thanks.
You likely will want to pass a querystring parameter in the request to the various controls so that you can keep track of where they were, and how to get back.
Example:
Instead of just calling ctl=controlvalue try calling ctl=controlvalue&prevvalue=edit
THen you can wire up your Return code to use the querystring value of "prevvalue"
Chris
Check out my DNNHero.com video tutorials on Module Views, Settings & Navigation. I give code and instruction on different ways of doing module view navigation.
I decided to write a custom solution for this. It works really well, but it's a bit involved.
1) I wrote a SourceType enum to list the different forms in my application.
2) Any page can serve as the 'base page." On form load I read a property in settings for "base page url" and if it's not there yet, I write the base page's rawurl to the setting along with the enum value of which form (SourceType) it is.
3) Since sub-controls all use the same settings as the base page, whenever navigation occurs, I pass in the base page's enum value to the new form; in the new form I read the base page URL in the Page_Load of the new form and, if the current form's enum value is different from the enum value passed in (which it is), I use that base URL for the link 'back'.
4) If the user goes to another form from the second form, the process is repeated. But I pass both 'prevous' form enums to the third form so it shows two links to choose from to return to.
5) This can be repated as long as possible. One caveat: you have to remove the current form from the SourceType enum before you pass the SourceForms property back to a previous form; if you don't do this, the form you are coming from will also be listed as a 'go back to' form which you don't want.
Hope this helps someone having trouble figuring out a clean DNN redirection solution within multiple controls in a module.
If this isn't clear hit me up and I'll show some of my code.

Powershell: How to open a file from a separate window

I'm using PowerShell for about a week now. I am able to open a specific URL and fill in my username and password automatically. I can also navigate to a certain page where multiple files can be found to download.
I use the following command to select a certain file to download:
$ie.navigate2('http://www.example.com/resource.aspx?ResourceID=GetDocStoreFile&EntryID=1234')
What happens next is that a second window will open, named "file download". There are three buttons: open, save and close.
I don't want to press the "open" button manually, but would like the script to do that for me and then goes back to the original window to select another file. Any suggestions?
If you use a download URL, I don't think you can interact directly with IE using the COM object, because there's no document. Once the dialog box opens, all of the object's properties become null. You can use the method I posted here: How to perform keystroke inside powershell? AppActivate will work to activate a dialog box by title.
The % represents the the ALT key, so if the underlined letter of the button you want to click is O, you'd invoke SendKeys like this:
$wshell.SendKeys('%O')

WPF webbrowser "document modified" alert

I am hosting a WPF webbrowser control in a WPF page.The webbrowser displays a WORD document which i display using webbrowser Navigate method. Now if i make any changes to the word document and then without saving i navigate to a different page i get a WORD message saying that "The document has been modified. Do you want to save the changes?".
I do not want to display this message as we have our own way of detecting changes and prompting the user if he wants to save or not.I should also mention that when i navigate away from the page i set the browser to "about:blank" so that WORD releases the handle to the file before navigating away.
I have tried the following options but it didn't solve my problem.
wordApp.DisplayAlerts = WORD.WdAlertLevel.wdAlertsNone;
wordDoc.Saved = true;
I have a method "SetBrowserDocumentAlerts" where i have tried one of the above two mentioned options and i call it after navigating to "about:blank"
Please also note that i am not allowed to Quit the wordApp or close the wordDoc. It gives a error that this operation is not available as WORD is in use in another application.
Please suggest how i can stop the above alert message from WORD.

Windows Mobile ShowDialog form's title bar is not visible

In my Windows Mobile project, I have a form (let's call it form M to help keep thing straight) that I need to display modally, so I am using the ShowDialog method on a new copy of the form. When I show it from a form (form A) that takes up the whole screen (WindowState Maximized, Location 0,0, all other properties default except for name, the designer picks this up and shows it without a title bar), it shows up fine with the title bar intact.
However, if I display another modal window on top of this form (form B) that takes up the whole screen and uses the same form properties as form A, and then try to show the modal dialog form M from that form, the title bar is not visible and I can see the top part of form B behind it. Form M also has all default properties except for ControlBox False, and as such shows up in the designer with the title bar.
Any ideas as to what to look for? I have tried just about every combination of manipulating the properties of the parent and modal forms (WindowState, FormBorderStyle, ControlBox, TopMost, etc.) and have not found a combination that works yet.
It exhibits the same behavior both in the Windows Mobile 6 Classic emulator and on my device.
Here is what the form M is supposed to look like, which it does when shown on top of form A:
Good Form http://imagebin.antiyes.com/images/0710161001266357909_33.png
And when form M is displayed on top of form B (and form A):
Bad Form http://imagebin.antiyes.com/images/0020949001266357931_33.png
(These screen captures are taken from my Dell Axim X51V, which has a 480x640 screen.)
This project worked fine in the past, I just converted it from VS2005 to VS2008, and I am wondering of something in the conversion is causing this to happen.
EDIT: I noticed that this is happening with other forms with title bars in my application that try to show on top of form B, and it is exhibiting the same behavior. If when this happens, I press the Calendar hardware button to open up the calendar application, and then press Ctrl+Q (I am using MyMobiler for screen shots and keyboard control of the device), the Calendar window goes away and the form M shows up, this time with the title bar showing just fine.

Resources