如何将DialogResult放在前面。 以下是我的表格。我想把它带到所有其他应用程序运行的前面。 但它正在调试模式下工作,但没有工作在"无需调试模式运行"。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace XYZ
{
public partial class Form2 : Form
{
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool SetForegroundWindow(IntPtr hwnd);
public Form2()
{
InitializeComponent();
}
static Form2 MsgBox; static DialogResult result = DialogResult.No;
public static DialogResult Show( /*string Text, string Caption, string btnOK, string btnCancel */)
{
MsgBox = new Form2();
MsgBox.FormBorderStyle = FormBorderStyle.None;
result = DialogResult.No;
MsgBox.TopMost = true;
try
{
SetForegroundWindow(MsgBox.Handle);
System.Media.SystemSounds.Beep.Play();
MsgBox.TopLevel = true;
MsgBox.ShowDialog(MsgBox.ParentForm);
}
catch (Exception ex)
{
LogHelper.WriteFatalLog("Show", ex);
}
return result;
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void btnLoginF2_Click(object sender, EventArgs e)
{
Program.username = txtUserNameBtn.Text;
Program.password = txtPassBtn.Text;
result = DialogResult.Yes; MsgBox.Close();
}
}
}
我正在执行如下
try
{
Util.TaskHide(0);
Util.KillCtrlAltDelete();
Util.KillTaskManager();
// ShowWindow(hwnd,0);
}
catch (Exception ex)
{
// MessageBox.Show(ex.Message);
LogHelper.WriteErrorLog("Hide Kill Manage", ex);
}
Form2.Show();
// Program.mfLogin.Hide();
try
{
Util.TaskHide(1);
Util.EnableCTRLALTDEL();
}
catch (Exception ex2)
{
MessageBox.Show(ex2.Message);
LogHelper.WriteErrorLog("Show Pamper Leave", ex2);
}