110,546
社区成员
发帖
与我相关
我的任务
分享
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
public const uint GW_CHILD = 5;
public class SubWindow : NativeWindow
{
protected override void WndProc(ref Message m)
{
const int WM_CONTEXTMENU = 0x007B;
switch (m.Msg)
{
case WM_CONTEXTMENU: return;
}
base.WndProc(ref m);
}
}
private void Form1_Load(object sender, EventArgs e)
{
SubWindow vSubWindow = new SubWindow();
vSubWindow.AssignHandle(GetWindow(comboBox1.Handle, GW_CHILD));
}
if (aMsg .Msg ==WM_CLOSE)
{
if (this.txtbxDepaName.CausesValidation == true)
{
this.txtbxDepaName.CausesValidation = false;
}
}
else
{
if (this.txtbxDepaName.CausesValidation == false)
{
this.txtbxDepaName.CausesValidation = true;
}
}
this.txtbxDepaName.CausesValidation = aMsg .Msg != WM_CLOSE;
if (aMsg .Msg ==WM_CLOSE)
{
if (this.txtbxDepaName.CausesValidation == true)
{
this.txtbxDepaName.CausesValidation = false;
}
}
else
{
if (this.txtbxDepaName.CausesValidation == false)
{
this.txtbxDepaName.CausesValidation = true;
}
}
[img=http://p.blog.csdn.net/images/p_blog_csdn_net/zswang/%E7%80%91%E5%B8%83%E6%B1%97.gif]图[/img]private void textBox1_Validating(object sender, CancelEventArgs e)
{
e.Cancel = string.IsNullOrEmpty(((TextBox)sender).Text);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
textBox1.CausesValidation = true;
}
protected override void WndProc(ref Message m)
{
const int WM_CLOSE = 0x0010;
switch (m.Msg)
{
case WM_CLOSE:
textBox1.CausesValidation = false;
break;
}
base.WndProc(ref m);
}
private void textBox1_Validating(object sender, CancelEventArgs e)
{
Console.WriteLine("textBox1_Validating");
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Console.WriteLine("Form1_FormClosing");
}
protected override void WndProc(ref Message m)
{
const int WM_CLOSE = 0x0010;
switch (m.Msg)
{
case WM_CLOSE:
Console.WriteLine("WM_CLOSE");
break;
}
base.WndProc(ref m);
}
private bool closing = false;
private void textBox1_Validating(object sender, CancelEventArgs e)
{
e.Cancel = !closing & string.IsNullOrEmpty(((TextBox)sender).Text);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
closing = false;
}
protected override void WndProc(ref Message m)
{
const int WM_CLOSE = 0x0010;
switch (m.Msg)
{
case WM_CLOSE:
closing = true;
break;
}
base.WndProc(ref m);
}
private void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBox.Show("S");
}
private const int WM_CLOSE = 0x0010;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_CLOSE)
{
textBox1.CausesValidation = false;
}
base.WndProc(ref m);
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}