Can a FixedDocument be converted to a Drawing.Printing.PrintDocument? - c#

I have written a Label making program for work. It uses an opendialog to pull in the data. Splits it up and put it in tables. No issues there. Setting up the the FixedDocument to print the user control labels as well as the class that stores the Fixed Document Data all work great.
My only issue is I can't stand the restrictions on a WPF document when it comes to text searching and print control. I have gone with a printpreviewdialog but this does not use FixedDocument.
I am needing to know if it can be converted with a simple bit of code or if i Have to rewrite my entire class and go back to the drawing that printpreviewdialog uses.
The code for the call is below.
private void button3_Click(object sender, EventArgs e)
{
var avery = new Avery5160();
DataTable data = (DataTable)dataGridView1.DataSource;
var A5160 = avery.CreateDocument(data);
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = A5160;
ppd.ShowDialog();
}
The error is :
Cannot implicitly convert type 'System.Windows.Documents.FixedDocument' to
'System.Drawing.Printing.PrintDocument'
Thanks for any assistance.

I am not so sure there is a simple conversion. A simple (if not a little time-consuming) method would be to create a preview dialog with a document viewer to simulate what you would be seeing. Then printing using the FixedDocument's DocumentPaginator and a regular PrintDialog.
The answer to this question shows how to do it by creating an XpsDocument that is then used with a custom PrintPreview class.

Related

Controlling a rich text box control that is on form 1 from form 2

I'm sorry if this seems incredibly obvious or a very much commonly asked question, but I've been searching and looking over posts for a while now and i still can't seem to get it.
I'm just getting into learning C# and I set myself a little project, making a word processor around a richtextbox control with a few extra features.
I'm currently just adding in the ability to 'Find & Replace' text, and the below code is working when used on the same form as the rich text box control.
richTextBox1.Rtf = richTextBox1.Rtf.Replace("bob", "bill");
I don't want to use a dialog box or something similar, i'm coming direct from our old friend VB6 though, so i'm not sure if they still even exist as such, so i'm making an external form that acts sort of like a dialog box, where i'd like the user to be able to enter the text to look for and replace and then press okay, and be sent back to the main form, sounds simple huh, probably is, i'm not sure what i'm missing...
private void findReplaceToolStripMenuItem_Click(object sender, EventArgs e)
{
Form3 AboutBox = new Form3();
AboutBox.ShowDialog();
}
I've tried my best at implementing a few of the answers I've read over here, in one of them i managed to be able to control form1 but only if i opened a new instance of it with form1.show(); after the code, which is kind of useless in what i'm trying to achieve.
I've set the richTextBox1.Modifiers to Public, but I'm still scratching my head over this one.
Instead of making the RichTextBox public, I'd add a property to the other form that returns the text from that control, like this:
public class SearchForm : Form
{
public string SearchTerm
{
get { return richTextBox1.Text; }
}
...
When the user closes the "search" form, you can get the search term by referencing the property:
private void findReplaceToolStripMenuItem_Click(object sender, EventArgs e)
{
string searchTerm;
using (var searchForm = new SearchForm()) // used 'using' to dispose the form
{
searchForm.ShowDialog();
searchTerm = searchForm.SearchTerm;
}
// do something with searchTerm
}
You'll find this makes maintenance more manageable too. Changing the names of controls in one form shouldn't require you to make changes in any other form that uses them.

ReportViewer: Two rldc files with same DataSource

I have a report working fine, but now I need develop the same report in other language (english btw).Same layout, same fields.
So I created another .rdlc file and other winform (Maybe it's possible use the same winform, I saw something like that on my research)
My problem is:
After I set all fields and layout, when I select .rdlc file on "choose report" in ReportViewer and do the same way I was doing. Something isn't right because I not getting all BindingSource and all TableAdapter automatically.
On .rdlc file I add all DataSet from DataSource that I was needing.
I Try add manually the TableAdapter from Toolbox because it's showing all components from the other report, but doesn't work.
What is the best way to do something like that? two rdlc file with same data, same DataSource.
I'm thinking create another DataSource file (.xsd).
(sorry my english)
Same data but different languages? Try this:
use a single RDLC file with a boolean parameter like blnEnglishLanguage
for every TextBox used as label set an expression like this: =IIf(Parameters!blnEnghlishLanguage.Value, "Item", "Articolo")
BONUS: give a look at this link to localize your form:
see accepted answer and the answer provided by noelicus.
what i have don is.
you need to set a parent window to IsMdiContainer = true.
and then you can open the windows forms with the report in the same parent.
Remove the form border of the windows form report windows
with the code for the buttons to open it in the mdi Container
awDushiHomesClients OpenawViewClients;
private void ViewClientsMenuB_Click(object sender, EventArgs e)
{
if (OpenawViewClients == null)
{
OpenawViewClients = new awDushiHomesClients();
OpenawViewClients.MdiParent = this;
OpenawViewClients.FormClosed += OpenawViewClients_FormClosed;
OpenawViewClients.Show();
}
else
OpenawViewClients.Activate();
}
void OpenawViewClients_FormClosed(object sender, FormClosedEventArgs e)
{
OpenawViewClients = null;
///throw new NotImplementedException();
}
for the second button use the same code but rename all awDushiHomesClients to lets say awDushiHomesClientsEng."But then your file name"
don't know what kind of information you are showing but if you just need to rename the column text copy and past the first report and rename it.

Writing a GridView to print doc in PrintPageEventArgs (PrintDocument

I'm currently writing an application in ASP.NET/C#, where the user needs to be able to generate PDF's of invoice summary's through the web based admin system.
The customer did not want to use an open source solution such as iTextSharp (stupid, I know) and instead purchased Adobe Acrobat/Reader (not sure which) which come with a virtual PDF printer. So we'll be interfacing with this printer on the server to generate the PDF's.
That's working well - we can easily generate PDF's and display them to the user. However, the way the content is written to the document to be printed (using the Graphics class of the PrintPageEventArgs event) is a bit foreign to me right now. Writing the text and header information is a piece of cake, but what's the easiest way of writing the contents of the GridView to the doucment?
Here's some example code of the sort of thing I'm using:
protected void Page_Load(object sender, EventArgs e)
{
PrintDocument NewDoc = new PrintDocument();
NewDoc.PrinterSettings.PrinterName = "PrinterName";
NewDoc.PrintPage += new PrintPageEventHandler(NewDoc_PrintPage);
NewDoc.Print();
}
void NewDoc_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("Test Header", new Font("Verdana", 18), Brushes.Black, 220, 120);
}
Ended up having to essentially draw the grid myself. Pretty hacky but it works.

Printing a dwf/dwfx file from WPF

I'm currently attempting to print a document from WPF. I'm using the web browser because it contains an active x control which has the autodesk plugin which I need to view the document.
I'm aware that WPF doesn't directly support web browser but I've just integrated the Windows Forms library for this. I've managed to get the code running and even printing, however the document that prints is blank.
I'm not sure if it could possibly be a conflict between the Windows Forms library and WPF; I'm navigating to the document and only printing once it's loaded with no errors thrown.
Here's the code I'm using:
private void btnPrint_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.WebBrowser w = new System.Windows.Forms.WebBrowser();
Uri uri = new Uri("C:\\BOS-BD-4518-000.dwg.dwf");
w.Navigate(uri);
w.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(w_DocumentCompleted);
}
void w_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
System.Windows.Forms.WebBrowser w = (System.Windows.Forms.WebBrowser)sender;
w.Print();
}
One possible hitch could be that the active x control is not being allowed to be load, does anyone know how to force the control to be initialised.
Does anyone have any ideas about how to solve this or another method of printing an autodesk (.dwf) document
Thanks in advance,
SumGuy
Not really an answer of sorts but a solution if anyone out does want to print a .dwf file. Don't, use the new form .dwfx. This is the new file type Autodesk are switching too and its actually a form of XPS which makes things quite easy. You can load it into a web browser without needing active x OR (this is the better way) use the XPS libraries in visual studio because it can be loaded very simply into an XPS viewer.
The code I eventually used to print the dreaded file is below:
private PrintQueue printQueue;
PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
if (pDialog.ShowDialog() == true)
PrintSystemJobInfo xpsPrintJob = printQueue.AddJob(v.FileName, v.FilePath, false);
How easy's that??? There are loads of other ways of doing it using XPS. You can basically just use the dwfx file as an XPS document

