달력

12025  이전 다음

  • 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
반응형



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
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;
 
namespace App1ButtonImage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            SetButtonBackImage(button1);
            SetButtonBackImage(button2);
            SetButtonBackImage(button3);
            SetButtonBackImage(button4);
            SetButtonBackImage(button5);
            SetButtonBackImage(button6);            
        }
 
        private void SetButtonBackImage(Button button)
        {
            Point ptImg = new Point(00);
            ptImg = this.PointToScreen(ptImg);
 
            Point ptBtn = new Point(00);
            ptBtn = button.PointToScreen(ptBtn);
 
            int intXOffset = ptBtn.X - ptImg.X;
            int intYOffset = ptBtn.Y - ptImg.Y;
 
            Bitmap bitmap = new Bitmap(button.ClientSize.Width
                                               , button.ClientSize.Height);
            using (Graphics gr = Graphics.FromImage(bitmap))
            {
                Rectangle btn_rect = new Rectangle(00, button.ClientSize.Width
                                                      , button.ClientSize.Height);
                Rectangle src_rect = new Rectangle(intXOffset, intYOffset
                                                 , button.ClientSize.Width
                                                 , button.ClientSize.Height);
 
                gr.DrawImage(this.BackgroundImage, btn_rect, src_rect, GraphicsUnit.Pixel);
            }
 
            button.BackgroundImage = bitmap;
        }
    }
}
 
cs

몇 픽셀 정도 차이나는데 어차피 이런 코딩할일이 없으니 패스

실행



Posted by 유령회사
|