Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I create a floating text box without stealing focus from the user?

Posted on 2010-09-18
7
Medium Priority
?
823 Views
Last Modified: 2013-12-14
Hi,

Let me first try to describe what I want to do.

Basically, I have a program that needs to continually be monitoring whatever the user is currently typing. At various points in time, when it has gathered sufficient information, it will show a transparent box slightly below where the user has been typing, which contains some possible autocomplete suggestions. The user can choose one of these suggestions, or just completely ignore the box and continue working.

So for example, if they were typing a memo in Microsoft Word, the suggestion box could overlay itself near where they are typing, however, without interfering with the user's workflow. That means that it is important that the box not steal focus from what the user is doing at the moment. However, there would be a special mappable hotkey, such as Ctrl-Alt-Num, where Num would correspond to one of the suggestions offered in the suggestion box, this hotkey would be redirected to my application, and the application would then paste the chosen suggestion into the currently active Windows Control.

Basically, kind of like a application-agnostic autocompletion tool.

Secondary question:
Although I'm monitoring/caching what the user is currently typing, what I would ideally prefer is the ability to see into the user's currently active windows control, determine if the control is some kind of input box such as a text box, and than iterate backwards from the cursor position to the beginning of the sentence that they were in the middle of typing.

Right now, this program is still in the design-phase, so I'm completely open to general suggestions as well as detailed help, although I would prefer the latter.

Main points in order of importance:
1. Creating a dynamic graphical box that can appear below the user's cursor without interfering with workflow.
2. Scanning the existing text in user's currently active application.
3. Trapping certain hot-keys and suppressing them from any given active application

This application is being designed in C# for Windows XP and up. Any help is much appreciated.

Thanks,
Shaun Christopher
0
Comment
Question by:shaunchristopher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 2

Accepted Solution

by:
Matt_Lebrao earned 1000 total points
ID: 33709517
To create a floating TextBox set the form's following properties:
¿ FormBorderStyle = FormBorderStyle.None;
¿ BackColor = Color.Lime;
¿ TranparencyKey = Color.Lime;

So only the controls inside the form are visible.
To make it appear without stealing focus (there are a lot of complicated codes around the web some of then has DLLImport and all this hard stuff, but mine is simpler and works :D)
¿ Make the form invisible on loading
¿ Example:
        private void Form1_Load(object sender, EventArgs e)
        {
            this.Visible = false;
        }
¿ As the form wasn't visible when it was really open, it can't be focused.

¿ Make the form visible after it's already open
¿ Example:
        private void Form1_Shown(object sender, EventArgs e)
        {
            this.Visible = true;
        }
¿ As the you didn't opened the form, just made it visible, it won't steal the focus.
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 1000 total points
ID: 33709600
Use WS_EX_NOACTIVATE to prevent the Form from ever receiving focus.  Use WS_EX_TRANSPARENT to make it so that user clicks literally pass THRU the form and on to whatever is "below".

See: http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx

    "The WS_EX_NOACTIVATE value for dwExStyle prevents foreground activation by the system."

See: http://msdn.microsoft.com/en-us/library/aa251511(VS.60).aspx

    "Specifies that a window created with this style is to be transparent. That is, any windows that are beneath the window are not obscured by the window."

Override CreateParams() to set these flags...no complicated codes necessary:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class Form1
{
	private const int WS_EX_TRANSPARENT = 0x20;
	private const int WS_EX_NOACTIVATE = 0x8000000;

	public Form1()
	{
		InitializeComponent();
		this.BackColor = Color.Yellow;
		this.Opacity = 0.5;
		this.ShowInTaskbar = false;
		this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
		this.TopMost = true;
	}

	protected override System.Windows.Forms.CreateParams CreateParams {
		get {
			CreateParams cp = base.CreateParams;
			cp.ExStyle = cp.ExStyle | WS_EX_NOACTIVATE | WS_EX_TRANSPARENT;
			return cp;
		}
	}

}

Open in new window

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33709603
The keyboard trapping can be done with either system wide global hotkeys or via a low level keyboard hook.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:Matt_Lebrao
ID: 33709606
This is great Idle_Mind!
But then how the user will select the chosen sugestion if desired?
By the way I sugest replacing the TextBox by a ListBox and adding the sugestion to it.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33709637
"But then how the user will select the chosen sugestion if desired?"

This does make interaction with the "floating form" a little difficult eh?... ;)

The author stated though:

    "However, there would be a special mappable hotkey, such as Ctrl-Alt-Num, where Num would correspond to one of the suggestions offered in the suggestion box, this hotkey would be redirected to my application, and the application would then paste the chosen suggestion into the currently active Windows Control."

So the user would press a Hotkey combo corresponding to they entry number and the value will be pasted and I assume the form will be hidden again.

Simple Labels in a FlowLayoutPanel could be used to easily position the available suggestions.
0
 
LVL 2

Expert Comment

by:Matt_Lebrao
ID: 33709659
Hehe right...
But wouldn't be better if an unexpirient user (like old people) could just click on the suggestion if desired?
Neither averybody can understand what is a Hotkey combo (trust me, I know a lot of "slow" people).
making the floatable form as I described would allow that.

And another thing that I forgot...

When the suggestion is chosen (or not) instead of closing the form, just make it invisible again. (remember that invisible forms doesn't catch clicks, so user's clicking on the form while invisible will go to whatever is behind it.) and clean the suggestion on the FlowLayoutPanel with FlowLayoutPanel1.Controls.Clear(); or clean the list box with ListBox1.Items.Clear();
0
 
LVL 2

Expert Comment

by:Matt_Lebrao
ID: 33709661
Please forgive my English... It's not my first language.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question