Cannot show print dialog on the top of asp.net web control - printdialog

I am currently using System.Windows.Forms.PrintDialog on a custom control in ASP.net because I want to show the print dialog and assign its PrinterSettings to ReportPrintDocument.PrinterSettings after I click Ok button on the dialog.
Here is my code:
using (PrintDialog printDialog = new PrintDialog())
{
if (printDialog.ShowDialog() == DialogResult.OK)
{
ReportPrintDocument rp = new ReportPrintDocument(rvPermit.ServerReport);
rp.PrinterSettings = printDialog.PrinterSettings;
rp.Print();
}
}
My problem is that the print dialog always show behind the web browser and I couldn't know that it is showing or not until I minimize the web browser.
Do you know how to show the print dialog on the top of a web form? Please help.

Here is my solution for now. (Not recommended)
If you can find another one, please share it to me and I'm very appreciate your help on that.
initialize a new window form
Form currentForm = new Form();
show the form
currentForm.Show();
Activate the form
currentForm.Activate();
Set its TopMost to true, so it will bring the form to the top
currentForm.TopMost = true;
Set it to be Focus
currentForm.Focus()
set the form.visible = false
currentForm.Visible = false;
start to show the print dialog
printDialog.ShowDialog(currentForm)
close the new form
currentForm.Close();
try
{
using (PrintDialog printDialog = new PrintDialog())
{
ReportPrintDocument rp = new ReportPrintDocument(rvPermit.ServerReport);
Form currentForm = new Form();
currentForm.Show();
currentForm.Activate();
currentForm.TopMost = true;
currentForm.Focus();
currentForm.Visible = false;
if (printDialog.ShowDialog(currentForm) == DialogResult.OK)
{
if (PrintReport != null)
PrintReport(this, e);
rp.PrinterSettings = printDialog.PrinterSettings;
rp.Print();
}
currentForm.Close();
}
}
catch (Exception)
{
// Prevent any error while calling the printer dialog
}

Related

How to create a share button in laravel?

How can I create a share button, and also get count for each post shared?
In your Blade file that outputs the article, you can output a button. this contains a hidden textarea as a child element. With JS you can put a click event listener on it.
So you can copy the URL to the post. I hope I have understood it correctly?
document.addEventListener("click", function(e)
{
const textArea = document.createElement("textarea");
textArea.value = e.target.querySelector('.url-container').innerHTML;
document.body.appendChild(textArea);
textArea.select();
let successful = null;
let msg = '';
try {
successful = document.execCommand('copy');
msg = successful ? 'successful' : 'unsuccessful';
} catch (err) {
console.warning('unable to copy');
console.warning(err);
}
document.body.removeChild(textArea);
if (successful) {
alert('copied');
// make an XHR call to your App Api for counting
}
});
<button id="share" data-test="test"><textarea class="url-container" style="display:none;">www.your-domain.com/your-post-x</textarea>Share Post X</button>

How to set the navigation controller to take the user to a different view in xamarin ios

My initial view has this code
if (CLLocationManager.Status == CLAuthorizationStatus.Denied ||
CLLocationManager.Status == CLAuthorizationStatus.Restricted ||
CLLocationManager.Status == CLAuthorizationStatus.NotDetermined)
{
Core.FirstLaunch = true;
NavigationController.PushViewController(new LocationServicesVerifyViewController(), false);
}
else
{
NavigationController.PushViewController(new JobListViewController(), false);
}
If the location is not enabled, the location services verify controller is shown, however, the menu has a back button which is taking the user to license activation screen.
How can I change the back button to Job list and clicking it will take the user to job list controller instead?
e.g.,
Solution 1: You need to replace the backbutton and associate an action handler. You could either use text or an image for the Back Button. To do this, in your ViewDidLoad override, add this:
var _backButton = new UIBarButtonItem()
{
Title = "Back",
// Image = UIImage.FromBundle("back_navbar").OriginalRendering(), Need to add the image in Resources for this to work
TintColor = UIColor.FromRGB(0, 70, 113) // Change this to your app colours
};
_backButton.Clicked += _backButton_Clicked;
NavigationItem.SetLeftBarButtonItem(_backButton, animated: true);
And then handle the button press as shown:
void _backButton_Clicked(object sender, System.EventArgs e)
{
var controller = new JobListViewController();
this.PresentViewController(controller, true, null);
}
Solution 2: You could also just remove the unwanted LicenseActivation view controller from the navigation stack so going back won't go to that page. So when you are leaving the LicenseActivation page, in the ViewWillDisappear override, add this code:
var oldControllers = this.NavigationController.ViewControllers;
var newControllers = new UIViewController[oldControllers - 1];
int index = 0;
foreach (var item in oldControllers) {
if (item != this)
{
newControllers [index] = item;
index++;
}
}
this.NavigationController.ViewControllers = newControllers;
Solution 3:
Just use a modal for the LicenseActivation page, so that as soon as you Accept the LicenseActivation, it closes the modal and goes to the next page.
So you are pushing views on to the navigation stack, e.g.,
NavigationController.PushViewController(new LocationServicesVerifyViewController(), false);
so when you press back you are popping the stack and going to the last view. If you don't want this type of navigation you could do this:
Don't push the LocationServicesVerifyViewController to the navigation controller. Rather present it modally like this:
PresentModalViewController(new LocationServicesVerifyViewController(), false);
You will need a close button on LocationServicesVerifyViewController to dismiss.
I would present the JobListViewController by pushing to the navigation controller first then check for the location inside JobListViewController then present the modal LocationServicesVerifyViewController if needed.
OR
Do you need a whole view controller for this? You could just present a popup:
var locationServiceAlertController = UIAlertController.Create("Location Services are off", "Your company... Bla", UIAlertControllerStyle.Alert);
locationServiceAlertController.AddAction(UIAlertAction.Create("Enable", UIAlertActionStyle.Default, alert => Console.WriteLine ("Do your enable stuff")));
locationServiceAlertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, alert => Console.WriteLine ("Cancel was clicked")));
PresentViewController(locationServiceAlertController, true, null);

How to control new window in nightwatchjs

Am using nightwatchjs to automate submission of a support form. Clicking a link using nightwatchjs opens the form page in a new window. How can I set focus on that window? Any help is greatly appreciated.
Use the switchWindow command.
https://nightwatchjs.org/api/switchWindow.html
I try to give you a more detailed explanation with examples of code. Currently I use chromedriver 2.43.1 (installed with npm), selenim standalone 3.141.5 and nigtwatch 0.9.21.
module.exports = {
'Test new tab open': function (browser) {
browser.url('http://localhost:8000')
.click('#a-href-with-target-blank')
// Switch to new tab
browser.window_handles(function (result) {
// 0 == current main window, 1 == new tab
var handle = result.value[1];
browser.switchWindow(handle);
});
// do something
browser.closeWindow(); // Close tab
// Switch to main window
browser.window_handles(function (result) {
// 0 == current main window, 1 == new tab
var handle = result.value[0];
browser.switchWindow(handle);
});
}
};
Hope it helps.

Form validation on Facebook tab

I am using static FBML but I am having trouble debugging a form validation problem. I get the dialog which to me seems like it should return false, but the form submits anyway. I am using Firebug and I see a brief message in Red that I have no chance to read. I appreciate the help :-)
var txt ='Enter Zipcode';
//...
function setError(){
var obj=document.getElementById('mapsearch');
obj.setValue(txt);
obj.setStyle('color', '#FF0000');
}
function valform(){
var obj=document.getElementById('mapsearch');
var val = obj.getValue();
if(val!='' && !isNaN(val) && val.length>2 ){
return true;
} else {
setError();
(new Dialog()).showMessage('Zip Required', 'Please enter your zip code.');
return false;
}
}
//...
Try the "Persist" button if the Firebug/javascript error message in Firebug disappears too quickly. This way all messages are kept between page loads until you click "Clear".

Reusing a tab in Firefox, TabOpen event, and beyond

I followed a tutorial on reusing tabs inside Firefox, and right now my extension does it well. However, I also need to reuse tabs that are opened from outside (from some application, start menu etc.). How do I do this?
I tried adding an event listener for TabOpen event, but when I log the
event.target.linkedBrowser.currentURI.spec
it's value is "about:blank". I expected the actual address that I typed into the address bar (automatically opens in a new tab), or the address that I open from some other application, so I can close that tab immediately, and the focus the right one. What am I doing wrong?
Thanks in advance.
Just in case, here's the code that reuses the tab when a new tab is requested from an extension
function openAndReuseOneTabPerURL(url) {
var wm = Components.classes["#mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var browserEnumerator = wm.getEnumerator("navigator:browser");
// Check each browser instance for our URL
var found = false;
while (!found && browserEnumerator.hasMoreElements()) {
var browserWin = browserEnumerator.getNext();
var tabbrowser = browserWin.getBrowser();
// Check each tab of this browser instance
var numTabs = tabbrowser.browsers.length;
for(var index=0; index<numTabs; index++) {
var currentBrowser = tabbrowser.getBrowserAtIndex(index);
if (url == currentBrowser.currentURI.spec) {
// The URL is already opened. Select this tab.
tabbrowser.selectedTab = tabbrowser.mTabs[index];
// Focus *this* browser-window
browserWin.focus();
found = true;
break;
}
}
}
// Our URL isn't open. Open it now.
if (!found) {
var recentWindow = wm.getMostRecentWindow("navigator:browser");
if (recentWindow) {
// Use an existing browser window
recentWindow.delayedOpenTab(url, null, null, null, null);
}
else {
// No browser windows are open, so open a new one.
window.open(url);
}
}
}
When you receive the TabOpen event, it's too early for the page content to be loaded still. When you receive the TabOpen event, however, you should register for load or DOMContentLoaded. When you receive that event, you should be able to access the URI.
I guess you could extract the wanted behaviour from the implementation in the Tab Mix Plus extension

Resources