Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. namespace Print_My_Screen
  2. {
  3. public partial class Form1 : Form
  4. {
  5. public Form1()
  6. {
  7. InitializeComponent();
  8.  
  9. }
  10.  
  11. private void PrintScreen()
  12.  
  13. {
  14.  
  15. Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
  16.  
  17. Graphics graphics = Graphics.FromImage(printscreen as Image);
  18.  
  19. graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
  20.  
  21. string subPath = @"C:PrintMyScreen";
  22. bool exists = System.IO.Directory.Exists(subPath);
  23.  
  24. if (!exists)
  25. System.IO.Directory.CreateDirectory(subPath);
  26.  
  27. printscreen.Save(@"C:PrintMyScreenprintscreen.png", ImageFormat.Png);
  28. printIt();
  29.  
  30. MessageBox.Show("Your screen has been printed successfully","",MessageBoxButtons.OK,MessageBoxIcon.Information);
  31.  
  32. }
  33.  
  34. private void button1_Click(object sender, EventArgs e)
  35. {
  36. PrintScreen();
  37. }
  38.  
  39.  
  40. private void printIt()
  41. {
  42. PrintDocument pd = new PrintDocument();
  43. // pd.PrintPage += PrintPage;
  44. pd.PrintPage += (sender, args) =>
  45. {
  46. System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:PrintMyScreenprintscreen.png");
  47. img.RotateFlip(RotateFlipType.Rotate90FlipXY);
  48. args.Graphics.DrawImage(img, args.MarginBounds);
  49. };
  50.  
  51. pd.Print();
  52. }
  53.  
  54. private void PrintPage(object o, PrintPageEventArgs e)
  55. {
  56. System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:PrintMyScreenprintscreen.png");
  57. Point loc = new Point(100, 100);
  58.  
  59.  
  60. e.Graphics.DrawImage(img, loc);
  61. img.Dispose();
  62. }
  63. protected override void WndProc(ref Message m)
  64. {
  65. switch (m.Msg)
  66. {
  67. case 0x84:
  68. base.WndProc(ref m);
  69. if ((int)m.Result == 0x1)
  70. m.Result = (IntPtr)0x2;
  71. return;
  72. }
  73.  
  74. base.WndProc(ref m);
  75. }
  76.  
  77. private void moveApp()
  78. {
  79.  
  80. }
  81. public void Repeater(Button btn, int interval)
  82. {
  83. var timer = new Timer { Interval = interval };
  84. timer.Tick += (sender, e) => moveApp();
  85. btn.MouseDown += (sender, e) => timer.Start();
  86. btn.MouseUp += (sender, e) => timer.Stop();
  87. btn.Disposed += (sender, e) =>
  88. {
  89. timer.Stop();
  90. timer.Dispose();
  91. };
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement