Printing contents from textbox - c#

I have a problem with the PrintPreviewDialog. I get this result:
All the contents goes into one page. I already tried \f and e.HasMorePages but with no result:
PS. I'm new to c# and stackeroverflow wont allow me to paste the whole code.
private void btnPrintReport_Click(object sender, EventArgs e)
{
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString(txtInvoices.Text, txtInvoices.Font, Brushes.Black, 10, 25);
//e.HasMorePages = true;
}
}

Related

Windows Form Application "How do I increase the size of the button when the mouse hovers over the button?"

private void Form1_Load(object sender, EventArgs e)
{
if (MouseMove == button1;)
{
button1.Size= 100;70;
}
}
}
}
I couldn't find how to write code
Use the MouseEnter event to capture the mouse cursor hovering over the button borders,
and the MouseLeave event to detect when the cursor leaves the button borders, in order to return it to its original size.
Here is one way to implement such functionality:
private Size OriginalButtonSize;
private Size HoveredSize;
private void Form1_Load(object sender, EventArgs e)
{
OriginalButtonSize = this.button1.Size;
HoveredSize = new Size(OriginalButtonSize.Width + 30, OriginalButtonSize.Height + 30);
}
private void button1_MouseEnter(object sender, EventArgs e)
{
button1.Size = HoveredSize;
}
private void button1_MouseLeave(object sender, EventArgs e)
{
button1.Size = OriginalButtonSize;
}
Output:
You can use this code:
private void button1_MouseHover(object sender, EventArgs e)
{
button1.Width = 100;
button1.Height = 70;
}
if you want to set size to the previous size after leaving the mouse, you can use this (for example it was 60 and 30 at first place):
private void button1_MouseLeave(object sender, EventArgs e)
{
button1.Width = 60;
button1.Height = 30;
}

How to make buttons appear after ProgressBar loads?

I'm new to C# and started making my own program. How ever, I want these (https://gyazo.com/8b4e0f4141b15e1ff204e1cfc8f41827) to disappear until my progress bar loads (https://gyazo.com/5064ebd9582593942c6e538e1ae516dc). I tried to use Visible but got nowhere.
ProgressBar code:
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Start();
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
var before = this.progressBar1.Value;
this.progressBar1.Increment(1);
var after = this.progressBar1.Value;
if (after > before && after == this.progressBar1.Maximum)
{
MessageBox.Show("Successfully loaded...");
this.BackgroundImage = Properties.Resources.image1;
}
}
In "Form.Load" set Image.Visible = false and when you are showing the MessageBox set Image.Visible = true

Trying to print the picturebox content but it shows there's no content

I am trying to print the content of picturebox in which the barcode is generated. Barcode is there and when I click 'print' the print preview shows there's no content.
Print button is named 'druk', picturebox 'box4'.
Code below:
private void druk_Click(object sender, EventArgs e)
{
printDocument1.OriginAtMargins = true;
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(box4.Image, 0, 0);
}
private void box4_Click(object sender, EventArgs e)
{

C# Printing A Form

I'm new to c#, so I hope this doesn't sound/look stupid.
I'm having an issue while printing. I can't seem to get my form to print on the full size of a regular piece of paper. It's printing in landscape, the height fits, but my width goes off the page. Here is the code I'm working with.
Any help would be greatly appreciated, thanks!
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
private void printPreviewDialog1_Load(object sender, EventArgs e)
{
PrintPreviewDialog _PrintPreview = new PrintPreviewDialog();
_PrintPreview.Document = printDocument1;
((Form)_PrintPreview).WindowState = FormWindowState.Normal;
_PrintPreview.ShowDialog();
}
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveAsBitmap(this, #"img\1.bmp");
CaptureScreen();
printDocument1.PrinterSettings.DefaultPageSettings.Landscape = true;
printDocument1.Print();
}
try setting the papersize in the printOption : http://msdn.microsoft.com/en-us/library/aa691030(v=vs.71).aspx
Hope this can help you!

C# PrintDocument prints blank page. Why?

I have the following picture box I populate with a barcode then try to print.
Here's the code:
private void button1_Click(object sender, EventArgs e)
{
printDocument1.OriginAtMargins = true;
printDocument1.DocumentName = "TEST IMAGE PRINTING";
printDialog1.Document = printDocument1;
printDialog1.ShowDialog();
printDocument1.Print();
}
private void printDocument1_PrintPage_1(object sender, PrintPageEventArgs e)
{
System.Drawing.Graphics formGraphics = System.Drawing.Graphics.FromImage(picpdf417.Image);
}
You need to actually draw the image:
private void printDocument1_PrintPage_1(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(picpdf417.Image, Point.Empty);
}

Categories