Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SelectIconForm.cs - github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5d5c26e1fefd18bbe696ef51e7236bccd2207d46 (plain)
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
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace com.clusterrr.hakchi_gui
{
    public partial class SelectIconForm : Form
    {
        public SelectIconForm(string selected = null)
        {
            InitializeComponent();
            listBox.Items.Clear();
            var files = Directory.GetFiles(NesMenuFolder.FolderImagesDirectory, "*.png", SearchOption.AllDirectories);
            listBox.Items.AddRange((from f in files select Path.GetFileNameWithoutExtension(f)).ToArray());

            if (selected != null)
                for (int i = 0; i < listBox.Items.Count; i++)
                    if (listBox.Items[i].ToString() == selected)
                    {
                        listBox.SelectedIndex = i;
                        break;
                    }
        }

        private void listBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox.SelectedItems.Count > 0)
            {
                buttonOk.Enabled = true;
                pictureBoxArt.Image = Image.FromFile(Path.Combine(NesMenuFolder.FolderImagesDirectory, listBox.SelectedItems[0] + ".png"));
            }
            else
            {
                buttonOk.Enabled = false;
                pictureBoxArt.Image = null;
            }
        }

        private void listBox_DoubleClick(object sender, EventArgs e)
        {
            if (listBox.SelectedItem != null)
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }
    }
}