Form without focus/activation

折月煮酒 提交于 2019-12-08 05:04:34

问题


I want to implement intellisense-like feature for my multiline textbox. The intellisense control is placed in standard form without control box (so, no title or maximize/minimze bottons are visible).

All works fine, but if intellisense-form is shown and user clicks into the intellisense form, the main form lost focus (so, user must click back into textbox for writing).

I know ShowWithoutActivation property, but it works only on activation, not on "standard focus".

EDIT:

I found the help on http://www.daniweb.com/software-development/csharp/threads/273724 , but the presented code does not work. It throws "Invalid parameter" exception during "Show()" method.


回答1:


To show the form without activation, override the ShowWithoutActivation property

protected override bool ShowWithoutActivation
{
  get { return true; }
}

And if you do not want to activate the form even on mouse clicks, override the CreateParams and set these styles

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;
  }
}



回答2:


i have a code somedays i downloaded from code project (i think ) and i dont what is the original download link try using this

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,
        }
    }
}

and use this form as follow

Balloon.NET.BalloonWindow ms = new Balloon.NET.BalloonWindow();
private void numberEdit1_TextChanged(object sender, EventArgs e)
{
    if (!ms.Visible)
    {
        ms.ShowBalloon(numberEdit1);
        numberEdit1.Focus();
    }
}



回答3:


I found the solution: Creating a Form That Doesn't Take Focus.



来源:https://stackoverflow.com/questions/6328962/form-without-focus-activation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!