2011-08-16 4 views
3

Visual Studio C# Express 2010에서 문서 당 e.Cancel을 설정하여 .Validating을 취소하면 응용 프로그램이 종료 될 때 응답하지 않습니다. 예 : 아래를 실행하고 제목 표시 줄 'X'를 클릭하십시오..Validating()을 피하는 방법 앱 종료가 멈추는 것을 취소 하시겠습니까?

누구나 해결책을 알고 계십니까? 감사. 양식이 textBox1로 폐쇄되는 것을 방지 할 수있다

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; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void textBox1_Validating(object sender, CancelEventArgs e) 
     { 
      e.Cancel = true; 
     } 
    } 
} 

답변

3

가 유효하지 않습니다 - 당신은 여전히 ​​사용자가 다음과 같이 FormClosing 이벤트 처리 할 수있는 폼을 닫습니다 수있게하려면 :

private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
{ 
    e.Cancel = false; 
} 

당신을 예를 들어, 일반적인 방법으로이 이벤트를 연결할 필요가 : 위의 이벤트 핸들러를 디버깅 할 경우 e.Cancel는 것을 볼 수

this.FormClosing += new FormClosingEventHandler(this.Form1_FormClosing); 

true 유효성 검사 이벤트 핸들러가 e.Cancel을 true로 설정 한 경우

+0

우수 - thanks Kragen. – ChrisJJ

관련 문제