mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-13 21:21:03 +00:00
This commit is contained in:
parent
224cd05c81
commit
7563e0abd1
Binary file not shown.
29
WelsonJS.Toolkit/WelsonJS.Toolkit/Prompt.cs
Normal file
29
WelsonJS.Toolkit/WelsonJS.Toolkit/Prompt.cs
Normal 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 : "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,17 +13,21 @@
|
||||||
* - https://stackoverflow.com/questions/9501022/cannot-create-an-object-from-a-active-x-component
|
* - 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://stackoverflow.com/questions/13547639/return-window-handle-by-its-name-title
|
||||||
* - https://blog.naver.com/zlatmgpdjtiq/222016292758
|
* - https://blog.naver.com/zlatmgpdjtiq/222016292758
|
||||||
|
* - https://stackoverflow.com/questions/5427020/prompt-dialog-in-windows-forms
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace WelsonJS
|
namespace WelsonJS
|
||||||
{
|
{
|
||||||
[ComVisible(true)]
|
[ComVisible(true)]
|
||||||
public class Toolkit
|
public class Toolkit
|
||||||
{
|
{
|
||||||
|
private static string ApplicationName = "WelsonJS";
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||||
|
|
||||||
|
@ -113,5 +117,25 @@ namespace WelsonJS
|
||||||
|
|
||||||
return result;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,8 +43,10 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Prompt.cs" />
|
||||||
<Compile Include="Toolkit.cs" />
|
<Compile Include="Toolkit.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user