I have been looking for the answer for 7 hours. So a quick google isn't going to cap this one. I Am working on a programming notepad app with intellisense like Visual Studio. only I have run into a big issue. In Visual studio the little intellisense window is its own form. Thats no problem, But notice that the little window doesn't take focus when it opens. Thats no problem either right? ShowWindow with a shownotactivate flag. but NOTICE that when you click on the little window. it changes selection but STILL doesn't activate! I can't seem to reproduce that.
I found a exStyle called WS_EX_NOACTIVATE. All over the net it says this does what I want. And in fact it DOES! but only if its created on the MAIN form of an application. have 2 or more forms, if they aren't all WS_EX_NOACTIVATE, then none of them are. End of story.
If someone could show the light, on how this could be done in C#. I would appreciate it. I'm about shot. I don't want to give up. But I might have to use a floating List view like the rest of the internet community has. I just really would like to see this work.
Keep in mind that I am using windows 7. some of the code examples I have found might work on older systems. but not mine. Also. however Visual studio does it, it works on windows7.
try this.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
namespace ExampleApp
{
class Program : Form
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Program());
}
TextBox m_textBox;
Program()
{
int x = 0;
int y = 0;
foreach (string line in new string[] {
"1234567890", "QWERTYUIOP", "ASDFGHJKL", "ZXCVBNM "})
{
foreach (char cur in line)
{
Button button = new Button();
button.Location = new Point(x * 25, y * 25);
button.Size = new Size(23, 23);
button.Text = cur.ToString();
button.Click += new EventHandler(Button_Click);
Controls.Add(button);
x++;
}
x = 0;
y++;
}
m_textBox = new TextBox();
m_textBox.Top = 25 * 4;
m_textBox.Size = new Size(25 * 10, 23);
Controls.Add(m_textBox);
ClientSize = new Size(25 * 10, 25 * 5);
TopMost = true;
}
void Button_Click(object sender, EventArgs e)
{
m_textBox.Text = ((Button)sender).Text;
SendKeys.Send(m_textBox.Text);
}
const int WS_EX_NOACTIVATE = 0x8000000;
protected override CreateParams CreateParams
{
get
{
CreateParams ret = base.CreateParams;
ret.ExStyle |= WS_EX_NOACTIVATE;
return ret;
}
}
}
}
Compile that simple code and you have a little onscreenkeyboard that will never take focus, but will work just fine. allowing you to click its little buttons with other windows focused.
now create a new windows forms app and open that form from a 2nd one. see that it no longer works.