Click here to Skip to main content
16,004,991 members
Home / Discussions / C#
   

C#

 
GeneralRe: Object Viewer Pin
TylerBrinks9-Mar-05 6:12
TylerBrinks9-Mar-05 6:12 
GeneralRe: Object Viewer Pin
RohanWest9-Mar-05 6:17
RohanWest9-Mar-05 6:17 
GeneralRe: Object Viewer Pin
TylerBrinks9-Mar-05 6:40
TylerBrinks9-Mar-05 6:40 
GeneralRe: Object Viewer Pin
Heath Stewart9-Mar-05 7:22
protectorHeath Stewart9-Mar-05 7:22 
GeneralDelphi / C# COM w/ EL Crypto Pin
Prof AKA8-Mar-05 22:43
Prof AKA8-Mar-05 22:43 
GeneralRe: Delphi / C# COM w/ EL Crypto Pin
Heath Stewart9-Mar-05 7:14
protectorHeath Stewart9-Mar-05 7:14 
QuestionHow to do I Print data Row in Database Table using C#.? Pin
pubududilena8-Mar-05 20:52
pubududilena8-Mar-05 20:52 
AnswerRe: How to do I Print data Row in Database Table using C#.? Pin
Heath Stewart9-Mar-05 7:09
protectorHeath Stewart9-Mar-05 7:09 
You should consider using a third-party component that can do this for you, since such components implement advanced print styles and output formats. These are relatively inexpensive most times and will probably cost you less to buy than what would be required to develop a component even close to what you'd buy. Most are also royalty free.

If you want to do this yourself, then you need to read the documentation[^] for the PrintDocument class and all linked topics. A good object-oriented design would be to extend PrintDocument with your own class, define a property that accepts, for example, a DataTable, then override OnPrintPage to enumerate each row and print the data using the PrintPageEventArgs passed to the method. A very basic example follows:
public class DataPrintDocument : PrintDocument
{
  DataTable table;
  Font font;
  int rowsPerPage = 0;
  int margin = 4;
  DataRow currentRow;
  public DataPrintDocument() : this(null)
  {
  }
  public DataPrintDocument(DataTable table)
  {
    this.table = table;
    font = new Font("Arial", 10f);
  }
  public Font Font
  {
    get { return font; }
    set { font = value; }
  }
  protected override void OnPrintPage(PrintPageEventArgs e)
  {
    base.OnPrintPage(e);
    Graphics g = e.Graphics;
    if (rowsPerPage == 0)
    {
      SizeF fontSize = g.MeasureString("CAPS", font);
      rowsPerPage = e.MarginBounds.Height - (fontSize.Height + margin);
    }
    if (table == null || table.Rows.Count == 0)
      g.DrawString("No data to print.", font, Brushes.Black, e.MarginBounds.Location);
    else
    {
      int row = 0;
      foreach (currentRow in table.Rows)
      {
        if (row++ > rowsPerPage) break;
        // Loop through each column and print - within a bounds small enough
        // to fit on the page - each column value in the row.
      }
    }
  }
}
This should be enough to get you started, but I highl recommend a third-party solution that will save you lots of development time and at a relatively low cost. Some of those third-party component houses even advertise here on CodeProject, like ActiveReports from Data Dynamics that I see while typing this reply! Smile | :)

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRetrieving extended file properties Pin
Vlad Judys8-Mar-05 18:30
Vlad Judys8-Mar-05 18:30 
GeneralRe: Retrieving extended file properties Pin
Heath Stewart9-Mar-05 6:41
protectorHeath Stewart9-Mar-05 6:41 
GeneralRe: Retrieving extended file properties Pin
lil dracula9-Mar-05 7:55
susslil dracula9-Mar-05 7:55 
Question[VS .NET] Drag & Drop into Solution Explorer? Pin
spacebass50008-Mar-05 17:59
spacebass50008-Mar-05 17:59 
AnswerRe: [VS .NET] Drag & Drop into Solution Explorer? Pin
Heath Stewart9-Mar-05 6:23
protectorHeath Stewart9-Mar-05 6:23 
GeneralRe: [VS .NET] Drag & Drop into Solution Explorer? Pin
spacebass50009-Mar-05 6:30
spacebass50009-Mar-05 6:30 
GeneralRe: [VS .NET] Drag & Drop into Solution Explorer? Pin
Heath Stewart9-Mar-05 7:48
protectorHeath Stewart9-Mar-05 7:48 
GeneralRe: [VS .NET] Drag & Drop into Solution Explorer? Pin
spacebass50009-Mar-05 8:44
spacebass50009-Mar-05 8:44 
GeneralRe: [VS .NET] Drag & Drop into Solution Explorer? Pin
Heath Stewart9-Mar-05 9:47
protectorHeath Stewart9-Mar-05 9:47 
QuestionHow to do a balloon tip in a tray icon in C# Pin
howardsilver8-Mar-05 17:41
howardsilver8-Mar-05 17:41 
AnswerRe: How to do a balloon tip in a tray icon in C# Pin
TylerBrinks9-Mar-05 6:05
TylerBrinks9-Mar-05 6:05 
AnswerRe: How to do a balloon tip in a tray icon in C# Pin
Kasdoffe9-Mar-05 6:09
Kasdoffe9-Mar-05 6:09 
GeneralExpriences Pin
Toan Thang8-Mar-05 16:49
Toan Thang8-Mar-05 16:49 
GeneralRe: Expriences Pin
Chua Wen Ching8-Mar-05 23:34
Chua Wen Ching8-Mar-05 23:34 
Generalwrap a dll into another dll Pin
ppp0018-Mar-05 15:28
ppp0018-Mar-05 15:28 
GeneralRe: wrap a dll into another dll Pin
mav.northwind8-Mar-05 22:27
mav.northwind8-Mar-05 22:27 
GeneralRe: wrap a dll into another dll Pin
Chua Wen Ching8-Mar-05 23:40
Chua Wen Ching8-Mar-05 23:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.