반응형
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(0, 0); ptImg = this.PointToScreen(ptImg); Point ptBtn = new Point(0, 0); 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(0, 0, 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 |
몇 픽셀 정도 차이나는데 어차피 이런 코딩할일이 없으니 패스
실행
'프로그래밍 > C#' 카테고리의 다른 글
[C#] 유닉스시간 <> 윈도우시간 변환 함수 (0) | 2018.06.27 |
---|---|
[C#] 텍스트를 픽쳐박스로... (0) | 2018.06.23 |
[C#]AnimateWindow (0) | 2018.06.13 |
[C#]폼을 투명하게 (0) | 2018.04.14 |
[C#]소켓으로 이미지 전송하기 Thread로 여러장 보내기 merong-답글소스 (0) | 2018.04.10 |