1

我想为我的多行文本框实现类似智能感知的功能。智能感知控件以标准形式放置,没有控制框(因此,没有标题或最大化/最小化按钮可见)。

一切正常,但如果显示智能感知表单并且用户单击智能感知表单,则主表单失去焦点(因此,用户必须单击返回文本框进行写作)。

我知道ShowWithoutActivation属性,但它仅适用于激活,而不适用于“标准焦点”。

编辑:

我在http://www.daniweb.com/software-development/csharp/threads/273724上找到了帮助,但提供的代码不起作用。它在“Show()”方法期间抛出“Invalid parameter”异常。

4

2 回答 2

10

要在不激活的情况下显示表单,请覆盖 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;
  }
}
于 2012-05-26T08:03:50.197 回答
1

有一天我从代码项目(我认为)下载了一个代码,但我不知道原始下载链接是什么尝试使用这个

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();
    }
}
于 2011-06-13T16:01:43.793 回答