This commit is contained in:
Namhyeon Go 2021-08-22 16:42:04 +09:00
parent 224cd05c81
commit 7563e0abd1
4 changed files with 55 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,29 @@
using System.Windows.Forms;
namespace WelsonJS
{
public static class Prompt
{
public static string ShowDialog(string text, string caption)
{
Form prompt = new Form()
{
Width = 500,
Height = 150,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = caption,
StartPosition = FormStartPosition.CenterScreen
};
Label textLabel = new Label() { Left = 50, Top = 20, Text = text };
TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 };
Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(textBox);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.AcceptButton = confirmation;
return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
}
}
}

View File

@ -13,17 +13,21 @@
* - https://stackoverflow.com/questions/9501022/cannot-create-an-object-from-a-active-x-component
* - https://stackoverflow.com/questions/13547639/return-window-handle-by-its-name-title
* - https://blog.naver.com/zlatmgpdjtiq/222016292758
* - https://stackoverflow.com/questions/5427020/prompt-dialog-in-windows-forms
*/
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WelsonJS
{
[ComVisible(true)]
public class Toolkit
{
private static string ApplicationName = "WelsonJS";
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
@ -113,5 +117,25 @@ namespace WelsonJS
return result;
}
[ComVisible(true)]
public int Alert(string message)
{
MessageBox.Show(message, ApplicationName);
return 0;
}
[ComVisible(true)]
public bool Confirm(string message)
{
return (MessageBox.Show(message, ApplicationName, MessageBoxButtons.YesNo) == DialogResult.Yes);
}
[ComVisible(true)]
public string Prompt(string message, string _default = "")
{
string result = WelsonJS.Prompt.ShowDialog(message, ApplicationName);
return (result == "" ? _default : result);
}
}
}

View File

@ -43,8 +43,10 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="Prompt.cs" />
<Compile Include="Toolkit.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>