Click here to Skip to main content
15,904,348 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Capturing a still from a RTSP stream Pin
Richard MacCutchan19-Sep-23 1:52
mveRichard MacCutchan19-Sep-23 1:52 
AnswerRe: Capturing a still from a RTSP stream Pin
jschell19-Sep-23 5:43
jschell19-Sep-23 5:43 
QuestionVB.NET Framework 7, how to multithread on existing user control? Pin
Member 1415594910-Sep-23 7:06
Member 1415594910-Sep-23 7:06 
AnswerRe: VB.NET Framework 7, how to multithread on existing user control? Pin
Dave Kreskowiak10-Sep-23 11:43
mveDave Kreskowiak10-Sep-23 11:43 
AnswerRe: VB.NET Framework 7, how to multithread on existing user control? Pin
Gerry Schmitz10-Sep-23 16:05
mveGerry Schmitz10-Sep-23 16:05 
Questionvb.net 2022 webview2 getting current url. Pin
steve20152-Sep-23 10:16
steve20152-Sep-23 10:16 
AnswerRe: vb.net 2022 webview2 getting current url. Pin
Dave Kreskowiak2-Sep-23 10:50
mveDave Kreskowiak2-Sep-23 10:50 
GeneralRe: vb.net 2022 webview2 getting current url. Pin
steve20153-Sep-23 4:08
steve20153-Sep-23 4:08 
QuestionHelp! My .NET to MySQL application suddenly stopped working... Pin
erikbrannlund25-Aug-23 0:07
professionalerikbrannlund25-Aug-23 0:07 
AnswerRe: Help! My .NET to MySQL application suddenly stopped working... Pin
Dave Kreskowiak25-Aug-23 3:39
mveDave Kreskowiak25-Aug-23 3:39 
GeneralRe: Help! My .NET to MySQL application suddenly stopped working... Pin
erikbrannlund25-Aug-23 4:24
professionalerikbrannlund25-Aug-23 4:24 
GeneralRe: Help! My .NET to MySQL application suddenly stopped working... Pin
Gerry Schmitz25-Aug-23 4:30
mveGerry Schmitz25-Aug-23 4:30 
GeneralRe: Help! My .NET to MySQL application suddenly stopped working... Pin
jkirkerx24-Oct-23 11:47
professionaljkirkerx24-Oct-23 11:47 
QuestionMessage Closed Pin
17-Aug-23 0:11
YASH PATEL 202317-Aug-23 0:11 
QuestionRe: How can Power BI development services assist businesses in transforming raw data into meaningful insights and visualizations? Pin
Richard MacCutchan17-Aug-23 0:17
mveRichard MacCutchan17-Aug-23 0:17 
AnswerRe: How can Power BI development services assist businesses in transforming raw data into meaningful insights and visualizations? Pin
Richard Deeming17-Aug-23 1:25
mveRichard Deeming17-Aug-23 1:25 
GeneralRe: How can Power BI development services assist businesses in transforming raw data into meaningful insights and visualizations? Pin
Richard MacCutchan17-Aug-23 1:35
mveRichard MacCutchan17-Aug-23 1:35 
AnswerRe: How can Power BI development services assist businesses in transforming raw data into meaningful insights and visualizations? Pin
Dave Kreskowiak17-Aug-23 3:13
mveDave Kreskowiak17-Aug-23 3:13 
GeneralRe: How can Power BI development services assist businesses in transforming raw data into meaningful insights and visualizations? Pin
Richard MacCutchan17-Aug-23 3:23
mveRichard MacCutchan17-Aug-23 3:23 
AnswerRe: How can Power BI development services assist businesses in transforming raw data into meaningful insights and visualizations? Pin
jschell17-Aug-23 5:37
jschell17-Aug-23 5:37 
QuestionHow would you test a minimal api that uses a dictionary for saving entities? Pin
Nikol Dimitrova 202314-Aug-23 13:13
Nikol Dimitrova 202314-Aug-23 13:13 
AnswerRe: How would you test a minimal api that uses a dictionary for saving entities? Pin
jschell15-Aug-23 4:36
jschell15-Aug-23 4:36 
GeneralRe: How would you test a minimal api that uses a dictionary for saving entities? Pin
Nikol Dimitrova 202315-Aug-23 7:46
Nikol Dimitrova 202315-Aug-23 7:46 
AnswerRe: How would you test a minimal api that uses a dictionary for saving entities? Pin
Gerry Schmitz15-Aug-23 4:37
mveGerry Schmitz15-Aug-23 4:37 
QuestionCreating a print event handler in a class, and calling it from my print dialog, I need human help on this Pin
jkirkerx27-Jul-23 9:08
professionaljkirkerx27-Jul-23 9:08 
This is my first time trying to to print directly to a printer using the PrintDialog and PrintDocument. I thought it would be like creating a PDF, where I just compose and create a file and print, but it looks like I'm forced to use an event handler to compose my print document using Drawing.

