Im trying to print (show in screen ) a screenshot on my main monitor , I think I’ve got all the necessary variables to make that happen but I have no clue how to get past “ PaintEventArgs” . What should I send, how should I do it?
EDIT: Here is what I want to do http://msdn.microsoft.com/en-us/library/8tda2c3c.aspx
static void Main(string[] args)
{
Rectangle rect = Screen.PrimaryScreen.Bounds;
int color = Screen.PrimaryScreen.BitsPerPixel;
PixelFormat pf;
pf = PixelFormat.Format32bppArgb;
Bitmap BM= new Bitmap(rect.Width, rect.Height, pf);
Graphics g = Graphics.FromImage(BM);
g.CopyFromScreen(rect.Left, rect.Top, 0, 0, rect.Size);
Bitmap bitamp = new Bitmap(BM);
print (bmp,) // what now?
}
private static void print(Bitmap BM, PaintEventArgs e)
{
Graphics graphicsObj = e.Graphics; // or "Bitmap bitmap = new Bitmap("Grapes.jpg");"
graphicsObj.DrawImage(BM, 60 ,10); // or "e.Graphics.DrawImage(bitmap, 60, 10);"
graphicsObj.Dispose();
}
PS: this is my first time using the site so excuse any noobish mistakes I might have made
The simplest way would be to use a Windows Forms PictureBox
inside a Form
.
For example:
Form form = new Form();
form.Text = "Image Viewer";
PictureBox pictureBox = new PictureBox();
pictureBox.Image = YourImage;
pictureBox.Dock = DockStyle.Fill;
form.Controls.Add(pictureBox);
Application.Run(form);
You'll need to call print(Bitmap, PaintEventArgs)
within the form Paint
event.
Try this
private void Form1_Load(object sender, EventArgs e)
{
Paint += new PaintEventHandler(Form1_Paint); //Link the Paint event to Form1_Paint; you can do this within the designer too!
}
private void print(Bitmap BM, PaintEventArgs e)
{
Graphics graphicsObj = e.Graphics; //Get graphics from the event
graphicsObj.DrawImage(BM, 60, 10); // or "e.Graphics.DrawImage(bitmap, 60, 10);"
graphicsObj.Dispose();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = Screen.PrimaryScreen.Bounds;
int color = Screen.PrimaryScreen.BitsPerPixel;
PixelFormat pf;
pf = PixelFormat.Format32bppArgb;
Bitmap BM = new Bitmap(rect.Width, rect.Height, pf); //This is the Bitmap Image; you have not yet selected a file,
//Bitmap BM = new Bitmap(Image.FromFile(@"D:\Resources\International\Picrofo_Logo.png"), rect.Width, rect.Height);
Graphics g = Graphics.FromImage(BM);
g.CopyFromScreen(rect.Left, rect.Top, 0, 0, rect.Size);
Bitmap bitamp = new Bitmap(BM);
print(bitamp, e);
}
Thanks,
I hope you find this helpful :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With