110,534
社区成员
发帖
与我相关
我的任务
分享
public Form2 form2;
private void Form1_Shown(object sender, EventArgs e)
{
form2 = new Form2();
form2.MdiParent = this;
form2.Show();
}
protected override void WndProc(ref Message m)
{
const int WM_CLOSE = 0x0010;
switch (m.Msg)
{
case WM_CLOSE:
form2.textBox1.CausesValidation = false;
break;
}
base.WndProc(ref m);
}
private void button1_Click(object sender, EventArgs e)
{
Close();
}
private void textBox1_Validating(object sender, CancelEventArgs e)
{
e.Cancel = string.IsNullOrEmpty(((TextBox)sender).Text);
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
textBox1.CausesValidation = true;
}
public class SubWindow : NativeWindow
{
public TextBox textBox;
protected override void WndProc(ref Message m)
{
const int WM_LBUTTONDOWN = 0x0201;
switch (m.Msg)
{
case WM_LBUTTONDOWN:
textBox.CausesValidation = false;
break;
}
base.WndProc(ref m);
}
public SubWindow(TextBox textBox)
{
this.textBox = textBox;
}
}
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);
}
protected override void OnEnter(EventArgs e)
{
Console.WriteLine("OnEnter");
base.OnEnter(e);
}
private void Form2_Load(object sender, EventArgs e)
{
SubWindow vSubWindow = new SubWindow(textBox1);
vSubWindow.AssignHandle(button1.Handle);
}