PrintDialog.ShowDialog() instantly closes with CANCEL result

L

Larry Brindise

I have a project that raises a print dialog so the user
can select a printer and click "OK".
I have included a snippet of code. When the "real"
project gets to the
DialogResult = dlg.ShowDialog()
statement, you can see the dialog flash instantly, then
the code immediately drops to the next statement without
giving the user the opportunity to hit any button. The
result is always "cancel". (Not very useful!)
I have copied this code to a "test" project with a single
form/button. When I run this code in the "test" project,
it works as expected - the dialog box remains until the
user makes a selection.
What can I look for in my project that would be causing
the bad behavior in the "real" project? A review of
available properties of the DialogResult does not reveal
anything obvious to me.
Thanks,
-Larry

VB.NET Framework 1.0, CODE>>>>>>

Dim dlg As New PrintDialog()
AddHandler p_doc.PrintPage, AddressOf p_doc_PrintPage
dlg.Document = p_doc
dlg.AllowPrintToFile = False
Dim DialogResult As New System.Windows.Forms.DialogResult
()
DialogResult = dlg.ShowDialog()
'see box for < 1 second and instantly DialogResult
= "cancel" value!!!
 
Y

Ying-Shen Yu[MSFT]

Hi Larry,

In your real project, Are you using STA Threading model or MTA Threading
model?
and I'd also like to make sure if you have added the [STAThread] onto the
Main method.

If you still have problem please be free to reply to this thread and let me
know more about your problem.
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.

--------------------
| Content-Class: urn:content-classes:message
| From: "Larry Brindise" <[email protected]>
| Sender: "Larry Brindise" <[email protected]>
| Subject: PrintDialog.ShowDialog() instantly closes with CANCEL result
| Date: Wed, 12 Nov 2003 09:02:41 -0800
| Lines: 31
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOpPshZ2XQFb2abQQi+dwGbgiFitg==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:56375
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I have a project that raises a print dialog so the user
| can select a printer and click "OK".
| I have included a snippet of code. When the "real"
| project gets to the
| DialogResult = dlg.ShowDialog()
| statement, you can see the dialog flash instantly, then
| the code immediately drops to the next statement without
| giving the user the opportunity to hit any button. The
| result is always "cancel". (Not very useful!)
| I have copied this code to a "test" project with a single
| form/button. When I run this code in the "test" project,
| it works as expected - the dialog box remains until the
| user makes a selection.
| What can I look for in my project that would be causing
| the bad behavior in the "real" project? A review of
| available properties of the DialogResult does not reveal
| anything obvious to me.
| Thanks,
| -Larry
|
| VB.NET Framework 1.0, CODE>>>>>>
|
| Dim dlg As New PrintDialog()
| AddHandler p_doc.PrintPage, AddressOf p_doc_PrintPage
| dlg.Document = p_doc
| dlg.AllowPrintToFile = False
| Dim DialogResult As New System.Windows.Forms.DialogResult
| ()
| DialogResult = dlg.ShowDialog()
| 'see box for < 1 second and instantly DialogResult
| = "cancel" value!!!
|
 
L

Larry Brindise

I've never touched that setting. Where would I look to
answer your question? Both the real and test projects
were developed on the same machine. I am sole
owner/developer of the real and test projects. I have
not purposely changed any such setting.

The real project acts incorrectly regardless of whether I
am running it on my development machine or on any
deployment PC's. I run them side-by-side and the test
project allows the dialog to remain available while the
real project flashes and disappears as previously
described.

-Larry
-----Original Message-----
Hi Larry,

In your real project, Are you using STA Threading model or MTA Threading
model?
and I'd also like to make sure if you have added the [STAThread] onto the
Main method.

If you still have problem please be free to reply to this thread and let me
know more about your problem.
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.

--------------------
| Content-Class: urn:content-classes:message
| From: "Larry Brindise" <[email protected]>
| Sender: "Larry Brindise" <[email protected]>
| Subject: PrintDialog.ShowDialog() instantly closes with CANCEL result
| Date: Wed, 12 Nov 2003 09:02:41 -0800
| Lines: 31
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOpPshZ2XQFb2abQQi+dwGbgiFitg==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:56375
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I have a project that raises a print dialog so the user
| can select a printer and click "OK".
| I have included a snippet of code. When the "real"
| project gets to the
| DialogResult = dlg.ShowDialog()
| statement, you can see the dialog flash instantly, then
| the code immediately drops to the next statement without
| giving the user the opportunity to hit any button. The
| result is always "cancel". (Not very useful!)
| I have copied this code to a "test" project with a single
| form/button. When I run this code in the "test" project,
| it works as expected - the dialog box remains until the
| user makes a selection.
| What can I look for in my project that would be causing
| the bad behavior in the "real" project? A review of
| available properties of the DialogResult does not reveal
| anything obvious to me.
| Thanks,
| -Larry
|
| VB.NET Framework 1.0, CODE>>>>>>
|
| Dim dlg As New PrintDialog()
| AddHandler p_doc.PrintPage, AddressOf p_doc_PrintPage
| dlg.Document = p_doc
| dlg.AllowPrintToFile = False
| Dim DialogResult As New System.Windows.Forms.DialogResult
| ()
| DialogResult = dlg.ShowDialog()
| 'see box for < 1 second and instantly DialogResult
| = "cancel" value!!!
|

.
 
Y

Ying-Shen Yu[MSFT]

Hi Larry,

Thanks for your reply!

If you didn't change that attribute, this might not be the cause. I need a
repro sample to give you the further advices. Is it possible to send me
simplified copy of your project to repro the problem?

Also, since it's a printdialog problem, could you let me know some
information of your system, such as OS version, and print settings. I guess
you didn't have problem in opening the PrinterDialog in other applications
such as notepad.. etc.

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 
L

Larry Brindise

The project is really big. I do not know what to do
next. Where should I send it? I would rather send you
the whole project because, as I stated, when I use the
same code in a simple test project, the print dialog
works OK. The problem with sending the whole project is
that then you have to have a database, etc, which is a
big installation problem.
Ideas?
Thanks,
-Larry
 
Y

Ying-Shen Yu[MSFT]

Hi Larry,

Thanks for your reply,

So it's a big project, it might not be proper to send me the whole project
to repro your problem. Let's try to narrow down the problem,
first of all, could you give me some background info of the problem, such
as
do you use multi-thread in your program?
Also , I'd like you set the Vs.NET to catch the first-chance exception,
then we can get to know if there is there is any error in the internal.
You may set this in "Debug"->"Exceptions", In Exceptions dialog, set all
exceptions to "Break into the debugger" in "When the exception is thrown".

I hope we can find some clue from this. If you got an exception, please
give me some info about it, such as exception name or error code, if you
can provide a stack trace if would be greate. you can open the stack window
by "Debug"->"Windows"->"Call Stacks".

My another quick thought, is it possible to test your program on .NET
Framework v1.1? Is it working properly?

I'll follow up with you on this issue. If you have any updates on this
issue, please be free to reply this thread to let me know.
Thanks!



Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 
L

Larry Brindise

do you use multi-thread in your program?
Also , I'd like you set the Vs.NET to catch the first- chance exception,
then we can get to know if there is there is any error in the internal.
You may set this in "Debug"->"Exceptions", In Exceptions dialog, set all
exceptions to "Break into the debugger" in "When the exception is thrown".

I hope we can find some clue from this. If you got an exception, please
give me some info about it, such as exception name or error code, if you
can provide a stack trace if would be greate. you can open the stack window
by "Debug"->"Windows"->"Call Stacks".
Stack Trace:
tgm1image.dll!tgm1image.frmImage.PrintPartImage
(Boolean CloseAfterPrint = True) Line 871 Basic
tgm1image.dll!tgm1image.M1Images.OpenPartArray
(Object M1ADOConnectionDef = "Provider=SQLOLEDB.1;Initial
Catalog=master;Data Source=muirsqlm1;Extended
Properties="uid=sa;pwd=zzz";Network Library=DBMSSOCN;Use
Procedure for Prepare=1;Auto Translate=True;Packet
Size=4096;Workstation ID=TGNOTE4;Use Encryption for
Data=False;Tag with column collation when
possible=False;CurrM1DB=m1_mg;" {String}, Object M1UserID
= "LBRINDIS" {String}, Object Keylist = {System.Array},
Object ListOfJobs = False {Boolean}, Object
PrintAndCloseFlag = True {Boolean}, Object ErrText = ""
{String}) Line 72 + 0x10 bytes Basic
My another quick thought, is it possible to test your program on .NET
Framework v1.1? Is it working properly?

-Larry
 
L

Larry Brindise

I've just noticed something very interesting that might
help.

There are basically two ways to invoke the code that
opens the printer dialogue:
1. The user the image on the windows form first, then
clicks a button that calls the print routine. This works
fine - that is, the print dialogue opens as expected and
the user can select printer options, etc.
2. The user does not first view the image. Instead, they
call the program with parameters such that the image is
not first loaded onto a windows form, rather it just
loads the image from the datasource, then performs the
print routine. This misbehaves.

Both processes use the exact same "PrintPartImage"
function. I don't know why the system thinks there is
any difference, but there certainly is something
different. Perhaps there is some kind of "cancelled"
action queued somewhere???

Thanks,
-Larry
 
L

Larry Brindise

As I mentioned in a prior posting, this situation is even
more interesting as it works/does not work under certain
conditions. This gives me some hope that it is
debuggable.

Case 1 - the image is viewed first, then printed. The
windows command button calls this PrintPartImage. This
scenario works fine - the dialogue is launched and the
user can select OK, etc.

Case 2 - the image is loaded but not displayed on a form,
rather this routine is immediately called. No windows
form is yet open at this time. The dialogue is launched
but immediately closes.

This code has been in production since the beginning of
2003. Users only let me know of the problem recently, so
I do not know when the problem started. Once upon a time
it worked, so I don't believe there is a dependence on a
windows form being open at the time the dialogue is shown.

Here is the code snippet.
#Region "Print Part Image"
Friend Sub PrintPartImage(ByVal CloseAfterPrint As
Boolean)
'Dim i As Integer
If Me.ImageIsLoaded Then
Try
Dim PrinterOrientationLandscape As Boolean
Dim dlg As New PrintDialog()
AddHandler p_doc.PrintPage, AddressOf
p_doc_PrintPage
dlg.Document = p_doc
dlg.AllowPrintToFile = False
Dim DialogResult As New
System.Windows.Forms.DialogResult()
DialogResult = dlg.ShowDialog()
If DialogResult =
System.Windows.Forms.DialogResult.OK Then
Me.PrintableImage = Image.FromStream
(PrepareImageForPrinting(PictureBox1.Image,
PrinterOrientationLandscape))
p_doc.DefaultPageSettings.Landscape =
PrinterOrientationLandscape
p_doc.Print()
If Not CloseAfterPrint Then
MessageBox.Show("Image printed
successfully.", "Image Manager for M1",
MessageBoxButtons.OK, MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1)
End If
Else
MessageBox.Show("Printing
cancelled.", "Image Manager for M1",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ue As Exception
MessageBox.Show("Could not print the
Image, error = " & ue.ToString, "Image Manager for M1",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Else
MessageBox.Show("Could not print the Image
because no image is currently loaded", "Image Manager for
M1", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub


(BEFORE MISBEHAVIOR - IT FLASHES THE DIALOGUE THEN
INSTANTLY CANCELS)
?dlg
{System.Windows.Forms.PrintDialog}
System.Windows.Forms.CommonDialog:
{System.Windows.Forms.PrintDialog}
printRangeMask: 3
settings: {System.Drawing.Printing.PrinterSettings}
printDocument: {System.Drawing.Printing.PrintDocument}
allowPages: False
allowPrintToFile: False
allowSelection: False
printToFile: False
showHelp: False
showNetwork: True
AllowSomePages: False
AllowPrintToFile: False
AllowSelection: False
Document: {System.Drawing.Printing.PrintDocument}
PageSettings: {System.Drawing.Printing.PageSettings}
PrinterSettings:
{System.Drawing.Printing.PrinterSettings}
PrintToFile: False
ShowHelp: False
ShowNetwork: True

(BEFORE IT WORKS FINE)
?dlg
{System.Windows.Forms.PrintDialog}
System.Windows.Forms.CommonDialog:
{System.Windows.Forms.PrintDialog}
printRangeMask: 3
settings: {System.Drawing.Printing.PrinterSettings}
printDocument: {System.Drawing.Printing.PrintDocument}
allowPages: False
allowPrintToFile: False
allowSelection: False
printToFile: False
showHelp: False
showNetwork: True
AllowSomePages: False
AllowPrintToFile: False
AllowSelection: False
Document: {System.Drawing.Printing.PrintDocument}
PageSettings: {System.Drawing.Printing.PageSettings}
PrinterSettings:
{System.Drawing.Printing.PrinterSettings}
PrintToFile: False
ShowHelp: False
ShowNetwork: True
 
Y

Ying-Shen Yu[MSFT]

Hi Larry,

It seems not easy to find the cause of the problem, maybe we can try some
workaround.
If the Image does affect , is possible to workaround by loading the image
first to a invisible picturebox?
now, since the problem becomes more clear, is it possible to send me a
small repro sample? I really want to help you , however without a repro
sample the complexity of the problem is beyond the scope of the newsgroup,
you may contact our Product Support Service and a open support incident
for it. You may find the PSS phone number on

http://support.microsoft.com

Please be advised that contacting telephone support *will* be a charged
call.
Thanks for your understanding.

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top