I was on the internet, and the examples where very simple and basic, but my document is going to be huge, and used many times in my c# winforms .Net Core 7 app. So I used ChatGPT to help me design a class, that I can call as my event handler, but I'm missing something in my class, or got it wrong on how all of this works.

On my Print Dialog Form, when I hit the print button, my code example ...
The printDefault.Question is what I'm trying to call, where Question is where I'm stumped ..
C#
if (result == DialogResult.OK)
{
    // Record the printer name used when the print job was accepted
    this.PrintObject.PrintSettings.DefaultPrinter = printDialog.PrinterSettings.PrinterName;

    if (this.PrintObject.PrintSettings.DefaultDocument != null)
    {
        var printDefault = new PrintDefault
        {
            Bol = this.PrintBol
        };

        // Subscribe to the PrintPage event of your custom PrintDocument.
        printDocument.PrintPage += new PrintPageEventHandler(printDefault.Question);

        // Start the printing process.
        printDocument.Print();

        this.PrintComplete = true;
    }
}

And my class ....
I figured that my class is an extension of PrintDocument, but I'm not sure. One of the dumb requirements is that I need the MongoDb collection document to generate the BOL form to print, because that has all my data I need to populate the document I'm trying to create. I'm not really sure if my design is sound or not, and may have to think of an alternative. But I feel like I'm really close, just missing something that I didn't think of.
C#
namespace SimpleBol.Classes.DirectPrint
{
    public class PrintDefault : PrintDocument
    {
        public BILLOFLADINGS Bol { get; set; } = null!;

        // Create a PrintPage event handler method
        public void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            // Create the fonts we need to print with
            Font fontTitleBold = new Font("Arial", 16, FontStyle.Bold);
            Font fontTitleRegular = new Font("Arial", 16, FontStyle.Regular);
            Font fontLargeBold = new Font("Arial", 12, FontStyle.Bold);
            Font fontLargeRegular = new Font("Arial", 12, FontStyle.Regular);
            Font fontMedium = new Font("Arial", 10);
            Font fontSmall = new Font("Arial", 8);
            Font fontTiny = new Font("Arial", 6, FontStyle.Italic);

            // Create the brushes we need to draw with
            SolidBrush brush = new SolidBrush(System.Drawing.Color.Black);

            // Define the printable area.
            RectangleF printArea = e.PageSettings.PrintableArea;

            if (e.Graphics != null)
            {
                // Measure the size of the text.
                SizeF textSize = e.Graphics.MeasureString("BILL OF LADING", fontTitleBold);

                // Calculate the starting position to center the text.
                float x = printArea.Left + (printArea.Width - textSize.Width) / 2;
                float y = printArea.Top + (printArea.Height - textSize.Height) / 2;

                // Draw the text on the page.
                e.Graphics.DrawString("Date: ", fontMedium, brush, x, y);

                // Continue with your drawing logic for the rest of the document
                // You can access the 'Bol' property here if needed
                // For example, e.Graphics.DrawString(Bol.SomeProperty, fontMedium, brush, x, y);

                // For example, you can access the Bol property here:
                if (Bol != null)
                {
                    string date = Bol.BolDate.ToString("dd-MM-yyyy");
                    e.Graphics.DrawString("Date: " + date, fontMedium, brush, x, y);
                    e.Graphics.DrawString("Shipper: " + Bol.ShipperName, fontMedium, brush, x, y + 20);
                    e.Graphics.DrawString("Vendor: " + Bol.ShipFromVendor, fontMedium, brush, x, y + 40);

                    // Continue with more drawing logic as needed
                }

            }

        }

        // Override the OnPrintPage method to call your custom PrintPage event handler
        protected override void OnPrintPage(PrintPageEventArgs e)
        {
            base.OnPrintPage(e);
            PrintDocument_PrintPage(this, e);
        }
    }
}

On another note; since this is my first time, what's the best way to test during document composition. I threw out my cheap printer with cheap toner, and can't see having to print a sheet a paper on every test. Should I build a temp print preview first, and get it close enough there, and then use paper to fine tune?

Now I'm wondering if I should change my print dialog to show the preview first, and then hit the print button. The downside to being a rogue programmer is that I have no team to ask for help, and any help or opinions would be appreciated.
If it ain't broke don't fix it
Discover my world at jkirkerx.com

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.