mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using Panuon.WPF.UI;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
|
|
namespace VPet_Simulator.Windows;
|
|
/// <summary>
|
|
/// winInputBox.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class winInputBox : WindowX
|
|
{
|
|
MainWindow mw;
|
|
public winInputBox(MainWindow mainw, string title, string text, string defaulttext, bool AllowMutiLine = false, bool CanHide = false, bool TextCenter = true)
|
|
{
|
|
InitializeComponent();
|
|
mw = mainw;
|
|
Text.Text = text;
|
|
Title = title;
|
|
TextBoxInput.AcceptsReturn = AllowMutiLine;
|
|
TextBoxInput.Text = defaulttext;
|
|
|
|
if (!TextCenter)
|
|
{
|
|
Text.TextAlignment = TextAlignment.Left;
|
|
}
|
|
}
|
|
private void TextBoxInput_PreviewKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (!TextBoxInput.AcceptsReturn && e.Key == Key.Enter)
|
|
{
|
|
ReturnYes = true;
|
|
Close();
|
|
}
|
|
}
|
|
public bool ReturnYes = false;
|
|
private void ButtonYes_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ReturnYes = true;
|
|
Close();
|
|
}
|
|
Action<string> ENDAction;
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
if (!ReturnYes)
|
|
TextBoxInput.Text = "";
|
|
}
|
|
public static winInputBox Show(MainWindow mainw, string title, string text, string defaulttext, Action<string> ENDAction, bool AllowMutiLine = false, bool TextCenter = true, bool CanHide = false)
|
|
{
|
|
winInputBox msgbox = new winInputBox(mainw, title, text, defaulttext, AllowMutiLine, CanHide, TextCenter);
|
|
msgbox.ENDAction = ENDAction;
|
|
mainw.Windows.Add(msgbox);
|
|
msgbox.ShowDialog();
|
|
return msgbox;
|
|
}
|
|
|
|
private void Window_Closed(object sender, EventArgs e)
|
|
{
|
|
ENDAction?.Invoke(TextBoxInput.Text);
|
|
mw.Windows.Remove(this);
|
|
}
|
|
}
|