반응형

2021.11.27 - [C#] - C# Desktop Image Display Program - 바탕화면 이미지 출력 프로그램

2021.11.29 - [C#] - C# Desktop Capture and Image Display Program - 바탕화면 캡쳐 & 이미지 출력 프로그램

 

바탕화면(Desktop)에 사랑한다는 메세지를 출력하는 프로그램.

 

Love.zip
0.05MB

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
using System.Runtime.InteropServices;
 
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        [DllImport("User32.dll")]
        public static extern IntPtr GetDC(IntPtr hwnd);
 
        [DllImport("user32.dll")]
        public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
 
        Random R;
        int screenX;
        int screenY;
 
        string[] str;
 
        public Form1()
        {            
            R = new Random();
            screenX = Screen.PrimaryScreen.WorkingArea.Width;
            screenY = Screen.PrimaryScreen.WorkingArea.Height;
            str = new string[] {"I love you""♡""♥""사랑해""너무 좋아"};
            StartPosition = FormStartPosition.Manual;
            Location = new Point(screenX/2 - Size.Width/2, screenY/2 - Size.Height/2);
            
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }
 
        private async void Form1_Shown(object sender, EventArgs e)
        {
            IntPtr desktopPtr = GetDC(IntPtr.Zero);
            using (Graphics g = Graphics.FromHdc(desktopPtr))
            {
                FontFamily[] fms = FontFamily.Families;                
 
                foreach (FontFamily fm in fms)
                {                    
                    try
                    {
                        Font f = new Font(fm, R.Next(1530));
                        g.DrawString(str[R.Next(str.Length)], f, new SolidBrush(Color.FromArgb(R.Next(256), R.Next(256), R.Next(256))),
                            R.Next(screenX-30), R.Next(screenY-30));                        
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show(exc.Message);
                    }
                    await Task.Delay(100);
                }
            }
            ReleaseDC(IntPtr.Zero, desktopPtr);
        }
    }
}
 

 

실행하면 지정된 메세지가 폰트 수 만큼 출력된다.

 

'이제 그만...' 버튼을 클릭하면 종료된다.

 

반응형
Posted by J-sean
: