Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Printing doesn't work

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Printing doesn't work
Link Posted: 15-May-2006 11:13
The printing sample in the demos supplied by you doesn't work. When I click print, nothing happens.
If I use the same code in my application, nothing happens either:

            PrintSettings ps = new PrintSettings();
            ps.PrinterSettings = new PrinterSettings();
            ps.PrinterSettings.PrintRange = PrintRange.SomePages;
            ps.Options = PrintOptions.ShowMarginsInPreview;
            ps.Options |= PrintOptions.ShowPrintDialog;
            ps.Options |= PrintOptions.ShowPreviewDialog;
            ps.Options |= PrintOptions.FitToPageWidth;
            ps.DocumentName = \"FlyGrid.Net Print/Preview Sample\";
            ps.Header = \"Current Date: \" + PrintSettings.ShortDateMacro + \"\\tDocument:\" + PrintSettings.DocumentNameMacro + \"\\tCurrent Time:\" + PrintSettings.ShortTimeMacro;
            ps.Footer = \"\\tPage [\" + PrintSettings.PageNumberMacro + \"] of [\" + PrintSettings.PageCountMacro + \"]\\t\";
            grid.ActivePort.PrintGrid(ps);
Link Posted: 16-May-2006 09:22
It seems thos you've used an old version.
I've just checked, see the screenshot:
Link Posted: 16-May-2006 09:30
do this: unheck \"Show Print Dialog\" and the preview dialog will come up empty
Link Posted: 16-May-2006 09:31
btw, how can I make the print black & white only with no background colors or anything.
Link Posted: 16-May-2006 09:55
Yes, ps.PrinterSettings.PrintRange = PrintRange.SomePages; is used for PrintOptions.ShowPrintDialog, or you should specify pegaes before PrintGrid call.
[c#]
private void printPreviewBtn_Click(object sender, System.EventArgs e)
{
  PrintSettings ps = new PrintSettings();
  ps.PrinterSettings = new PrinterSettings();
  ps.Options = PrintOptions.ShowMarginsInPreview;
  if (showPrintDlgChkBox.Checked)
  {
    ps.PrinterSettings.PrintRange = PrintRange.SomePages;
    ps.Options |= PrintOptions.ShowPrintDialog;
  }
  if (showPreviewDlgChkBox.Checked)
    ps.Options |=  PrintOptions.ShowPreviewDialog;
  if (fitToPageWidthChkBox.Checked)
    ps.Options |= PrintOptions.FitToPageWidth;
  ps.DocumentName = \"FlyGrid.Net Print/Preview Sample\";
  ps.Header = \"Current Date: \"+ PrintSettings.ShortDateMacro +
          \"\\tDocument:\" + PrintSettings.DocumentNameMacro +
          \"\\tCurrent Time:\" + PrintSettings.ShortTimeMacro;
  ps.Footer = \"\\tPage [\"+PrintSettings.PageNumberMacro+\"] of [\"+
         PrintSettings.PageCountMacro+\"]\\t\";              
  gridFunctionalityGrid.ActivePort.PrintGrid(ps);      
}



how can I make the print black & white only with no background colors or anything.

there are some ways:
[list]
  • You can use special IStylist that determining PrintPreview and uses B/W colors and doesn't fills background. DrawCellInfo provides special flag DrawCellInfo.Preview to determine that current drawing is used in Print/Preview mode.
  • [/*:m]
  • Change Colors of printed FlyGrid at runtime
  • [/*:m][/list:u]
    Link Posted: 19-May-2006 12:14
    [quote="NineRays"]
    there are some ways:
    [list]
  • You can use special IStylist that determining PrintPreview and uses B/W colors and doesn't fills background. DrawCellInfo provides special flag DrawCellInfo.Preview to determine that current drawing is used in Print/Preview mode.
  • [/*:m][/list:u]


    Do you have such an IStylist already available?
    Link Posted: 19-May-2006 12:22
    The problem with the IStylist solution is that it doesn't draw the cell content (text) and thus I can not change the font color or am I missing something here?
    Link Posted: 19-May-2006 13:12
    No, but you can replace all gradient brushes by solid white brushes in NineRays.Stylist to make B/W stylist.
    Link Posted: 19-May-2006 22:08
    Well, that doesn't really help me because I'm using white font eveywhere
    Link Posted: 23-May-2006 02:53
    If you using Stylist, you can use following code snippet to let Stylist recognize printing and draw necessary elements in b/w:
    [C#]
    public class PrintingStylist : Stylist
    {
      public override void Draw(StylistDrawInfo sdi)
      {
          Draw(sdi, false);
      }
      
      internal bool Draw(StylistDrawInfo sdi, bool test)
      {
        switch(sdi.Element)
        {        
          case Parts.Control:
            return DrawControlBackground(sdi, test);
          case Parts.Cell:
            return DrawCell(sdi);    
        }
        return false;  
      }
      
      internal static bool DrawCell(StylistDrawInfo sdi, bool test)
      {
        if (!test)
        {
          //draw to printer - change colors
          NineRays.Windows.Forms.Grids.CellDrawInfo cdi = sdi.Context as NineRays.Windows.Forms.Grids.CellDrawInfo;
          if (cdi != null && cdi.Preview)
          {
            cdi.customForeColor = Color.Black;
            cdi.customBackColor = Color.White;
            return true;
          }
        }
        return true;
      }
      
      internal static bool DrawControlBackground(StylistDrawInfo sdi, bool test)
      {      
        if (!test)
        {        
          NineRays.Windows.Forms.Grids.CellDrawInfo cdi = sdi.Context as NineRays.Windows.Forms.Grids.CellDrawInfo;
          //draw to print
          if (cdi != null && cdi.Preview)
          {
            using (Brush whiteBrush = new SolidBrush(Color.White))
            {
              sdi.Graphics.FillRectangle(whiteBrush, sdi.Rectangle);
            }
          }
          else
          {
            //draw to screen
          }
        }
        return true;
      }
    }


    If you using custom drawing in nodes or columns, you can analyze NineRays.Windows.Forms.Grids.CellDrawInfo.Preview to recognize painting to printer/preview and use another colors.