Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Diagnostics;
- using System.Threading;
- using System.Xml;
- using System.IO;
- using TAFactory.IconPack;
- namespace Game_s_Info
- {
- public partial class Form1 : Form
- {
- //SaveFileDialog saveFileDialog1 = new SaveFileDialog();
- //saveFileDialog1.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
- XmlDocument document = new XmlDocument();
- int saves_button5, saves_game_button = 0;
- int button_5_position = 0;
- int size = 0;
- int button = 0;
- public Button[] mybutton = new Button[1000];
- public Form1()
- {
- InitializeComponent();
- if (File.Exists("saves.xml") == false)
- {
- XmlTextWriter textWritter = new XmlTextWriter("saves.xml", Encoding.UTF8);
- textWritter.WriteStartDocument();
- textWritter.WriteStartElement("head");
- textWritter.WriteEndElement();
- textWritter.Close();
- document.Load("saves.xml");
- XmlNode save_check = document.CreateElement("save_check");
- document.DocumentElement.AppendChild(save_check); // указываем родителя
- XmlAttribute button5_check = document.CreateAttribute("button5_check");
- XmlAttribute game_button_check = document.CreateAttribute("game_button_check");
- XmlAttribute game_button_value = document.CreateAttribute("game_button_value");
- XmlAttribute screen_size_x = document.CreateAttribute("screen_size_x");
- XmlAttribute screen_size_y = document.CreateAttribute("screen_size_y");
- button5_check.Value = Convert.ToString(saves_button5);// устанавливаем значение атрибута
- game_button_check.Value = Convert.ToString(saves_game_button);
- game_button_value.Value = Convert.ToString(button);
- screen_size_x.Value = "0";
- screen_size_y.Value = "0";
- save_check.Attributes.Append(button5_check);
- save_check.Attributes.Append(game_button_check);// добавляем атрибут
- save_check.Attributes.Append(game_button_value);
- save_check.Attributes.Append(screen_size_x);
- save_check.Attributes.Append(screen_size_y);
- document.Save("saves.xml");
- }
- else
- {
- XmlReader read = XmlReader.Create("saves.xml");
- read.ReadToFollowing("save_check");
- saves_button5 = Convert.ToInt32(read.GetAttribute("button5_check"));
- saves_game_button = Convert.ToInt32(read.GetAttribute("game_button_check"));
- button = Convert.ToInt32(read.GetAttribute("game_button_value"));
- //this.SizeFromClientSize(new Size(Convert.ToInt32(read.GetAttribute("screen_size_x")), Convert.ToInt32(read.GetAttribute("screen_size_y"))));
- this.SizeFromClientSize(new Size(2000, 5000));
- if (button < 20)
- {
- this.SetAutoScrollMargin(0, 800);
- }
- else
- {
- this.SetAutoScrollMargin(0, button * 40);
- }
- read.Close();
- }
- if (saves_button5 == 1)
- {
- XmlReader reader = XmlReader.Create("saves.xml");
- reader.ReadToFollowing("button5");
- button5.Location = new Point(Convert.ToInt32(reader.GetAttribute("x")), Convert.ToInt32(reader.GetAttribute("y")));
- button_5_position = Convert.ToInt32(reader.GetAttribute("button5_position"));
- reader.Close();
- button5.ContextMenuStrip = contextMenuStrip1;
- this.Controls.Add(button5);
- }
- // создаем элементы меню
- ToolStripMenuItem changeName = new ToolStripMenuItem("Изменить название");
- ToolStripMenuItem changeIcon = new ToolStripMenuItem("Изменить ярлык");
- ToolStripMenuItem addGameWithOtherIcon = new ToolStripMenuItem("Добавить игру с другим ярлыком");
- ToolStripMenuItem deleteGame = new ToolStripMenuItem("Удалить игру");
- // добавляем элементы в меню
- contextMenuStrip1.Items.AddRange(new[] { changeName, changeIcon, addGameWithOtherIcon, deleteGame });
- // ассоциируем контекстное меню с текстовым полем
- // устанавливаем обработчики событий для меню
- changeName.Click += changeName_Click;
- changeIcon.Click += changeIcon_Click;
- addGameWithOtherIcon.Click += addGameWithOtherIconClick;
- deleteGame.Click += deleteGame_Click; ;
- if (saves_game_button != 0)
- {
- for (int i = 1; i < button + 1; i++)
- {
- XmlReader reader = XmlReader.Create("saves.xml");
- reader.ReadToFollowing("mbutton" + i);
- form2[i] = new Form2();
- mybutton[i] = new Button();
- mybutton[i].Location = new Point(Convert.ToInt32(reader.GetAttribute("x")), Convert.ToInt32(reader.GetAttribute("y")));
- mybutton[i].Name = "mbutton" + Convert.ToString(i);
- mybutton[i].Text = reader.GetAttribute("game");
- mybutton[i].Click += new EventHandler(form2[i].ShowForm2);
- mybutton[i].Size = new Size(200, 200);
- mybutton[i].TextAlign = ContentAlignment.BottomCenter;
- //mybutton[i].BackgroundImage = Image.FromFile("1.png");
- //if (reader.GetAttribute("textBox5") == "Пройдено")
- //{
- // mybutton[i].BackColor = Color.FromArgb(143, 255, 84);
- //}
- //else if (reader.GetAttribute("textBox5") == "На паузе")
- //{
- // mybutton[i].BackColor = Color.FromArgb(255, 212, 71);
- //}
- //else if (reader.GetAttribute("textBox5") == "Бросил")
- //{
- // mybutton[i].BackColor = Color.FromArgb(255, 120, 86);
- //}
- //else if (reader.GetAttribute("textBox5") == "Играю")
- //{
- // mybutton[i].BackColor = Color.FromArgb(76, 153, 255);
- //}
- if (reader.GetAttribute("icon").Substring(0,1) == "t")
- {
- mybutton[i].ImageAlign = ContentAlignment.TopCenter;
- }
- else
- {
- mybutton[i].ImageAlign = ContentAlignment.MiddleCenter;
- }
- mybutton[i].ContextMenuStrip = contextMenuStrip1;
- if (mybutton[i].Text.Length > 37)
- {
- mybutton[i].Font = new Font(mybutton[i].Font.Name, 9, FontStyle.Bold);
- }
- else
- {
- mybutton[i].Font = new Font(mybutton[i].Font.Name, 10, FontStyle.Bold);
- }
- byte[] bmpData;
- bmpData = Convert.FromBase64String(reader.GetAttribute("icon").Remove(0,1));
- MemoryStream stream = new MemoryStream(bmpData);
- mybutton[i].Image = new Bitmap(stream);
- reader.Close();
- this.Controls.Add(mybutton[i]);
- GC.WaitForPendingFinalizers();
- GC.Collect();
- }
- }
- }
- void deleteGame_Click(object sender, EventArgs e)
- {
- XmlReader reader = XmlReader.Create("saves.xml");
- reader.ReadToFollowing("save_check");
- int current_number = Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7));
- int number_games = Convert.ToInt32(reader.GetAttribute("game_button_value")) - Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7));
- reader.ReadToFollowing("button5");
- int x = Convert.ToInt32(reader.GetAttribute("x"));
- int y = Convert.ToInt32(reader.GetAttribute("y"));
- reader.Close();
- for (int i = 0; i < number_games; i++)
- {
- XmlReader readerr = XmlReader.Create("saves.xml");
- readerr.ReadToFollowing("mbutton" + (current_number + i + 1));
- string game = readerr.GetAttribute("game");
- string game_patch = readerr.GetAttribute("game_patch");
- string icon_patch = readerr.GetAttribute("icon_patch");
- string time = readerr.GetAttribute("time");
- string info = readerr.GetAttribute("info");
- string icon = readerr.GetAttribute("icon");
- string label7 = readerr.GetAttribute("label7");
- string textBox1 = readerr.GetAttribute("textBox1");
- string textBox2 = readerr.GetAttribute("textBox2");
- string textBox3 = readerr.GetAttribute("textBox3");
- string textBox4 = readerr.GetAttribute("textBox4");
- string textBox5 = readerr.GetAttribute("textBox5");
- string textBox7 = readerr.GetAttribute("textBox7");
- mybutton[current_number + i].Text = game;
- if (icon.Substring(0, 1) == "t")
- {
- mybutton[current_number + i].ImageAlign = ContentAlignment.TopCenter;
- }
- else
- {
- mybutton[current_number + i].ImageAlign = ContentAlignment.MiddleCenter;
- }
- byte[] bmpData;
- bmpData = Convert.FromBase64String(icon.Remove(0, 1));
- MemoryStream stream = new MemoryStream(bmpData);
- mybutton[current_number + i].Image = new Bitmap(stream);
- readerr.Close();
- document.Load("saves.xml");
- //XmlNodeList xmlNode = document.GetElementsByTagName("mbutton2");
- //xmlNode.Attributes[0]
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("game", game);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("game_patch", game_patch);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("icon_patch", icon_patch);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("time", time);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("info", info);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("icon", icon);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("label7", label7);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox1", textBox1);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox2", textBox2);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox3", textBox3);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox4", textBox4);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox5", textBox5);
- document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox7", textBox7);
- document.Save("saves.xml");
- }
- button = button - 1;
- document.Load("saves.xml");
- document.DocumentElement["save_check"].SetAttribute("game_button_value", Convert.ToString(button));
- if (button_5_position == 0)
- {
- button_5_position = 5;
- document.DocumentElement["button5"].SetAttribute("x", "1003");
- document.DocumentElement["button5"].SetAttribute("y", Convert.ToString(y - 200));
- button5.Location = new Point(1003, y - 200);
- }
- else
- {
- button_5_position = button_5_position - 1;
- document.DocumentElement["button5"].SetAttribute("x", Convert.ToString(x - 200));
- button5.Location = new Point(x - 200, y);
- }
- document.DocumentElement["button5"].SetAttribute("button5_position", Convert.ToString(button_5_position));
- XmlNode xmlNode = document.GetElementsByTagName("mbutton" + (current_number + number_games))[0];
- xmlNode.ParentNode.RemoveChild(xmlNode);
- document.Save("saves.xml");
- mybutton[current_number + number_games].Dispose();
- }
- void changeIcon_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog12 = new OpenFileDialog();
- // выход, если была нажата кнопка Отмена и прочие (кроме ОК)
- if (openFileDialog12.ShowDialog() != DialogResult.OK) return;
- // всё. имя файла теперь хранится в openFileDialog1.FileName
- Bitmap bitmap;
- string file_extension = openFileDialog12.FileName.Substring(openFileDialog12.FileName.LastIndexOf('.'));
- string position = "t";
- if (file_extension == ".exe" || file_extension == ".dll")
- {
- int x = 0;
- int folder = 0;
- int icon = 0;
- List<Icon> shellIcons = IconHelper.ExtractAllIcons(openFileDialog12.FileName);
- List<Icon> openFolderSet = IconHelper.SplitGroupIcon(shellIcons[0]);
- for (int i = 0; i < shellIcons.Count; i++)
- {
- int n = 0;
- for (int j = 0; j < openFolderSet.Count; j++)
- {
- if (openFolderSet[j].Height > x)
- {
- x = openFolderSet[j].Height;
- folder = i;
- icon = j;
- }
- }
- if (shellIcons.Count - 1 > n)
- {
- n++;
- openFolderSet = IconHelper.SplitGroupIcon(shellIcons[n]);
- }
- }
- openFolderSet = IconHelper.SplitGroupIcon(shellIcons[folder]);
- bitmap = new Bitmap(openFolderSet[icon].ToBitmap(), 160, 160);
- mybutton[Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7))].Image = bitmap;
- }
- else
- {
- Bitmap test = new Bitmap(openFileDialog12.FileName);
- double x = test.Width;
- double y = test.Height;
- if (x > y)
- {
- double z = x / 160;
- x = x / z;
- y = y / z;
- mybutton[Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7))].ImageAlign = ContentAlignment.MiddleCenter;
- position = "c";
- }
- else
- {
- double z = y / 160;
- x = x / z;
- y = y / z;
- position = "t";
- }
- bitmap = new Bitmap(new Bitmap(openFileDialog12.FileName), Convert.ToInt32(x), Convert.ToInt32(y));
- mybutton[Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7))].Image = bitmap;
- }
- TypeConverter bmpConverter = TypeDescriptor.GetConverter(bitmap.GetType());
- byte[] bmpData = (byte[])bmpConverter.ConvertTo(bitmap, typeof(byte[]));
- string bmp_str = Convert.ToBase64String(bmpData, Base64FormattingOptions.InsertLineBreaks);
- document.Load("saves.xml");
- document.DocumentElement[contextMenuStrip1.SourceControl.Name].SetAttribute("icon", position + bmp_str);
- document.Save("saves.xml");
- GC.WaitForPendingFinalizers();
- GC.Collect();
- }
- void changeName_Click(object sender, EventArgs e)
- {
- Form4 form4 = new Form4() {a = contextMenuStrip1.SourceControl.Name };
- form4.textBox1.Text = contextMenuStrip1.SourceControl.Text;
- form4.ShowDialog();
- XmlReader reader = XmlReader.Create("saves.xml");
- reader.ReadToFollowing(contextMenuStrip1.SourceControl.Name);
- contextMenuStrip1.SourceControl.Text = reader.GetAttribute("game");
- if (contextMenuStrip1.SourceControl.Text.Length > 37)
- {
- contextMenuStrip1.SourceControl.Font = new Font(contextMenuStrip1.SourceControl.Font.Name, 9, System.Drawing.FontStyle.Bold);
- }
- else
- {
- contextMenuStrip1.SourceControl.Font = new Font(contextMenuStrip1.SourceControl.Font.Name, 10, System.Drawing.FontStyle.Bold);
- }
- reader.Close();
- }
- void addGameWithOtherIconClick(object sender, EventArgs e)
- {
- if (saves_button5 == 0)
- {
- document.Load("saves.xml");
- XmlNode button5_saves = document.CreateElement("button5");
- document.DocumentElement.AppendChild(button5_saves); // указываем родителя
- XmlAttribute button5_x = document.CreateAttribute("x"); // создаём атрибут
- XmlAttribute button5_y = document.CreateAttribute("y");
- XmlAttribute button5_position = document.CreateAttribute("button5_position");
- button5_x.Value = Convert.ToString(button5.Location.X);
- button5_y.Value = Convert.ToString(button5.Location.Y);// устанавливаем значение атрибута
- button5_position.Value = Convert.ToString(button_5_position);
- button5_saves.Attributes.Append(button5_x);
- button5_saves.Attributes.Append(button5_y);// добавляем атрибут
- button5_saves.Attributes.Append(button5_position);
- document.Save("saves.xml");
- saves_button5 = 1;
- document.Load("saves.xml");
- document.DocumentElement["save_check"].SetAttribute("button5_check", Convert.ToString(saves_button5));
- document.Save("saves.xml");
- }
- OpenFileDialog openFileDialog1 = new OpenFileDialog();
- // выход, если была нажата кнопка Отмена и прочие (кроме ОК)
- if (openFileDialog1.ShowDialog() != DialogResult.OK) return;
- // всё. имя файла теперь хранится в openFileDialog1.FileName
- button = button + 1;
- form2[button] = new Form2();
- mybutton[button] = new Button();
- mybutton[button].Location = new Point(button5.Location.X, button5.Location.Y);
- mybutton[button].Text = openFileDialog1.SafeFileName.Remove(openFileDialog1.SafeFileName.LastIndexOf('.'));
- mybutton[button].Name = "mbutton" + Convert.ToString(button);
- mybutton[button].Click += new EventHandler(form2[button].ShowForm2);
- mybutton[button].Size = new Size(200, 200);
- mybutton[button].ContextMenuStrip = contextMenuStrip1;
- if (mybutton[button].Text.Length > 37)
- {
- mybutton[button].Font = new Font(mybutton[button].Font.Name, 9, System.Drawing.FontStyle.Bold);
- }
- else
- {
- mybutton[button].Font = new Font(mybutton[button].Font.Name, 10, System.Drawing.FontStyle.Bold);
- }
- mybutton[button].TextAlign = ContentAlignment.BottomCenter;
- mybutton[button].ImageAlign = ContentAlignment.TopCenter;
- OpenFileDialog openFileDialog12 = new OpenFileDialog();
- // выход, если была нажата кнопка Отмена и прочие (кроме ОК)
- if (openFileDialog12.ShowDialog() != DialogResult.OK) return;
- // всё. имя файла теперь хранится в openFileDialog1.FileName
- Bitmap bitmap;
- string position = "t";
- string file_extension = openFileDialog12.FileName.Substring(openFileDialog12.FileName.LastIndexOf('.'));
- if (file_extension == ".exe" || file_extension == ".dll")
- {
- int x = 0;
- int folder = 0;
- int icon = 0;
- List<Icon> shellIcons = IconHelper.ExtractAllIcons(openFileDialog12.FileName);
- List<Icon> openFolderSet = IconHelper.SplitGroupIcon(shellIcons[0]);
- for (int i = 0; i < shellIcons.Count; i++)
- {
- int n = 0;
- for (int j = 0; j < openFolderSet.Count; j++)
- {
- if (openFolderSet[j].Height > x)
- {
- x = openFolderSet[j].Height;
- folder = i;
- icon = j;
- }
- }
- if (shellIcons.Count - 1 > n)
- {
- n++;
- openFolderSet = IconHelper.SplitGroupIcon(shellIcons[n]);
- }
- }
- openFolderSet = IconHelper.SplitGroupIcon(shellIcons[folder]);
- bitmap = new Bitmap(openFolderSet[icon].ToBitmap(), 160, 160);
- mybutton[button].Image = bitmap;
- }
- else
- {
- Bitmap test = new Bitmap(openFileDialog12.FileName);
- double x = test.Width;
- double y = test.Height;
- if (x > y)
- {
- double z = x / 160;
- x = x / z;
- y = y / z;
- mybutton[Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7))].ImageAlign = ContentAlignment.MiddleCenter;
- position = "c";
- }
- else
- {
- double z = y / 160;
- x = x / z;
- y = y / z;
- position = "t";
- }
- bitmap = new Bitmap(new Bitmap(openFileDialog12.FileName), Convert.ToInt32(x), Convert.ToInt32(y));
- mybutton[button].Image = bitmap;
- }
- TypeConverter bmpConverter = TypeDescriptor.GetConverter(bitmap.GetType());
- byte[] bmpData = (byte[])bmpConverter.ConvertTo(bitmap, typeof(byte[]));
- string bmp_str = Convert.ToBase64String(bmpData, Base64FormattingOptions.InsertLineBreaks);
- this.Controls.Add(mybutton[button]);
- document.Load("saves.xml");
- XmlNode game_button_saves = document.CreateElement(mybutton[button].Name);
- document.DocumentElement.AppendChild(game_button_saves); // указываем родителя
- XmlAttribute game_button_x = document.CreateAttribute("x"); // создаём атрибут
- XmlAttribute game_button_y = document.CreateAttribute("y");
- XmlAttribute game = document.CreateAttribute("game");
- XmlAttribute game_patch = document.CreateAttribute("game_patch");
- XmlAttribute icon_patch = document.CreateAttribute("icon_patch");
- XmlAttribute time = document.CreateAttribute("time");
- XmlAttribute ico = document.CreateAttribute("icon");
- XmlAttribute label7 = document.CreateAttribute("label7");
- XmlAttribute textBox1 = document.CreateAttribute("textBox1");
- XmlAttribute textBox2 = document.CreateAttribute("textBox2");
- XmlAttribute textBox3 = document.CreateAttribute("textBox3");
- XmlAttribute textBox4 = document.CreateAttribute("textBox4");
- XmlAttribute textBox5 = document.CreateAttribute("textBox5");
- XmlAttribute textBox7 = document.CreateAttribute("textBox7");
- label7.Value = "";
- textBox1.Value = "";
- textBox2.Value = "";
- textBox3.Value = "";
- textBox4.Value = "";
- textBox5.Value = "";
- textBox7.Value = "";
- ico.Value = position + bmp_str;
- game_button_x.Value = Convert.ToString(mybutton[button].Location.X);
- game_button_y.Value = Convert.ToString(mybutton[button].Location.Y);// устанавливаем значение атрибута
- game_patch.Value = openFileDialog1.FileName;
- icon_patch.Value = openFileDialog12.FileName;
- time.Value = "00.00.00";
- game.Value = mybutton[button].Text;
- game_button_saves.Attributes.Append(game_button_x);
- game_button_saves.Attributes.Append(game_button_y);// добавляем атрибут
- game_button_saves.Attributes.Append(game);
- game_button_saves.Attributes.Append(game_patch);
- game_button_saves.Attributes.Append(icon_patch);
- game_button_saves.Attributes.Append(time);
- game_button_saves.Attributes.Append(ico);
- game_button_saves.Attributes.Append(label7);
- game_button_saves.Attributes.Append(textBox1);
- game_button_saves.Attributes.Append(textBox2);
- game_button_saves.Attributes.Append(textBox3);
- game_button_saves.Attributes.Append(textBox4);
- game_button_saves.Attributes.Append(textBox5);
- game_button_saves.Attributes.Append(textBox7);
- document.DocumentElement["save_check"].SetAttribute("game_button_value", Convert.ToString(button));
- if (saves_game_button == 0)
- {
- document.DocumentElement["save_check"].SetAttribute("game_button_check", "1");
- }
- document.Save("saves.xml");
- if (button_5_position > 4)
- {
- button5.Location = new Point(mybutton[1].Location.X, button5.Location.Y + 200);
- button_5_position = 0;
- }
- else
- {
- button5.Location = new Point(button5.Location.X + 200, button5.Location.Y);
- button_5_position = button_5_position + 1;
- }
- this.Controls.Add(button5);
- document.Load("saves.xml");
- document.DocumentElement["button5"].SetAttribute("x", Convert.ToString(button5.Location.X));
- document.DocumentElement["button5"].SetAttribute("y", Convert.ToString(button5.Location.Y));
- document.DocumentElement["button5"].SetAttribute("button5_position", Convert.ToString(button_5_position));
- document.Save("saves.xml");
- if (size == 89)
- {
- this.Width = 1161;
- }
- size++;
- GC.WaitForPendingFinalizers();
- GC.Collect();
- }
- Form2 d = new Form2();
- Form2[] form2 = new Form2[1000];
- private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //button1.Visible = false;
- int x = 3;
- int y = 0;
- mybutton[3].Visible = false;
- mybutton[4].Visible = false;
- mybutton[6].Visible = false;
- XmlReader reader = XmlReader.Create("saves.xml");
- reader.ReadToFollowing("save_check");
- for (int i = 1; i < Convert.ToInt32(reader.GetAttribute("game_button_value")) + 1; i++)
- {
- if (mybutton[i].Visible == true)
- {
- mybutton[i].Location = new Point(x, y);
- x = x + 200;
- }
- }
- reader.Close();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- int x = 3;
- int y = 0;
- XmlReader reader = XmlReader.Create("saves.xml");
- reader.ReadToFollowing("save_check");
- for (int i = 1; i < Convert.ToInt32(reader.GetAttribute("game_button_value")) + 1; i++)
- {
- mybutton[i].Visible = true;
- mybutton[i].Location = new Point(x, y);
- if (x == 1003)
- {
- x = 3;
- y = y + 200;
- }
- else
- {
- x = x + 200;
- }
- }
- reader.Close();
- }
- private void button5_Click(object sender, EventArgs e)
- {
- if (saves_button5 == 0)
- {
- document.Load("saves.xml");
- XmlNode button5_saves = document.CreateElement("button5");
- document.DocumentElement.AppendChild(button5_saves); // указываем родителя
- XmlAttribute button5_x = document.CreateAttribute("x"); // создаём атрибут
- XmlAttribute button5_y = document.CreateAttribute("y");
- XmlAttribute button5_position = document.CreateAttribute("button5_position");
- button5_x.Value = Convert.ToString(button5.Location.X);
- button5_y.Value = Convert.ToString(button5.Location.Y);// устанавливаем значение атрибута
- button5_position.Value = Convert.ToString(button_5_position);
- button5_saves.Attributes.Append(button5_x);
- button5_saves.Attributes.Append(button5_y);// добавляем атрибут
- button5_saves.Attributes.Append(button5_position);
- document.Save("saves.xml");
- saves_button5 = 1;
- document.Load("saves.xml");
- document.DocumentElement["save_check"].SetAttribute("button5_check", Convert.ToString(saves_button5));
- document.Save("saves.xml");
- }
- OpenFileDialog openFileDialog1 = new OpenFileDialog();
- // выход, если была нажата кнопка Отмена и прочие (кроме ОК)
- if (openFileDialog1.ShowDialog() != DialogResult.OK) return;
- // всё. имя файла теперь хранится в openFileDialog1.FileName
- button = button + 1;
- form2[button] = new Form2();
- mybutton[button] = new Button();
- mybutton[button].Location = new Point(button5.Location.X, button5.Location.Y);
- mybutton[button].Text = openFileDialog1.SafeFileName.Remove(openFileDialog1.SafeFileName.LastIndexOf('.'));
- mybutton[button].Name = "mbutton" + Convert.ToString(button);
- mybutton[button].Click += new EventHandler(form2[button].ShowForm2);
- mybutton[button].Size = new Size(200, 200);
- mybutton[button].ContextMenuStrip = contextMenuStrip1;
- if (mybutton[button].Text.Length > 37)
- {
- mybutton[button].Font = new Font(mybutton[button].Font.Name, 9, System.Drawing.FontStyle.Bold);
- }
- else
- {
- mybutton[button].Font = new Font(mybutton[button].Font.Name, 10, System.Drawing.FontStyle.Bold);
- }
- mybutton[button].TextAlign = ContentAlignment.BottomCenter;
- mybutton[button].ImageAlign = ContentAlignment.TopCenter;
- int x = 0;
- int folder = 0;
- int icon = 0;
- List<Icon> shellIcons = IconHelper.ExtractAllIcons(openFileDialog1.FileName);
- List<Icon> openFolderSet = IconHelper.SplitGroupIcon(shellIcons[0]);
- for (int i = 0; i < shellIcons.Count; i++)
- {
- int n = 0;
- for (int j = 0; j < openFolderSet.Count; j++)
- {
- if (openFolderSet[j].Height > x)
- {
- x = openFolderSet[j].Height;
- folder = i;
- icon = j;
- }
- }
- if (shellIcons.Count - 1 > n)
- {
- n++;
- openFolderSet = IconHelper.SplitGroupIcon(shellIcons[n]);
- }
- }
- openFolderSet = IconHelper.SplitGroupIcon(shellIcons[folder]);
- Bitmap bitmap = new Bitmap(openFolderSet[icon].ToBitmap(), 160, 160);
- mybutton[button].Image = bitmap;
- this.Controls.Add(mybutton[button]);
- TypeConverter bmpConverter = TypeDescriptor.GetConverter(bitmap.GetType());
- byte[] bmpData = (byte[])bmpConverter.ConvertTo(bitmap, typeof(byte[]));
- string bmp_str = "t" + Convert.ToBase64String(bmpData, Base64FormattingOptions.InsertLineBreaks);
- document.Load("saves.xml");
- XmlNode game_button_saves = document.CreateElement(mybutton[button].Name);
- document.DocumentElement.AppendChild(game_button_saves); // указываем родителя
- XmlAttribute game_button_x = document.CreateAttribute("x"); // создаём атрибут
- XmlAttribute game_button_y = document.CreateAttribute("y");
- XmlAttribute game = document.CreateAttribute("game");
- XmlAttribute info = document.CreateAttribute("info");
- XmlAttribute label7 = document.CreateAttribute("label7");
- XmlAttribute textBox1 = document.CreateAttribute("textBox1");
- XmlAttribute textBox2 = document.CreateAttribute("textBox2");
- XmlAttribute textBox3 = document.CreateAttribute("textBox3");
- XmlAttribute textBox4 = document.CreateAttribute("textBox4");
- XmlAttribute textBox5 = document.CreateAttribute("textBox5");
- XmlAttribute textBox7 = document.CreateAttribute("textBox7");
- XmlAttribute game_patch = document.CreateAttribute("game_patch");
- XmlAttribute icon_patch = document.CreateAttribute("icon_patch");
- XmlAttribute time = document.CreateAttribute("time");
- XmlAttribute ico = document.CreateAttribute("icon");
- ico.Value = bmp_str;/*Convert.ToString(folder) + Convert.ToString(icon);*/
- info.Value = "";
- game_button_x.Value = Convert.ToString(mybutton[button].Location.X);
- game_button_y.Value = Convert.ToString(mybutton[button].Location.Y);// устанавливаем значение атрибута
- game_patch.Value = openFileDialog1.FileName;
- icon_patch.Value = openFileDialog1.FileName;
- label7.Value = "";
- textBox1.Value = "";
- textBox2.Value = "";
- textBox3.Value = "";
- textBox4.Value = "";
- textBox5.Value = "";
- textBox7.Value = "";
- time.Value = "00.00.00";
- game.Value = mybutton[button].Text;
- game_button_saves.Attributes.Append(game_button_x);
- game_button_saves.Attributes.Append(game_button_y);// добавляем атрибут
- game_button_saves.Attributes.Append(game);
- game_button_saves.Attributes.Append(game_patch);
- game_button_saves.Attributes.Append(icon_patch);
- game_button_saves.Attributes.Append(time);
- game_button_saves.Attributes.Append(info);
- game_button_saves.Attributes.Append(ico);
- game_button_saves.Attributes.Append(label7);
- game_button_saves.Attributes.Append(textBox1);
- game_button_saves.Attributes.Append(textBox2);
- game_button_saves.Attributes.Append(textBox3);
- game_button_saves.Attributes.Append(textBox4);
- game_button_saves.Attributes.Append(textBox5);
- game_button_saves.Attributes.Append(textBox7);
- document.DocumentElement["save_check"].SetAttribute("game_button_value", Convert.ToString(button));
- if (saves_game_button == 0)
- {
- document.DocumentElement["save_check"].SetAttribute("game_button_check", "1");
- }
- document.Save("saves.xml");
- if (button_5_position > 4)
- {
- button5.Location = new Point(mybutton[1].Location.X, button5.Location.Y + 200);
- button_5_position = 0;
- }
- else
- {
- button5.Location = new Point(button5.Location.X + 200, button5.Location.Y);
- button_5_position = button_5_position + 1;
- }
- this.Controls.Add(button5);
- document.Load("saves.xml");
- document.DocumentElement["button5"].SetAttribute("x", Convert.ToString(button5.Location.X));
- document.DocumentElement["button5"].SetAttribute("y", Convert.ToString(button5.Location.Y));
- document.DocumentElement["button5"].SetAttribute("button5_position", Convert.ToString(button_5_position));
- document.DocumentElement["save_check"].SetAttribute("screen_size_x", Convert.ToString(AutoScrollMargin.Width));
- document.DocumentElement["save_check"].SetAttribute("screen_size_y", Convert.ToString(AutoScrollMargin.Width));
- document.Save("saves.xml");
- size++;
- GC.WaitForPendingFinalizers();
- GC.Collect();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement