C# Printing A Form - c#

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!

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;
}

Change Button text color

When we pass the mouse over a button we can change the button back color using MouseOverBackColor and MouseDownBackColor using FlatApearance property box.
How can I change a button text color in the same mode when the mouse pass over it?
This should work for all sorts of Buttons, with or without FlatAppearance:
private void button1_MouseEnter(object sender, EventArgs e)
{
button1.ForeColor = Color.Red;
}
private void button1_MouseLeave(object sender, EventArgs e)
{
button1.ForeColor = SystemColors.ControlText;
}
By using RGB values, this can look like this:
//Hover Text Color changing
private void btnHome_MouseHover(object sender, EventArgs e)
{
btnHome.ForeColor = System.Drawing.Color.FromArgb(1, 102, 207);
}
private void btnHome_MouseLeave(object sender, EventArgs e)
{
btnHome.ForeColor = System.Drawing.Color.LightGray;
}
donĀ“t forget to do everytime a new method call for each button!
Just follow this figure to come to a nice solution:
If you only want to change button text color when mouse is over the button:
private void button1_MouseEnter(object sender, EventArgs e)
{
button1.ForeColor = System.Drawing.Color.Red;
}
private void button1_MouseLeave(object sender, EventArgs e)
{
button1.ForeColor = System.Drawing.Color.Black;
}

Printing contents from textbox

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;
}
}

On c# the mousehover on a picturebox appear to do nothing.Do i need some kind of eventhandler?

I am trying to create a MouseHover event for a pictureBox, but I have had no luck so far:
private void pictureBox1_MouseHover(object sender, EventArgs e)
{
pictureBox1.Image = ArgyroCinema.Properties.Resources.ktz00h07;
label1.Text = "hover";
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.Image = ArgyroCinema.Properties.Resources.ktz00h07;
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
pictureBox1.Image = ArgyroCinema.Properties.Resources.ktz00h07;
}
What is going on here? MouseClick works correctly, maybe I have to add something on Form1.Designer.cs ?
ok i had to add this line on the constructor:
this.pictureBox1.MouseHover += new System.EventHandler(this.pictureBox1_MouseHover);
although i will use mouseenter, its faster

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