473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Wrapped text hittest: Good way to do it?

I'm working in C#, .NET framework 2.0.

I'm writing a text editor and wanted a finer degree of control over the
window that a normal edit box will allow, and so decided to build the
display beginning with a plain window and handle all the drawing
myself.

All the text in the screen is drawn with a single DrawString because I
am attempting to take advantage of Windows wrapping the text for me
when I draw a long string in a bounding rectangle. (I'm wondering if
that's really best now.)

The issue is writing the code to take a point-usually from a mouse
click-and convert it to the position in the string of text contained
in the window, for example, point(50,20) lands on txt[8].

I'm using MeasureCharacterRanges and binary searching the string and
that works fine when the hit is on the text proper.

Things become problematic when the click lands in the right margin and
the cursor should be placed at the end of a line. The problem arises
because it is tedious to figure out where Windows did the word wrap.
Now, if I measure a single character, if that character is the one
where the wrap occurs, a call to GetRegionScans returns an empty array
of rectangles. Using that fact, one can find the line ending.

Blank lines are an issue as well, as when measured, GetRegionScans
returns an empty array of rectangles for them, too. Some scheme
involving knowing rectangles above or below the blank lines is
necessary to locate the line and test for the hit.

So. . . The question: Is there an easier way?

On large strings, say 2000 characters, things get slow because of all
the measures. I can pre-measure the text as a set of small regions,
perhaps 64 characters, and that will speed things up quite a bit, but
the blank lines and right margins are just plain tedious.

Any help is very much appreciated.

Thanks,
gp

Jan 17 '07 #1
1 1257
For the sake of closure: It turned out much simpler to do my own word
wrapping. That way I know exactly what's on each line.

Jan 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jonathan | last post by:
I have a specific situation where I am applying padding to text inside of a "P" tag, where if the text wraps then the second line of text ignores the padding. Here is a snippet of what I am doing:...
1
by: DraguVaso | last post by:
Hi, I need to know the Lenght of the Text in a DataGridTextBoxColumn when I move with the mouse over it, and show it in a ToolTip. I have something that works, but it works only when the...
2
by: Sam Martin | last post by:
Hi all, I want to be able to draw wrapped text started at a point x into the rectangle on the first line If there's not a GDI+ method for this, i'm guessing it's a common technique, but can't...
0
by: luckybird | last post by:
I succeeded in obtaining a CListCtrl item info using HitTest() when the List Ctrl is owned by my current thread. But when I tried HitTest an item of a List Ctrl owned by other threads such as...
3
by: Maria Anthonsen | last post by:
I'm using HitTest to get a value from the cells into a textbox. I have put the HitTest code into the MouseDown-event, and everything is working except one thing. When I start the program the value...
1
by: Wepic | last post by:
render :update returns js wrapped in a HTML body Hi. From what I'm learned the below is suppose to return "alert('Im JS');" to the javascriptGenerator that's suppose to make the page scream...
8
by: Jonathan Sachs | last post by:
I'm trying to compose a list of items, each of which consists of text that wraps around a picture at the left margin. The examples I have seen tell me to do it like this: <p><img src="xxxx.jpg"...
2
by: =?Utf-8?B?UGFycm90?= | last post by:
I am trying to implement a drag and drop operation from a listbox to a data gridview control but I keep getting -1 for my row index when the dragdrop function is executed. Below is my coding. ...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.