test_form_test_visualstudio/Test_Form/Form1.cs

185 lines
6.8 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test_Form
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Anfängliche Fensteraussehen initialisieren
string btnLeft = "Left";
string btnCenter = "Center";
string btnRight = "Right";
SetWindowAppearance(Window.Size.Micro, Window.ControlBox.On, Window.BorderStyle.Sizeable, Window.TopMost.Off, btnLeft, btnCenter, btnRight);
//Anfängliches Icon initialisieren
SetIconImage(Icons.Icon.Information);
}
/// <summary>
/// Stores the current window size.
/// </summary>
private Window.Size CurrentWindowsSize { set; get; } //Speichert die aktuelle Fenstergröße
/// <summary>
/// Stores the current control box setting.
/// </summary>
private Window.ControlBox CurrentControlBox { set; get; } //Speichert die aktuelle ControllBox Einstellung
/// <summary>
/// Stores the current border sizeable setting.
/// </summary>
private Window.BorderStyle CurrentBorderStyle { set; get; } //Speichert die Größen-Einstellbarkeit
/// <summary>
/// Stores the windows most on top setting.
/// </summary>
private Window.TopMost CurrentTopMost { set; get; } //Speichert die Fenster meistens oben Einstellung
/// <summary>
/// Stores the current icon image
/// </summary>
private Bitmap CurrentIconImage { set; get; } //Speichert das aktuelle Icon
/// <summary>
/// Sets the appearance of the window.
/// </summary>
/// <param name="winSize">A valid window size. Possible options are: 'Nano' (360x270), 'Micro' (480x360), 'Mini' (640x480), 'Midi' (850x640), 'Maxi' (1020x770) and 'Magnum' (1360x1020).</param>
/// <param name="ctrlBox">A valid control box status value. Possible options are: 'Off' and 'On'.</param>
private void SetWindowAppearance(Window.Size winSize, Window.ControlBox ctrlBox, Window.BorderStyle borderStyle, Window.TopMost topMost, string btnLeft, string btnCenter, string btnRight)
{
var window = new Window();
//Fenstergröße setzen
window.SetWindowSize(winSize);
this.Size = new Size(window.CurrentWindowSizeValue[0], window.CurrentWindowSizeValue[1]);
CurrentWindowsSize = winSize;
//Control Box setzen
CurrentControlBox = window.SetControlBox(ctrlBox);
this.ControlBox = Convert.ToBoolean(CurrentControlBox);
//Border Style setzen
CurrentBorderStyle = window.SetBorderStyle(borderStyle);
this.FormBorderStyle = (FormBorderStyle)CurrentBorderStyle;
//Fenster immer oben auf
CurrentTopMost = window.SetTopMost(topMost);
this.TopMost = Convert.ToBoolean(CurrentTopMost);
//Button links
if (btnLeft == "")
{
buttonLeft.Enabled = false;
buttonLeft.Visible = false;
}
else
{
buttonLeft.Enabled = true;
buttonLeft.Visible = true;
buttonLeft.Text = btnLeft;
}
//Button mitte
if (btnCenter == "")
{
buttonCenter.Enabled = false;
buttonCenter.Visible = false;
}
else
{
int x = (int) window.CurrentWindowSizeValue[0] / 2 - 41;
int y = window.CurrentWindowSizeValue[1] - 66;
buttonCenter.Location = new System.Drawing.Point(x, y);
buttonCenter.Enabled = true;
buttonCenter.Visible = true;
buttonCenter.Text = btnCenter;
}
//Button rechts
if (btnRight == "")
{
buttonRight.Enabled = false;
buttonRight.Visible = false;
}
else
{
buttonRight.Enabled = true;
buttonRight.Visible = true;
buttonRight.Text = btnRight;
}
}
/// <summary>
/// Sets one of ten different Icons.
/// </summary>
/// <param name="icon">A valid icon. Possible options are: 'Construction', 'Email', 'Error', 'FatalError', 'Information', 'Instruction', 'Question', 'Telephone', 'Tips', 'Warning'.</param>
private void SetIconImage(Icons.Icon icon)
{
var icons = new Icons();
Bitmap bmp = icons.SetIcon(icon);
pictureBoxIcon.Image = bmp;
CurrentIconImage = bmp;
}
private void buttonChangeSize_Click(object sender, EventArgs e)
{
//Die Tasten-Texte definieren
string btnLeft = "Change Size";
string btnCenter = "Center";
string btnRight = "Right";
//Alle möglichen Auflösungen der Reihe nach durchschalten
if (CurrentWindowsSize == Window.Size.Nano)
{
SetWindowAppearance(Window.Size.Micro, CurrentControlBox, CurrentBorderStyle, CurrentTopMost, btnLeft, btnCenter, btnRight);
}
else if (CurrentWindowsSize == Window.Size.Micro)
{
SetWindowAppearance(Window.Size.Mini, CurrentControlBox, CurrentBorderStyle, CurrentTopMost, btnLeft, btnCenter, btnRight);
}
else if (CurrentWindowsSize == Window.Size.Mini)
{
SetWindowAppearance(Window.Size.Midi, CurrentControlBox, CurrentBorderStyle, CurrentTopMost, btnLeft, btnCenter, btnRight);
}
else if (CurrentWindowsSize == Window.Size.Midi)
{
SetWindowAppearance(Window.Size.Maxi, CurrentControlBox, CurrentBorderStyle, CurrentTopMost, btnLeft, btnCenter, btnRight);
}
else if (CurrentWindowsSize == Window.Size.Maxi)
{
SetWindowAppearance(Window.Size.Magnum, CurrentControlBox, CurrentBorderStyle, CurrentTopMost, btnLeft, btnCenter, btnRight);
}
else
{
SetWindowAppearance(Window.Size.Nano, CurrentControlBox, CurrentBorderStyle, CurrentTopMost, btnLeft, btnCenter, btnRight);
}
}
private void buttonCenter_Click(object sender, EventArgs e)
{
}
private void buttonRight_Click(object sender, EventArgs e)
{
}
}
}