Doing a print preview makes my form disappear

Hi! I have a label designer form and when I hit the preview button, my form disappears and another form in my application is visible. It's like the label designer form gets minimized. It's driving me nuts, lol Problem shown: https://www.youtube.com/watch?v=4dH4FRoBDHg Code:
private void RenderLabel() {
if (activeDocument == null) return;
if (activeDocument.PrinterId == Guid.Empty) {
if (lblPrinter.SelectedIndex > -1) {
activeDocument.Printer = lblPrinter.SelectedItem is Printer prt ? prt : null;
activeDocument.PrinterId = activeDocument.Printer?.Id ?? Guid.Empty;
} else {
Dialog($"Set the printer first!");
return;
}
}

isPreview = true;
SaveComponent(false);
activeDocument.Product = loadedProduct.Tag is Product prod ? prod : null;
activeDocument.Store = loadedStore.Tag is Store store ? store : null;
activeDocument.Customer = loadedCustomer.Tag is Customer cust ? cust : null;
var ps = printDoc.DefaultPageSettings;
ps.Margins = activeDocument.Margins;
activeDocument.Dpi = activeDocument.Printer?.Dpi ?? 300f;
if (activeDocument.PaperSize.Width > 0 && activeDocument.PaperSize.Height > 0) {
int w = (int)Math.Round(activeDocument.PaperSize.Width * 100f / activeDocument.Dpi);
int h = (int)Math.Round(activeDocument.PaperSize.Height * 100f / activeDocument.Dpi);
ps.PaperSize = new PaperSize("Custom", Math.Max(w, 1), Math.Max(h, 1));
}

preview.Document = printDoc;
preview.InvalidatePreview();
Show();
Activate();
WindowState = FormWindowState.Maximized;
ActiveControl = labels;
}
private void RenderLabel() {
if (activeDocument == null) return;
if (activeDocument.PrinterId == Guid.Empty) {
if (lblPrinter.SelectedIndex > -1) {
activeDocument.Printer = lblPrinter.SelectedItem is Printer prt ? prt : null;
activeDocument.PrinterId = activeDocument.Printer?.Id ?? Guid.Empty;
} else {
Dialog($"Set the printer first!");
return;
}
}

isPreview = true;
SaveComponent(false);
activeDocument.Product = loadedProduct.Tag is Product prod ? prod : null;
activeDocument.Store = loadedStore.Tag is Store store ? store : null;
activeDocument.Customer = loadedCustomer.Tag is Customer cust ? cust : null;
var ps = printDoc.DefaultPageSettings;
ps.Margins = activeDocument.Margins;
activeDocument.Dpi = activeDocument.Printer?.Dpi ?? 300f;
if (activeDocument.PaperSize.Width > 0 && activeDocument.PaperSize.Height > 0) {
int w = (int)Math.Round(activeDocument.PaperSize.Width * 100f / activeDocument.Dpi);
int h = (int)Math.Round(activeDocument.PaperSize.Height * 100f / activeDocument.Dpi);
ps.PaperSize = new PaperSize("Custom", Math.Max(w, 1), Math.Max(h, 1));
}

preview.Document = printDoc;
preview.InvalidatePreview();
Show();
Activate();
WindowState = FormWindowState.Maximized;
ActiveControl = labels;
}
I threw a bunch of stuff there at the end trying to bring the form back, but none of that makes any difference. Any suggestions on what I can try?
1 Reply
Zendist
Zendist3d ago
Did you try commenting out everything in RenderLabel? Try to comment out parts of the code until you find the culprit :).

Did you find this page helpful?