The best opinion for print from windows form

Answered The best opinion for print from windows form

  • Dienstag, 6. März 2012 08:07
     
     

    Hello,

    I have form with images, textbox, combobox, checkbox controls. I want value from this controls print, wich is the best way for do that?

    To use report, or printdocument class or something other?

    I never use yet report, where I can find good tutorial for learn how to use report?

    Thanks for help!

    • Verschoben CoolDadTxMVP Mittwoch, 7. März 2012 14:47 Winforms related (From:Visual C# General)
    •  

Alle Antworten

  • Dienstag, 6. März 2012 08:20
     
     

    Hi,

    you can use crystal reports or reporting services (which is microsoft) for creating documents for printing.

    For crystal reports its better to download Microsoft SQL Server 2008 Report Builder for generating reports.


    Bilhan silva

  • Dienstag, 6. März 2012 08:54
     
     

    Ok,

    how can I from example textbox value forward to report? Do you maybe have some example, because I never used before report service?

    First I must generate Chrystal report in Microsoft SQL Server then copy generated script from him in Visual studio or?

    Thanks!

  • Dienstag, 6. März 2012 09:30
     
     Beantwortet Enthält Code

    Microsoft SQL Server 2008 Report Builder is for reporting services which is different than crystal reports.

    If you choose to use crystal reports first you should create a report.  You can create one from right clicking your prject -> add new item-> on add new item window select visual c#->reporting then double click on Crystal Report.

    Once you added the report to your project then add a new field from tool box. then in runtime to populate the field from textbox value use the following code:

    rptMyReport report = new rptMyReport();
    TextObject to = (TextObject)report.ReportDefinition.Sections["Section1"].ReportObjects["textboxname"];
    to.Text = textbox1.Text;
    

    textboxname = is the field name in your report

    You can use crystal reports viewer control to show the report


    Bilhan silva

  • Dienstag, 6. März 2012 18:52
     
     

    Thanks for good answer,

    but I have problem when I add Chrystal Report to my solution;

    I have error when build solution;

    Error    1    The type or namespace name 'ReportMagic' could not be found (are you missing a using directive or an assembly reference?) 

    When I delete the chrystal report everything works ok,

    I don't now where is problem I use Visual Studio 2010, .net 4.0

    Platform: Active (Any CPU)

    Target framework: .NET Framework 4

    I have 3 solution. One solution is ReportMagic (I try Class libary, and windows form application)

    I try everything but not successfully.

    Thanks




    • Bearbeitet Nikola87 Dienstag, 6. März 2012 19:56
    • Bearbeitet Nikola87 Dienstag, 6. März 2012 19:56
    • Bearbeitet Nikola87 Dienstag, 6. März 2012 21:14
    •  
  • Mittwoch, 7. März 2012 10:48
     
     

    Check if your're pointing the right framework (Some times it points to .Net framework 4 client profile).

    To do this. Right click your project-> properties->on Application tab Target framework should be .Net framework 4 not .Net framework 4 client profile


    Bilhan silva

  • Mittwoch, 7. März 2012 12:48
     
     

    Yes, I Checked this, and target device is: .NET framework 4, no client profile,

    I try change the solution, first solution has been class libary, then I serach on google, and find information that solution should not be class libary, only windows form application, I try this, but not successfully.

  • Mittwoch, 7. März 2012 13:53
     
     

    Hi,

    ReportMagic is not a part of Crystal reports, i think you're trying to use a thired party dll. This is what i found on report magic try downloading and installing that component.


    Bilhan silva

  • Mittwoch, 7. März 2012 18:58
     
     

    No, I call my Solution reportmagic (this is my own dll),  he have: one form (for presenting report), and crystalreport, if I delete crystalreport everything work ok (build is successfully), if crystalreport exist in this solutinon, problem when I build the project.

  • Donnerstag, 8. März 2012 11:39
     
     
    Can you upload a sample and give me the link? The problem doesn't seems to like with crystal reports. did you tried to clean and rebuilt?

    Bilhan silva

  • Freitag, 9. März 2012 06:58
    Moderator
     
     Beantwortet

    Hi NikolaServer,

    Welcome to the MSDN Forum. 

    If the data on the form can be all shown without scrolling/data is not complex, I think you can print the form directly:

    Printing Multiple Pages and Tabular Printing: 
    http://www.codeproject.com/Articles/42925/Printing-Multiple-Pages-and-Tabular-Printing
     

    If your data is so complex that you will need to do a lot of caculations with large number of  rows, or you want a reports can be change styles any time, you can use Crystal Reports:

    For web: 
    Step by Step Creation of Crystal Report using its Features Group, Graph, Cross-Tab and Sub Report: 
    http://www.codeproject.com/Articles/142064/Step-by-Step-Creation-of-Crystal-Report-using-its 

    For WinForm: 
    Generate a Report using Crystal Reports in Visual Studio 2010: 
    http://www.codeproject.com/Articles/166291/Generate-a-report-using-Crystal-Reports-in-Visual 

    If you have any questions, please feel free to tell us.

    Best Regards


    Neddy Ren[MSFT]
    MSDN Community Support | Feedback to us

  • Freitag, 9. März 2012 07:03
    Moderator
     
     

    Yes, I Checked this, and target device is: .NET framework 4, no client profile,

    I try change the solution, first solution has been class libary, then I serach on google, and find information that solution should not be class libary, only windows form application, I try this, but not successfully.

    Hi NikolasServer, 

    Maybe you can have a try to reproduce the samples on my previews reply, maybe you can find the issue from there.

    The two links show the workthrough on how to create the Crystal Reports.

    Best Regards


    Neddy Ren[MSFT]
    MSDN Community Support | Feedback to us

  • Sonntag, 11. März 2012 12:25
     
     

    Here is new example how I use crytal report.

    In this project I have some problem.

    http://dl.dropbox.com/u/40075958/CrystalReport.rar

  • Sonntag, 11. März 2012 19:02
     
     

    Thank you for good examples.