Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
568 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...