Using F1 Help (CHM format) With WPF

I've been working on a WPF application for a while, and the time has come to attach the CHM format help document to it.
But alas! HelpProvider, the standard way to show CHM files in Winforms, has magically vanished and has no counterpart in WPF. I've been trying to use WindowsFormsHost to spawn a new control so I can actually display the help, but essentially it just grabs control of the entire UI.
A little more detail: I've got a menu item that I want to, when clicked, open up the CHM file.
First I set up the WindowsFormsHost...
host = new System.Windows.Forms.Integration.WindowsFormsHost();
helpForm = new System.Windows.Forms.Control();
host.Child = helpForm;
host.Visibility = System.Windows.Visibility.Hidden;
this.grid1.Children.Add(host);
hp = new System.Windows.Forms.HelpProvider();
hp.HelpNamespace = "Somehelpfile.chm";
hp.SetHelpNavigator(helpForm, System.Windows.Forms.HelpNavigator.TableOfContents);
And then I say, voila, reveal yourself.
private void Help_Click(object sender, RoutedEventArgs e)
{
host.Visibility = Visibility.Visible;
helpForm.Show();
hp.SetShowHelp(helpForm, true);
}
I'm not really sure of where to proceed from here. When I show the helpForm, it obscures / overrides the existing UI and all I get is a gray, empty WPF window with no help file.
Any takers?
If you include System.Windows.Forms.dll you can also do:
System.Windows.Forms.Help.ShowHelp(null, #"help.chm");
Also, there's an article here about adding a context sensitive help system to WPF.
Call me crazy, but couldn't you just do:
System.Diagnostics.Process.Start(#"C:\path-to-chm-file.chm");
I am trying out Easy Help with WPF, which also addresses context sensitive help based on key words. So far it seems good. All I need to do is get cracking and write some decent help!
You can use http://www.pinvoke.net/default.aspx/hhctrl.HtmlHelp to open chm help at specified topic and to have more control of how chm window shown.
How about using the Help class instead of opening the file externally

Categories