ShiftOS-Rewind/ShiftOS.Engine/WindowManager/InfoboxTemplate.cs

113 lines
3 KiB
C#
Raw Normal View History

2017-09-24 21:55:03 +00:00
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Media;
using System.IO;
namespace ShiftOS.Engine.WindowManager
{
public partial class InfoboxTemplate : UserControl
{
Stream _str;
private int _buttonChoice;
private int _buttonSelected;
public InfoboxTemplate(ButtonType type, ErrorIcon icon)
2017-09-24 21:55:03 +00:00
{
InitializeComponent();
2017-09-24 21:55:03 +00:00
switch (type)
{
case ButtonType.Ok:
2017-09-24 21:55:03 +00:00
btnOpt1.Text = "OK";
btnOpt2.Hide();
btnOpt1.Location = new Point(109, 134);
_buttonChoice = 1;
2017-09-24 21:55:03 +00:00
break;
case ButtonType.OkCancel:
2017-09-24 21:55:03 +00:00
btnOpt1.Text = "OK";
btnOpt2.Text = "Cancel";
_buttonChoice = 2;
2017-09-24 21:55:03 +00:00
break;
case ButtonType.YesNo:
2017-09-24 21:55:03 +00:00
btnOpt1.Text = "Yes";
btnOpt2.Text = "No";
_buttonChoice = 3;
2017-09-24 21:55:03 +00:00
break;
}
switch (icon)
{
case ErrorIcon.Critical:
SetImage(Properties.Resources.symbolError);
break;
case ErrorIcon.Error:
SetImage(Properties.Resources.symbolWarning);
break;
case ErrorIcon.Info:
SetImage(Properties.Resources.symbolInfo);
break;
case ErrorIcon.Question:
SetImage(Properties.Resources.symbolQuestion);
break;
}
2017-09-24 21:55:03 +00:00
}
public enum ButtonType
2017-09-24 21:55:03 +00:00
{
YesNo,
OkCancel,
Ok
2017-09-24 21:55:03 +00:00
}
public enum ErrorIcon
{
Info,
Critical,
Error,
Question
}
2017-09-24 21:55:03 +00:00
private void btnOpt1_Click(object sender, EventArgs e)
{
switch (btnOpt1.Text)
{
case "OK":
_buttonSelected = 1;
ParentForm?.Close();
2017-09-24 21:55:03 +00:00
break;
case "Yes":
_buttonSelected = 2;
ParentForm?.Close();
2017-09-24 21:55:03 +00:00
break;
}
}
private void btnOpt2_Click(object sender, EventArgs e)
{
switch (btnOpt2.Text)
{
case "No":
_buttonSelected = 3;
2017-09-24 21:55:03 +00:00
break;
case "Cancel":
_buttonSelected = 4;
2017-09-24 21:55:03 +00:00
break;
}
}
2017-09-24 21:55:03 +00:00
public void Play()
{
_str = Properties.Resources.infobox;
SoundPlayer sp = new SoundPlayer(_str);
2017-09-24 21:55:03 +00:00
sp.Play();
sp.Stream.Position = 0;
}
private void InfoboxTemplate_Load(object sender, EventArgs e)
=> Play();
private void SetImage(Image imageType)
{
pictureBox1.Image = imageType;
}
2017-09-24 21:55:03 +00:00
}
}