1 |
using System; |
2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel; |
4 |
using System.Drawing; |
5 |
using System.Data; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using System.Windows.Forms; |
9 |
using System.IO; |
10 |
|
11 |
namespace EmuXPortal |
12 |
{ |
13 |
public partial class PlatformControl : UserControl |
14 |
{ |
15 |
private FileStream fs = null; |
16 |
private object image_lock = new object(); |
17 |
|
18 |
private int m_ControlID = new Random().Next(); |
19 |
public int ControlID { get { return m_ControlID; } } |
20 |
public PlatformControl() { InitializeComponent(); |
21 |
platformImage.SizeMode = PictureBoxSizeMode.StretchImage; |
22 |
} |
23 |
public void ReleasePlatformStream () |
24 |
{ |
25 |
if (fs != null) { |
26 |
fs.Close(); |
27 |
fs.Dispose(); |
28 |
fs = null; |
29 |
} |
30 |
} |
31 |
public void UpdatePlatformImage(Image img) { |
32 |
this.PlatformImage = img; |
33 |
} |
34 |
public void UpdatePlatformImage(string filename) { |
35 |
ReleasePlatformStream(); |
36 |
fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None); |
37 |
this.PlatformImage = Image.FromStream(fs); |
38 |
} |
39 |
private Image PlatformImage |
40 |
{ |
41 |
get { lock (image_lock) { return platformImage.Image; } } |
42 |
set |
43 |
{ |
44 |
lock (image_lock) |
45 |
{ |
46 |
platformImage.Image = value; |
47 |
} |
48 |
} |
49 |
} |
50 |
public string PlatformName { get { return platformName.Text; } set { platformName.Text = value; } } |
51 |
private void PlatformControl_Load(object sender, EventArgs e) |
52 |
{ |
53 |
using (Graphics g = platformName.CreateGraphics()) |
54 |
{ |
55 |
Size size = g.MeasureString(platformName.Text, platformName.Font).ToSize(); |
56 |
platformName.Size = new Size(size.Width + 5, platformName.Size.Height); |
57 |
} |
58 |
} |
59 |
} |
60 |
} |