Commit ee88a653 HZH

解决无焦点窗体bug

1 个父辈 528e0a13
......@@ -84,7 +84,7 @@ namespace HZH_Controls.Controls.ComboBox
}
}
[Description("选中数据源改变事件"), Category("自定义")]
public new event EventHandler SelectedChangedEvent;
......@@ -119,7 +119,7 @@ namespace HZH_Controls.Controls.ComboBox
m_ucPanel.DataSource = m_dataSource;
if (_frmAnchor == null || _frmAnchor.IsDisposed || _frmAnchor.Visible == false)
{
_frmAnchor = new Forms.FrmAnchor(this, m_ucPanel);
_frmAnchor = new Forms.FrmAnchor(this, m_ucPanel, isNotFocus: false);
_frmAnchor.Show(this.FindForm());
}
......
......@@ -28,6 +28,7 @@ namespace HZH_Controls.Forms
private bool blnDown = true;
Size m_size;
Point? m_deviation;
bool m_isNotFocus = true;
#region 构造函数
/// <summary>
/// 功能描述:构造函数
......@@ -38,8 +39,9 @@ namespace HZH_Controls.Forms
/// <param name="parentControl">父控件</param>
/// <param name="childControl">子控件</param>
/// <param name="deviation">偏移</param>
public FrmAnchor(Control parentControl, Control childControl, Point? deviation = null)
public FrmAnchor(Control parentControl, Control childControl, Point? deviation = null,bool isNotFocus=true)
{
m_isNotFocus = isNotFocus;
m_parentControl = parentControl;
InitializeComponent();
this.Size = childControl.Size;
......@@ -62,13 +64,10 @@ namespace HZH_Controls.Forms
parentControl.LocationChanged += frmP_LocationChanged;
}
void frmP_LocationChanged(object sender, EventArgs e)
{
this.Hide();
}
public FrmAnchor(Control parentControl, Size size, Point? deviation = null)
public FrmAnchor(Control parentControl, Size size, Point? deviation = null, bool isNotFocus = true)
{
m_isNotFocus = isNotFocus;
m_parentControl = parentControl;
InitializeComponent();
this.Size = size;
......@@ -79,6 +78,10 @@ namespace HZH_Controls.Forms
m_deviation = deviation;
}
void frmP_LocationChanged(object sender, EventArgs e)
{
this.Hide();
}
#endregion
private void FrmDownBoard_HandleDestroyed(object sender, EventArgs e)
......@@ -93,37 +96,40 @@ namespace HZH_Controls.Forms
#region 无焦点窗体
//[System.Runtime.InteropServices.DllImport("user32.dll")]
//private extern static IntPtr SetActiveWindow(IntPtr handle);
//private const int WM_ACTIVATE = 0x006;
//private const int WM_ACTIVATEAPP = 0x01C;
//private const int WM_NCACTIVATE = 0x086;
//private const int WA_INACTIVE = 0;
//private const int WM_MOUSEACTIVATE = 0x21;
//private const int MA_NOACTIVATE = 3;
//protected override void WndProc(ref Message m)
//{
// if (m.Msg == WM_MOUSEACTIVATE)
// {
// m.Result = new IntPtr(MA_NOACTIVATE);
// return;
// }
// else if (m.Msg == WM_NCACTIVATE)
// {
// if (((int)m.WParam & 0xFFFF) != WA_INACTIVE)
// {
// if (m.LParam != IntPtr.Zero)
// {
// SetActiveWindow(m.LParam);
// }
// else
// {
// SetActiveWindow(IntPtr.Zero);
// }
// }
// }
// base.WndProc(ref m);
//}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private extern static IntPtr SetActiveWindow(IntPtr handle);
private const int WM_ACTIVATE = 0x006;
private const int WM_ACTIVATEAPP = 0x01C;
private const int WM_NCACTIVATE = 0x086;
private const int WA_INACTIVE = 0;
private const int WM_MOUSEACTIVATE = 0x21;
private const int MA_NOACTIVATE = 3;
protected override void WndProc(ref Message m)
{
if (m_isNotFocus)
{
if (m.Msg == WM_MOUSEACTIVATE)
{
m.Result = new IntPtr(MA_NOACTIVATE);
return;
}
else if (m.Msg == WM_NCACTIVATE)
{
if (((int)m.WParam & 0xFFFF) != WA_INACTIVE)
{
if (m.LParam != IntPtr.Zero)
{
SetActiveWindow(m.LParam);
}
else
{
SetActiveWindow(IntPtr.Zero);
}
}
}
}
base.WndProc(ref m);
}
#endregion
......
......@@ -35,7 +35,7 @@ namespace Test
if (this.ucProcessEllipse1.Value == 100)
this.ucProcessEllipse1.Value = 0;
if (this.ucProcessEllipse2.Value == 100)
this.ucProcessEllipse2.Value = 0;
this.ucProcessEllipse2.Value = 0;
if (this.ucProcessLine1.Value >= this.ucProcessLine1.MaxValue)
this.ucProcessLine1.Value = 0;
if (this.ucProcessLineExt1.Value >= this.ucProcessLineExt1.MaxValue)
......@@ -68,7 +68,7 @@ namespace Test
private void ucDropDownBtn1_BtnClick(object sender, EventArgs e)
{
HZH_Controls.Forms.FrmTips.ShowTipsSuccess(this,sender.ToString());
HZH_Controls.Forms.FrmTips.ShowTipsSuccess(this, sender.ToString());
}
private void button1_Click_1(object sender, EventArgs e)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!