-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathScaleButtonImages.cs
More file actions
61 lines (52 loc) · 1.42 KB
/
ScaleButtonImages.cs
File metadata and controls
61 lines (52 loc) · 1.42 KB
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
using PerMonitorDemo.Properties;
using System.Drawing;
using System.Windows.Forms;
using System;
namespace PerMonitorDemo
{
public partial class ScaleButtonImages : Form
{
public ScaleButtonImages()
{
InitializeComponent();
errorButton.OriginalIcon = Resources.Error;
propertiesButton.OriginalIcon = Resources.Wrench;
}
}
internal class ImageButton : Button
{
public ImageButton() : base()
{
}
private Icon originalIcon;
public Icon OriginalIcon
{
private get
{
return originalIcon;
}
set
{
originalIcon = value;
Image = GetScaledBitmapFromIcon(originalIcon);
}
}
private Bitmap GetScaledBitmapFromIcon(Icon icon)
{
Icon scaledIcon = new Icon(icon, GetScaledSize());
Bitmap bitmap = scaledIcon.ToBitmap();
scaledIcon.Dispose();
return bitmap;
}
private Size GetScaledSize()
{
int dimention = LogicalToDeviceUnits(32);
return new Size(dimention, dimention);
}
protected override void OnDpiChangedAfterParent(EventArgs e)
{
base.OnDpiChangedAfterParent(e);
Image = GetScaledBitmapFromIcon(originalIcon);
}
}
}