473,378 Members | 1,536 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,378 software developers and data experts.

Drawing text without an offset

I need to create a label with the last character drawn in red.
My idea was to create a label and override OnPaint.
So far so good.
I then measure the character range for the last character.
All good.
Then when I call drawstring and pass the rectangle I get via
Region.GetBounds(Graphics) it draws it with the same offset as the
beginning of the label.
Not good.

Question is, how can I stop it from doing this?
TextRenderer.DrawText does the same thing.

Failing this, is there another way I should be doing this?

The region is correct as when I fill the region and draw the whole
string normally, the last character falls smack into the filled region.
Cheers
JB
May 29 '06 #1
2 1942
I'm not sure why you're using a Region here. The PaintEventArgs class has a
property called ClipRectangle that defines the drawing area. You can use
Graphics.MeasureString to find the size of the rectangle that the first part
of the string will occupy, then combine the X and Y properties of that
Rectangle added to the X and Y properties of the ClipRectangle to define
where to draw the last character.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

This is, by definition, not that.

"John B" <jb******@yahoo.com> wrote in message
news:44**********@news.iprimus.com.au...
I need to create a label with the last character drawn in red.
My idea was to create a label and override OnPaint.
So far so good.
I then measure the character range for the last character.
All good.
Then when I call drawstring and pass the rectangle I get via
Region.GetBounds(Graphics) it draws it with the same offset as the
beginning of the label.
Not good.

Question is, how can I stop it from doing this?
TextRenderer.DrawText does the same thing.

Failing this, is there another way I should be doing this?

The region is correct as when I fill the region and draw the whole string
normally, the last character falls smack into the filled region.
Cheers
JB

May 29 '06 #2
Kevin Spencer wrote:
I'm not sure why you're using a Region here. The PaintEventArgs class has a
property called ClipRectangle that defines the drawing area. You can use
Graphics.MeasureString to find the size of the rectangle that the first part
of the string will occupy, then combine the X and Y properties of that
Rectangle added to the X and Y properties of the ClipRectangle to define
where to draw the last character.

If you have a look at the doc's for measurestring it specifically says
it is approximate only and to get more accurate measure, use
measurecharacterranges which returns an array of characterranges from
which I then get the region.
I would still have the same problem no matter what I used to calculate
where to paint. Where to paint is not a problem, where it _will_ paint
is the problem.
If I paint a dot @ 10,10 then draw a string at 10,10 the dot is offset
back and up by ?, ?.
That is the problem.

Cheers
JB
May 29 '06 #3

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

Similar topics

7
by: F. Da Costa | last post by:
Hi, I' looking to retrieve ProdName1 form the <tr> below. <tr id="1-1-1" class="even"> <td> <div class="tier4"> <a href="#" class="leaf"></a> ProdName1 </div>
2
by: mhansemann | last post by:
I'm a C# (but not programming in general) novice, but I couldn't find any answer to this elsewhere. I'm trying to make a text scroll on the form. I thought this was a good example to get started...
13
by: Metallicraft | last post by:
I have a vb6 application. On the main form is a picture box with one or two images and several pieces of text displayed in it. These are created on the fly using gdi32 routines that are all in a...
3
by: pamelafluente | last post by:
Hi I have some instances of a class: Class Myobject Public Color As Color Public Label As String End Class I need to show these instances on a treeview (which has checked boxes)
9
by: liorm | last post by:
Hi folks, I need to write a short program which gets a few parameters and draws a diagram in the text file. Basically what I need is a guidance on how I put stream indicator to the required...
3
by: John B | last post by:
I need to create a label with the last character drawn in red. My idea was to create a label and override OnPaint. So far so good. I then measure the character range for the last character. All...
4
by: amit | last post by:
Hi guys!I am trying to write a program which will segregate some selected keywords from a given file.The source code is given alongwith #include<stdio.h> #include<string.h> char...
0
by: jijiz | last post by:
Hi everyone, My english is quite poor... I prefer inform you about it... So i would like to draw some pictures (cubic, square, lines) into objects (QLabel), and instanciate those objects into a...
9
by: Steven Bethard | last post by:
I have some text and a list of Element objects and their offsets, e.g.:: ... (etree.Element('a'), 0, 21), ... (etree.Element('b'), 11, 18), ... (etree.Element('c'), 18, 18), ... ] ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.