Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
570 views
in Technique[技术] by (71.8m points)

winforms - Form without focus/activation

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...