IntelliSense in .net application

G

Guest

i am creating a formula editor and would like to provide intellisense feature
to the textbox in formula editor. does any one know how can i do that?

thanks
 
D

Dave Sexton

Hi,
i am creating a formula editor and would like to provide intellisense
feature
to the textbox in formula editor. does any one know how can i do that?

You're not going to be able to use IntelliSense, AFAIK, but you could make
your own, similar tool.

When the user presses some key combination in your editor, show a ComboBox
in DropDownList mode near the text cursor after filling it with the
appropriate items.

Monitoring key presses is a simple matter of handling the appropriate event
for the editor control, which is probably KeyUp. Showing and hiding the
ComboBox is easy with the Show and Hide methods, respectively. Discovering
the position of the text cursor depends a lot on how you've implemented, or
are planning on implementing, your editor.

For your editor, you might find that using the WebBrowser in design mode [1]
or with isolated editable content [2] will be much more functional [3] than
using a simple TextBox. You can locate the position of the text cursor
using the TextRange Object [4]. Using the editor you can provide very rich
behavior using a combination of managed code, JScript and the DHTML DOM.
With the WebBrowser control you can create your own edit designers and
custom glyphs. You could even add visual markup such as squiggly red lines
if you're up to the challenge. To use many of the DOM functions from within
managed code, you'll need a reference to the MSHTML assembly. There is a
primary interop assembly (PIA) that you can reference as of the .NET
Framework 2.0 [5].

If you decide to just use a TextBox then I believe you must calculate the
text cursor's position based on the Font size and the SelectionStart
property using the Graphics.MeasureString method. Get a Graphics object
from the CreateGraphics method and dispose of it immediately after the code
has finished using it, but don't attempt to paint with it. You may also
have to account for scroll bars. I haven't tried this approach myself so
there might be an easier way, but it's doubtful.

--
Dave Sexton
http://davesexton.com/blog
http://www.codeplex.com/DocProject (Sandcastle in VS IDE)

[1] designMode Property
http://msdn2.microsoft.com/en-us/library/ms533720.aspx

[2] CONTENTEDITABLE Attribute | contentEditable Property
http://msdn2.microsoft.com/en-us/library/ms533690.aspx

[3] How to Create an HTML Editor Application
http://msdn2.microsoft.com/en-us/library/aa969729.aspx

[4] TextRange Object
http://msdn2.microsoft.com/en-us/library/ms535872.aspx

[5] Accessing Unexposed Members on the Managed HTML Document Object Model
§ Accessing Unmanaged Interfaces
http://msdn2.microsoft.com/en-us/library/ms171716.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top