C# I Love You Program - 사랑해 프로그램
C# 2021. 11. 20. 18:45 |반응형
2021.11.27 - [C#] - C# Desktop Image Display Program - 바탕화면 이미지 출력 프로그램
2021.11.29 - [C#] - C# Desktop Capture and Image Display Program - 바탕화면 캡쳐 & 이미지 출력 프로그램
바탕화면(Desktop)에 사랑한다는 메세지를 출력하는 프로그램.
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(15, 30));
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);
}
}
}
|
반응형
'C#' 카테고리의 다른 글
C# Form Designer Layout Mode - 폼 디자이너 레이아웃 모드 (0) | 2021.11.22 |
---|---|
C# Windows Media Player Audio/Video Play #2 (0) | 2021.11.21 |
C# Windows Media Player Audio/Video Play #1 (0) | 2021.11.21 |
C# Media Player Mp3 (0) | 2021.11.21 |
C# - 바탕화면(Desktop)에 출력하기 (0) | 2021.11.20 |