|
He everyone,
within a application i've use a PrintPreviewControl. When calling ProntPage a error-message occour:
<b>Not ImplementedException System.Collections.ListDictionaryInternal</b>
The error comes up in Line:
<b>e.Graphics.DrawImage ( Image, 10,10 );</b>
But only if the program runs within Windows XP (Svp3). Doing under Windows 7 all works well. Ive also tried all versions of .NET Framework (2.0, 3.0, 3.5 4.0) but this does not change anything.
The development is done with VS2010 under Windows 7
Here are the code to test:
<pre>//Form1.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace PrintImageTest
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main ()
{
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault ( false );
Application.Run ( new Form1 () );
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PrintImageTest
{
public partial class Form1 : Form
{
public Form1 ()
{
InitializeComponent ();
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler ( printDocument1_PrintPage );
}
void printDocument1_PrintPage ( object sender, System.Drawing.Printing.PrintPageEventArgs e )
{
Bitmap Image = new Bitmap (@"C:\Temp\TestImage.jpg");
e.Graphics.DrawImage ( Image, 10,10 );
}
}
}
<br/>//Forms.Designer.cs
namespace PrintImageTest
{
partial class Form1
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose ( bool disposing )
{
if ( disposing && ( components != null ) )
{
components.Dispose ();
}
base.Dispose ( disposing );
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent ()
{
this.printPreviewControl1 = new System.Windows.Forms.PrintPreviewControl ();
this.printDocument1 = new System.Drawing.Printing.PrintDocument ();
this.SuspendLayout ();
//
// printPreviewControl1
//
this.printPreviewControl1.AutoZoom = false;
this.printPreviewControl1.Document = this.printDocument1;
this.printPreviewControl1.Location = new System.Drawing.Point ( 24, 32 );
this.printPreviewControl1.Name = "printPreviewControl1";
this.printPreviewControl1.Size = new System.Drawing.Size ( 401, 432 );
this.printPreviewControl1.TabIndex = 1;
this.printPreviewControl1.Zoom = 0.36783575705731392D;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF ( 6F, 13F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size ( 471, 508 );
this.Controls.Add ( this.printPreviewControl1 );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout ( false );
}
#endregion
private System.Windows.Forms.PrintPreviewControl printPreviewControl1;
private System.Drawing.Printing.PrintDocument printDocument1;
}
}
<br/>
//Programm.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace PrintImageTest
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main ()
{
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault ( false );
Application.Run ( new Form1 () );
}
}
}
</pre>
I would be very happy if someone could help with this.
Thank you in advance
pfotenh
|
|
|
|
|
Hi,
According to the PrintDocument class documentation, I would rather use
e.PageVisual = Image;
than
e.Graphics.DrawImage ( Image, 10,10 );
in your printDocument1_PrintPage method.
|
|
|
|
|
Hi Phil,
thanks for your answer.
Unfortunately i could not use this implementation (as it only available in .Net-Framework 4.0. I have to use .Net-Framework 3.5. There ist not PageVisual available.
Regards
pfotenh
|
|
|
|
|
Did you try a couple of image files? I suspect your image is broken, or just not supported by GDI+.
PS: please use PRE tags when showing code.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi Lic,
thanks for your help.
Yes, i've tried some images. Also i've worked on two differet machines one with Windows 7 one with windows XP.
The images on Windows 7 always appear correct.
Regards
pfotenh
|
|
|
|
|
JPEG images hold properties, that probably is what .NET is using a collection for, which seems to be failing somehow when your code tries to print them.
My gut feeling still is the problem is not related to printing; so I would suggest you try:
- same images in a WinForms Form+PictureBox;
- other images (from a different source); and maybe a different image type, say PNG or GIF.
I'm puzzled by your XP/7 remark. There could be two causes IMO:
- your XP being 32-bit, and Win7 being 64-bit, thus running completely different GDI+ code;
- your systems having different software revisions, older bugs not having been patched up on XP.
In either case, this is the first such thing I hear in this area.
PS: if you want, you can use the "e-mail" widget below to send me a private e-mail, or just check the "Allow private email" checkbox under the edit box; I would then provide you with my address so you could send me an actual JPEG that causes the problems, for me to look in to.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Problem with Process.Start("WINWORD.EXE", selectedFile);
I even put the entire path there: //string MSWordPath = @"c:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE";
Still same result:
the path and file name is:
c:\Users\xxx\Documents\Visual Studio 2010\Projects\zMAP\bridgeWord-Html\bridgeWord-Html\bin\Debug\01 SettingsForVSC#.docx
The MSWord is lunched but these errors are thrown:
Microsoft Word
This file could not be found!
(c:\Users\xxx\Documents\Visual.doc)
(c:\Users\xxx\Documents\...\Studio.doc)
(c:\Users\xxx\Documents\...\01.doc)
(c:\Users\xxx\Documents\...\Studio.doc)
(c:\Users\xxx\Documents\...\SettingsForVSC#.doc)
And then an empty msword page is open.
[I see it breaks at the spaces in between names] ---How to fix this problem?
I wish to open not only a docx file, but a html file also,or a txt file.
thank you.
string path = Application.StartupPath;
private void button3_Click(object sender, EventArgs e)
{
string MSWordPath = "\"c:\\Program Files (x86)\\Microsoft Office\\Office14\\WINWORD.EXE\"";
selectedFile = path + "\\" + listBox1.SelectedItem as string;
Process.Start(MSWordPath, selectedFile);
}
modified on Friday, May 20, 2011 1:13 PM
|
|
|
|
|
Enclose the entire path to all filepaths, even your winword.exe, in double quotes. Your command line would end up looking like this:
"C:\Program Files (x86)\Microsoft Office\Office14\WinWord.exe" "C:\Users\xxxx\Documents\Visual Studio 2010\...\01SettingsForVSC#.doc"
The quotes MUST be part of the string, otherwise any spaces in the path will deliniate a parameter for the command line.
|
|
|
|
|
It worked... THANK YOU Dave !!!
string MSWordPath = "\"c:\\Program Files (x86)\\Microsoft Office\\Office14\\WINWORD.EXE\"";
selectedFile = "\"" + path + "\\" + listBox1.SelectedItem as string + "\"";
Process.Start("WINWORD.EXE", selectedFile);
|
|
|
|
|
Assuming Word is installed and is the default app to process .doc files, there is a much simpler alternative:
Process.Start(myDocFilePath);
This is equivalent to double-clicking "myDocFilePath" inside Windows Explorer, it doesn't care about spaces, and it doesn't need to know where your Word app is and what it is actually called.
BTW: what you wrote earlier, then removed, wasn't correct; a partial success is not a proof of correctness!
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Yes I know, that putting only the fileName+path, that file is opening with the default app.
But what I really want is to open a html file and edit it with msword.
If you have other alternative than: Process.Start(myDocFilePath); please tell.
Though, thank you for your fast response...
|
|
|
|
|
Editing an HTML file with Word is a horrible idea. When saved, the resulting HTML file will be all but useless to a website as Word adds TONS of crap to the file that just hoses up everything. CP gets a fair number of articles posted that were written in Word and saved in HTML format. You should see the carnage that ensues.
|
|
|
|
|
yes ) I know that too "Word adds TONS of crap to the resulting HTML".
But i dont make it for publication, just for my inner use. So, Ill adapt to its creepiness.
If are some hints to make something look good/and right editing with msword, please do tell.
thanks.
|
|
|
|
|
There is no way to get Word to stop screwing up your HTML.
|
|
|
|
|
Dave Kreskowiak wrote: There is no way to get Work to stop screwing up your HTML.
Darn coworkers!
|
|
|
|
|
|
If you want to go against the established file associations, then you need to specify the executable as the first parameter to Process.Start, the arguments concatenated and properly quoted as the second parameter. You already have that.
Using Word for HTML editing is a horrible idea. Type three words and you get a huge file, that should tell enough. Use a real HTML editor, or use Visual Studio, or whatever you choose, but not Word.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
You know, (you deleted what you originally replied with!) just because it worked with Notepad before does NOT mean that you did it correctly.
Even in this latest code, I can see HUGE problems with it. You're code is making some rather large assumptions that will break it if run on another system that isn't identically configured with the exact Office installed in the exact same way it is on your machine.
|
|
|
|
|
I am certain that you guys are right, but for the moment i want to make MY OWN HELPING FRIENDS APPs.
After that, I will make app for distribution, though i wonder if i will really do that.
|
|
|
|
|
It's up the the particular application to interpret the command line in any way it chooses. Notepad is unusual in that it does not require a path containing spaces to be quoted. This is probably because Notepad can take one argument, a filename, and it has been coded to accept spaces within the name. Word has many command line options http://support.microsoft.com/kb/210565[^]and requires that filenames containing spaces are quoted to ensure that they are recognised as one item.
The executable path passed to the Process.Start method does not need quoting as it can only ever refer to one file.
Alan.
|
|
|
|
|
I see a little problem with saving from msWord back to original.
The file is opened all right, but in read-only.
How do I change this?
Sorry for my lack of knowledge... but this things are a bit new to me.
|
|
|
|
|
Do the user under which is running your program have write privileges over the file?
Can you open it by hand (eg. open Word and then open the html file) and save it?
|
|
|
|
|
Yes, If I open it by hand, it is saving ok, loading ok... I am the only user and I have all the privileges over the file R&W.
|
|
|
|
|
Does your app (that contains the Process.Start stuff) do something else with the same .doc path, something Stream-like, File-like, FileInfo-like? If so, did you Close() and Dispose() it properly before calling Process.Start()?
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Yes, it opened the file... and I was not disposed it. Now is working correct.
Thank you.
|
|
|
|