2016-08-27 1 views
-1

DialogResult를 앞에 가져 오는 방법. 다음은 나의 양식입니다. 나는 다른 모든 응용 프로그램을 실행하기 전에 그것을 가져오고 싶습니다. 하지만 디버그 모드에서 작동하지만 "디버그 모드없이 실행"에서는 작동하지 않습니다.앞에 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); 
       } 
+0

정지 시스템을 해킹하려고 방법이 더 필요 이상으로 복잡하고도 적절하게 개체를 처리하지 않는 등 나쁜 코드를 작성하는 ... 일반적으로 – Phil1970

+0

, 넣어 나쁜 디자인 다른 응용 프로그램 앞에있는 양식 시스템과 사용자를 존중하지 않는 응용 프로그램은 작성하지 않아야합니다. – Phil1970

+0

냉담한 형제, 그것은 클라이언트의 요구입니다. –

답변

2

사용 양식의 Activate() 방법 아래 here에게로 같이 실행하고 있습니다.

비고문에 : 활성 응용 프로그램 인 경우 양식을 활성화하면 맨 앞으로 가져옵니다. 희망이 도움이

,