C # A small program that displays images at random positions in full screen mode,

Source: Internet
Author: User

C # A small program that displays images at random positions in full screen mode,

Idea: Use the screen as the background image of the program. In the displayed dialog box, select "OK" and display the scheduled image at random position. (The ESC key can be exited)

  • Control to be added: Timer

1 Rectangle bounds = Screen. getBounds (Screen. getBounds (Point. empty); 2 3 public Form1 () 4 {5 this. formBorderStyle = System. windows. forms. formBorderStyle. none; 6 this. backgroundImage = GetNoCursor (); 7 InitializeComponent (); 8} 9 10 private void Form1_Load (object sender, EventArgs e) 11 {12 timer1.Interval = 500; 13 if (MessageBox. show ("message", "title", MessageBoxButtons. yesNo) = DialogResult. yes) 14 {15 Timer1.Enabled = true; 16} 17 else18 {19 this. close (); 20} 21} 22 23 private void Form1_KeyDown (object sender, KeyEventArgs e) 24 {25 if (e. keyData = Keys. escape) 26 {27 timer1.Enabled = false; 28 MessageBox. show ("message", "title", MessageBoxButtons. OK); 29 this. close (); 30} 31} 32 33 private Bitmap GetNoCursor () 34 {35 Bitmap Source = new Bitmap (bounds. width, bounds. height); // create a Bitmap object 36 Graphics g = Based on the screen size Graphics. fromImage (Source); 37g. copyFromScreen (0, 0, 0, 0, Source. size); // obtain the 38 GB screen without a mouse. dispose (); // release resource 39 return Source; 40} 41 42 private void timereffectick (object sender, EventArgs e) 43 {44 Image img = Resource1.Image1; // obtain the resource file for display 45 if (img! = Null) 46 {47 Graphics g = this. createGraphics (); 48 Random rd = new Random (); 49 int picXPoint = rd. next (0, bounds. right-img. width); 50 int picYPoint = rd. next (0, bounds. height-img. height); 51 Point ulCorner = new Point (picXPoint, picYPoint); 52g. drawImageUnscaled (img, ulCorner); 53} 54 else55 {56 timer1.Enabled = false; 57 MessageBox. show ("no image, thank you for using"); 58 this. close (); 59} 60}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.