Winforms 没有焦点/激活的表单
我想为我的多行文本框实现类似intellisense的功能。intellisense控件以标准形式放置,没有控制框(因此,没有标题或最大化/最小化按钮可见) 所有这些都可以正常工作,但如果显示intellisense表单,并且用户单击intellisense表单,则主表单会失去焦点(因此,用户必须单击返回文本框进行写入) 我知道ShowWithoutActivation属性,但它只对激活有效,对“标准焦点”无效 编辑:Winforms 没有焦点/激活的表单,winforms,focus,activation,Winforms,Focus,Activation,我想为我的多行文本框实现类似intellisense的功能。intellisense控件以标准形式放置,没有控制框(因此,没有标题或最大化/最小化按钮可见) 所有这些都可以正常工作,但如果显示intellisense表单,并且用户单击intellisense表单,则主表单会失去焦点(因此,用户必须单击返回文本框进行写入) 我知道ShowWithoutActivation属性,但它只对激活有效,对“标准焦点”无效 编辑: 我在上找到了帮助,但提供的代码不起作用。它在“Show()”方法期间抛出“I
我在上找到了帮助,但提供的代码不起作用。它在“Show()”方法期间抛出“Invalid parameter”异常。我有一段代码是从代码项目下载的(我想),我不知道原始下载链接是什么,请尝试使用此链接
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Balloon.NET
{
public class BalloonWindow : Form
{
public static readonly int TIPMARGIN;
public static readonly int TIPTAIL;
public BalloonWindow();
public Point AnchorPoint { get; set; }
public BalloonWindow.BallonQuadrant Quadrant { get; }
public static Point AnchorPointFromControl(Control anchorControl);
protected override void Dispose(bool disposing);
protected override void OnLoad(EventArgs e);
protected virtual Rectangle OnNCCalcSize(Rectangle windowRect);
protected virtual void OnNCPaint(Graphics g);
protected override void OnResize(EventArgs e);
protected void RecalcLayout();
protected void RepositionWindow(Point oldAnchorPoint, Point newAnchorPoint);
public void ShowBalloon(Control anchorControl);
protected override void WndProc(ref Message m);
public enum BallonQuadrant
{
TopLeft = 0,
TopRight = 1,
BottomLeft = 2,
BottomRight = 3,
}
}
}
并使用以下表格
Balloon.NET.BalloonWindow ms = new Balloon.NET.BalloonWindow();
private void numberEdit1_TextChanged(object sender, EventArgs e)
{
if (!ms.Visible)
{
ms.ShowBalloon(numberEdit1);
numberEdit1.Focus();
}
}
我有一个代码,有时我从代码项目下载(我想),我不知道什么是原始下载链接尝试使用这个
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Balloon.NET
{
public class BalloonWindow : Form
{
public static readonly int TIPMARGIN;
public static readonly int TIPTAIL;
public BalloonWindow();
public Point AnchorPoint { get; set; }
public BalloonWindow.BallonQuadrant Quadrant { get; }
public static Point AnchorPointFromControl(Control anchorControl);
protected override void Dispose(bool disposing);
protected override void OnLoad(EventArgs e);
protected virtual Rectangle OnNCCalcSize(Rectangle windowRect);
protected virtual void OnNCPaint(Graphics g);
protected override void OnResize(EventArgs e);
protected void RecalcLayout();
protected void RepositionWindow(Point oldAnchorPoint, Point newAnchorPoint);
public void ShowBalloon(Control anchorControl);
protected override void WndProc(ref Message m);
public enum BallonQuadrant
{
TopLeft = 0,
TopRight = 1,
BottomLeft = 2,
BottomRight = 3,
}
}
}
并使用以下表格
Balloon.NET.BalloonWindow ms = new Balloon.NET.BalloonWindow();
private void numberEdit1_TextChanged(object sender, EventArgs e)
{
if (!ms.Visible)
{
ms.ShowBalloon(numberEdit1);
numberEdit1.Focus();
}
}
若要在未激活的情况下显示表单,请重写ShowWithoutActivation属性
protected override bool ShowWithoutActivation
{
get { return true; }
}
如果您不想在鼠标单击时激活表单,请覆盖CreateParams并设置这些样式
protected override CreateParams CreateParams
{
get
{
CreateParams p = base.CreateParams;
p.Style |= 0x40000000; // WS_CHILD
p.ExStyle |= 0x8000000; // WS_EX_NOACTIVATE - requires Win 2000 or higher :)
return p;
}
}
若要在未激活的情况下显示表单,请重写ShowWithoutActivation属性
protected override bool ShowWithoutActivation
{
get { return true; }
}
如果您不想在鼠标单击时激活表单,请覆盖CreateParams并设置这些样式
protected override CreateParams CreateParams
{
get
{
CreateParams p = base.CreateParams;
p.Style |= 0x40000000; // WS_CHILD
p.ExStyle |= 0x8000000; // WS_EX_NOACTIVATE - requires Win 2000 or higher :)
return p;
}
}
为什么不为intellisense使用控件而不是窗体?因为客户希望intellisense窗体可以从主窗体溢出。显然,您的“intellisense控件”不是控件。这是一种什么样的动物,真是不可思议。如果它是表单,则将其TopLevel属性设置为false,以将其转换为控件。@Hans Passant:UserControl在表单中。表单通过“Show()”方法显示。属性“TopMost”设置为“true”,但它与窗体的焦点无关:(.好吧,当然是。控件没有最顶层属性。很明显,它是一个窗体,请使用TopLevel属性。为什么不使用控件而不是窗体作为intellisense?因为客户希望intellisense窗体可以从主窗体溢出。很明显,您的“intellisense控件”不是控件。我不知道我是哪种动物确实是。如果它是一个窗体,则将其TopLevel属性设置为false以将其转换为控件。@Hans Passant:UserControl在窗体中。窗体通过“Show()”方法显示。属性“TopMost”设置为“true”,但它与窗体的焦点无关:(.嗯,当然是。控件没有最顶层属性。显然,它是一个窗体,请使用TopLevel属性。它看起来很有用,我会试试。谢谢!它看起来很有用,我会试试。谢谢!ExStyle是一个int,所以在最近的.NET版本上不会编译。另外,关于调整CreateParams的最后一个建议,即使修改为compile,不起作用。您只得到“错误创建窗口句柄”Win32ExceptionExStyle是一个int,因此在最近的.NET版本上不会编译。此外,关于调整CreateParams的最后建议,即使修改为编译,也不起作用。您只得到“错误创建窗口句柄”Win32Exception