| |

VerySource

 Forgot password?
 Register
Search
View: 771|Reply: 8

[SOLVED] vb.net does not print directly by browsing crystal reports

[Copy link]

2

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 Italy

Post time: 2020-1-11 17:00:01
| Show all posts |Read mode
I now have a small program that I want to use vb.net to print directly without browsing the crystal report. That is, I enter a message, and then press the "Print" button to print directly, and the print specifications must be set. For example: printing a car ticket, I just print the ticket as long as I enter the destination station and the number of tickets. Can you give some reference? Previously, it is usually led to the crystal report and then printed. Now it is printing directly, urgent, thank you! !!
Reply

Use magic Report

2

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 United States

 Author| Post time: 2020-1-15 22:36:02
| Show all posts
Did you also pass the crystal report first, but just not let the crystal report appear? ? Hope you masters! !!
Reply

Use magic Report

2

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-1-18 12:27:01
| Show all posts
With the PrintDocument control, can the printer work as long as the "Print" key is pressed on the operation interface, can the ticket be printed out?
Reply

Use magic Report

1

Threads

12

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-1-25 22:00:01
| Show all posts
Yes, the printpage event of the PrintDocument control
Write print code

Call printdocument.print () to print
Reply

Use magic Report

2

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-2-1 15:36:02
| Show all posts
It needs to be used with the printDialog control.
You help me look at the following code:
public void StartPrint (Stream streamToPrint, string streamType)
{

this.streamToPrint = streamToPrint;
this.streamType = streamType;
// Allow the user to choose the page range he or she would
// like to print.
System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog (); // Create an instance of PrintDialog.
PrintDialog1.AllowSomePages = true;

// Show the help button.
PrintDialog1.ShowHelp = true;

// Set the Document property to the PrintDocument for
// which the PrintPage Event has been handled. To display the
// dialog, either this property or the PrinterSettings property
// must be set
PrintDialog1.Document = docToPrint; // Set the Document property of PrintDialog to the instance of PrintDocument configured above

DialogResult result = PrintDialog1.ShowDialog (); // Call the ShowDialog function of PrintDialog to display the print dialog

// If the result is OK then print the document.
if (result == DialogResult.OK)
{
docToPrint.Print (); // Start printing
}

}

// The PrintDialog will print the document
// by handling the document ’s PrintPage event.
private void docToPrint_PrintPage (object sender,
System.Drawing.Printing.PrintPageEventArgs e) // Set the event handler function for the printer to start printing
{

// Insert code to render the page here.
// This code will be called when the control is drawn.

// The following code will render a simple
// message on the printed document
switch (this.streamType)
{
case "txt":
string text = null;
System.Drawing.Font printFont = new System.Drawing.Font
("Arial", 35, System.Drawing.FontStyle.Regular);

// Draw the content.
System.IO.StreamReader streamReader = new StreamReader (this.streamToPrint);
text = streamReader.ReadToEnd ();
e.Graphics.DrawString (text, printFont, System.Drawing.Brushes.Black, e.MarginBounds.X, e.MarginBounds.Y);
break;
case "image":
System.Drawing.Image image = System.Drawing.Image.FromStream (this.streamToPrint);
int x = e.MarginBounds.X;
int y = e.MarginBounds.Y;
int width = image.Width;
int height = image.Height;
if ((width / e.MarginBounds.Width)> (height / e.MarginBounds.Height))
{
width = e.MarginBounds.Width;
height = image.Height * e.MarginBounds.Width / image.Width;
}
else
{
height = e.MarginBounds.Height;
width = image.Width * e.MarginBounds.Height / image.Height;
}
System.Drawing.Rectangle destRect = new System.Drawing.Rectangle (x, y, width, height);
e.Graphics.DrawImage (image, destRect, 0,0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel);
break;
default:
break;
}

How to trigger it in the end
I use a command button and I learn the code to "open the dialog":
With printDialog1.ShowDialog ();
No way
Please help, thanks
Reply

Use magic Report

1

Threads

12

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-2-6 19:15:01
| Show all posts
PrintDocument's printpage method


Private Sub print1_PrintPage (ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles print1.PrintPage

            e.Graphics.DrawString ("String to be output")


    End Sub


DrawArc is overloaded. Draws an arc that represents the portion of the ellipse specified by a pair of coordinates, width, and height.
DrawBezier is overloaded. Draws a Bezier spline defined by 4 Point structures.
DrawBeziers is overloaded. Draws a series of Bezier splines from an array of Point structures.
DrawClosedCurve is overloaded. Draws a closed cardinality spline defined by an array of Point structures.
DrawCurve is overloaded. Draws a cardinal spline that passes through a specified set of Point structures.
DrawEllipse is overloaded. Draws an ellipse defined by a border, which is specified by a pair of coordinates, height, and width.
DrawIcon is overloaded. Paints an image represented by the specified Icon object at the specified coordinates.
DrawIconUnstretched draws the image represented by the specified Icon object without scaling the image.
DrawImage is overloaded. Draws the specified Image object at the specified position and at its original size.
DrawImageUnscaled is overloaded. Draws the specified Image object at the position specified by the coordinate pair and at its original size.
DrawLine is overloaded. Draws a line connecting two points specified by a coordinate pair.
DrawLines is overloaded. Draws a series of line segments connecting a set of Point structures.
DrawPath draws a GraphicsPath object.
DrawPie is overloaded. Draws a sector defined by a coordinate pair, width and height, and an ellipse specified by two rays.
DrawPolygon is overloaded. Draws a polygon defined by a set of Point structures.
DrawRectangle is overloaded. Draws a rectangle specified by a coordinate pair, width, and height.
DrawRectangles is overloaded. Draws a series of rectangles specified by a Rectangle structure.
DrawString is overloaded. Draws the specified text string at the specified position and with the specified Brush and Font objects.
Reply

Use magic Report

2

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-2-9 20:45:01
| Show all posts
Then I want to specify the location to print some fields, such as: destination on the ticket, seat number, fare, what to do, thank you! !!
Reply

Use magic Report

2

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-1 10:30:01
| Show all posts
e.Graphics.DrawString("String to be output")
The above sentence will prompt: No accessible "DrawString" accepts this number of parameters, so the overload decision failed.
Not sure, but to trouble you again! !
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-8-3 20:00:01
| Show all posts
rpt1.PrintToPrinter(1,false,1,9999)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list