/[EmuXPortal]/branches/mono/EmuXPortal/GameControl.cs
ViewVC logotype

Contents of /branches/mono/EmuXPortal/GameControl.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 334 - (show annotations) (download)
Tue Dec 19 03:35:02 2017 UTC (2 years, 6 months ago) by william
File size: 1713 byte(s)
fix an issue with images not loading properly due to sharing violations
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 GameControl : UserControl
14 {
15 private FileStream fs = null;
16 private object image_lock = new object();
17 private int m_ControlID = new Random().Next();
18 public int ControlID { get { return m_ControlID; } }
19
20 public GameControl() { InitializeComponent();
21 gameImage.SizeMode = PictureBoxSizeMode.StretchImage;
22 }
23 public void ReleaseGameStream ()
24 {
25 if (fs != null) {
26 fs.Close();
27 fs.Dispose();
28 fs = null;
29 }
30 }
31 public void UpdateGameImage(Image img) {
32 this.GameImage = img;
33 }
34 public void UpdateGameImage (string filename)
35 {
36 ReleaseGameStream();
37 fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None);
38 this.GameImage = Image.FromStream(fs);
39 }
40 private Image GameImage {
41 get {
42 lock (image_lock) {
43 return gameImage.Image;
44 }
45 }
46 set {
47 lock (image_lock) {
48 gameImage.Image = value;
49 }
50 }
51 }
52 public string GameName { get { return gameName.Text; } set { gameName.Text = value; } }
53 private void GameControl_Load(object sender, EventArgs e)
54 {
55 using (Graphics g = gameName.CreateGraphics())
56 {
57 Size size = g.MeasureString(gameName.Text, gameName.Font).ToSize();
58 gameName.Size = new Size(size.Width + 5, gameName.Size.Height);
59 }
60 }
61 }
62 }

  ViewVC Help
Powered by ViewVC 1.1.22