Posts Tagged ‘.NET’

How-to deploy the Crystal Reports Basic Runtime that’s included in Visual Studio 2008

Monday, February 2nd, 2009

This week I’ve to deploy an ASP.NET application containing about 20 reports that have been created with the Crystal Reports Basic Runtime which is included in Visual Studio 2008. (By the way, the application also contains a lot of AJAX-Functionality. It uses the "AJAX Control Toolkit-based" MultiColumnDropDown that I’ve described in a previous post).

When deploying the application to a different machine than your developer-machine, the Crystal Report Basic Runtime must be deployed also. You do that by copying the necessary msi-file to the server and run it. The "necessary" .msi-file is already on your development machine and were installed with Visual Studio 2008. The .msi-files for different plattforms are located in the following paths:

Runtime | MSI-Location
(x86) C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\CrystalReports10_5\CRRedist2008_x86.msi
(x64) C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\CrystalReports10_5\CRRedist2008_x64.msi
(IA64)

C:\Program Files\Microsoft Visual Studio 9.0\Crystal Reports\CRRedist\IA64\CRRedist2008_ia64.msi

(the table above is contained in MSDN-documentation here)

The installation is very simple. You doesn’t need to click anything, simply run the .msi and you see the window below. Just wait until it closes.

crystalReportsBasic

There’s also the possibility to include the msi in your setup-application. For more information on that take a look at this thread in MSDN-Forums.

The PrintForm-Component in the Visual Basic Powerpack for Windows Forms

Friday, January 23rd, 2009

Did you ever wanted to print a Form without calling any native code? Well, with Windows Forms and Visual Studio 2008 this is a really simple exercise. When you design your WinForms-Application you’ll find a Tab Visual Basic PowerPacks in the Toolbox of Visual Studio 2008. In this Tab, you’ll find a component called PrintForm. Simply drop this component on your form, and you’ll find all the functionality you need. Let’s take a look at a small sample by using a very simple Windows Forms application.

The application just has a Browse-Button to browse an image from the filesystem, a PictureBox to display the image and a TextBox displaying the path to the image.

printForm_pic1

The Browse-Button does nothing more than showing an OpenFileDialog and setting the Text-Property of the TextBox to the selected file and assigning the chosen image to the Image-Property of the PictureBox.

private void btnBrowse_Click(object sender, EventArgs e)
{
  var dlg = new OpenFileDialog
    {
      Multiselect = false,
      Filter = "JPEG (*.jpg)|*.jpg|JPEG (*.jpeg)|*.jpeg"
               + "|GIF(*.gif)|*.gif|Bitmap (*.bmp)|*.bmp"
    };
  if(dlg.ShowDialog() == DialogResult.OK)
  {
    txtImagePath.Text = dlg.FileName;
    pictureBox1.Image = Image.FromFile(dlg.FileName);
  }
}

The Form above already contains a "Print Form!"-Button. The eventhandler of that Button is currently empty. Let’s implement it. But before that, go to the designer and drag’n'drop a PrintForm-component out of the Toolbox on the Form.

printForm_pic2

After dropping the PrintForm-component, you’ll find it in the Component Tray of the Windows Forms-Designer. It’s named printForm1 by default. I won’t change that here. Now let’s step to the EventHandler of the "Print Form!"-Button.

To print the form, first a PrintDialog is shown allowing the user to select a printer. Then the settings of the PrintDialog are assigned to the PrinterSettings-Property of the printForm1-component. The Print-Method on that component is called passing in the Form (this) and an Enum-Value specifying to print the full Window.

private void btnPrintForm_Click(object sender, EventArgs e)
{
  var dlg = new PrintDialog();
  if(dlg.ShowDialog()==DialogResult.OK)
  {
    printForm1.PrinterSettings = dlg.PrinterSettings;
    printForm1.Print(this, PrintForm.PrintOption.FullWindow);
  }
}

That’s all! :-) E.g. when I print into my PDFPrinter, the resulting PDF-Document will look like this:

printForm_pic3

Beside the PrinterSettings-Property the PrintForm-Component contains some more important properties . The most mentionable one is the PrintAction-Property. It’s of type PrintAction, an enum in Namespace System.Drawing.Printing. The PrintAction-enum contains three values, PrintToPrinter (the default for the PrintForm’s PrintAction-Property), PrintToFile and PrintToPreview.

So to show a preview of the Print-output, you simply need the following to lines:

printForm1.PrintAction = PrintAction.PrintToPreview;
printForm1.Print(this, PrintForm.PrintOption.FullWindow);

Replace the code in btnPrintForm_Click with the two lines above, and you’ll automatically get a preview, like shown below. But be careful. The user can print out of the Preview. If you’ve no PrinterSettings assigned to the PrinterSettings-Property of the PrintForm, the Print will be implicitly written to the users default-Printer.

printForm_pic4

So, that’s all. Get the sample here.

The first one

Tuesday, November 13th, 2007

Today I decided to start my own blog. So far I enjoyed life just as a blog-reader for the last couple of years. But now there are several reasons to start my own blog:

  • Up to now I just played around with WPF for nearly two years, and I discovered some things I want to share with you
  • I want to post some technical content to find it later again. Also the provider guarantees me a backup of my site. :-)
  • A blog is a great platform to communicate with you and other guys working with .NET, WPF, XAML, C#, LINQ, …

During the next days I’ll provide some stuff just heared and learned from TechEd 2007 in Barcelona.
So stay tuned…