开发者

c# child form close by itself after one of it functions finished

child form (called by parent form code 1) with name call_order close by itself after button click function finished. in button click function i work with DataBase and set a local variable that Get_Result return to parent form. i think its not about my code, problem must be somewhere else but i can't found it, if you have an idea appreciate. also in keydown function of call_order i have checked that if the key is escape then this.close(); that suppose to close form when user press escape.

code1: in parent form
if (e.KeyCode == Keys.F12) {
  call_order call_order = new call_order(today_sale);
  call_order.ShowDialog();
  today_sale = Convert.ToInt64(call_order.Get_Result);
}

in button click function of call_order form i have this:

if (shomare_eshterake_user != "")
        {
            int success = save_one_sale();
            if (success == 1)
            {
                MessageBox.Show("something");
                shomare_moshtari_fish.Text = Convert.ToString(shomare_fish_phone_user);
                docPrint.Print();
                shomare_moshtari_fish.Text = Convert.ToString(shomare_fish_phone_user + 1);
            }
            else if (success == 0)
            {
                MessageBox.Show("something");
            }
            else if (success == 3)
            {
                nan_barbari_count.Text = "0";
                nan_tafton_count.Text = "0";
                nan_mahali_count.Text = "0";
                nan_barbari_count.Focus();
                nan_barbari_count.SelectAll();
            }
            else if (success == 5)
            {
                MessageBox.Show("something");
            }
  }
  else MessageBox.Show("something");

@ Hans Passant, do that in in call stack i have these(its from first call of child form.), but i couldn't understand why form is closed, its all assembly references. can you understand why ?

        System.Windows.Forms.dll!System.Windows.Forms.Control.OnKeyDown(System.Windows.Forms.KeyEventArgs e) + 0x6d bytes   
System.Windows.Forms.dll!System.Windows.Forms.Control.ProcessKeyEventArgs(ref System.Windows.Forms.Message m) + 0x开发者_如何学C3f3 bytes 
System.Windows.Forms.dll!System.Windows.Forms.Form.ProcessKeyPreview(ref System.Windows.Forms.Message m) + 0x43 bytes   
System.Windows.Forms.dll!System.Windows.Forms.Control.ProcessKeyPreview(ref System.Windows.Forms.Message m) + 0x16 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.ProcessKeyMessage(ref System.Windows.Forms.Message m) + 0x1c bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.WmKeyChar(ref System.Windows.Forms.Message m) + 0x15 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x7dd bytes 
System.Windows.Forms.dll!System.Windows.Forms.TextBoxBase.WndProc(ref System.Windows.Forms.Message m) + 0x37 bytes  
System.Windows.Forms.dll!System.Windows.Forms.TextBox.WndProc(ref System.Windows.Forms.Message m) + 0x36 bytes  
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes  
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes 
[Native to Managed Transition]  
[Managed to Native Transition]  
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason, int pvLoopData) + 0x24e bytes  
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) + 0x177 bytes  
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x31 bytes  


    Nan_Behesht_winform.exe!Nan_Behesht_winform.call_order.call_order_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e) Line 1308 C#
System.Windows.Forms.dll!System.Windows.Forms.Form.OnFormClosing(System.Windows.Forms.FormClosingEventArgs e) + 0x77 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.CheckCloseDialog(bool closingOnly) + 0x8c bytes  
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FContinueMessageLoop(int reason, int pvLoopData, System.Windows.Forms.NativeMethods.MSG[] msgPeeked) + 0x160 bytes   
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason, int pvLoopData) + 0x1ae bytes  
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) + 0x177 bytes  
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form form) + 0x33 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window owner) + 0x370 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog() + 0x7 bytes 
Nan_Behesht_winform.exe!Nan_Behesht_winform.Main_Form.Main_Form_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) Line 260 + 0xa bytes    C#


Have you set the DialogResult property on that button?

From Button.DialogResult page on MSDN:

If the DialogResult for this property is set to anything other than None, and if
the parent form was displayed through the ShowDialog method, clicking the button
closes the parent form without your having to hook up any events.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