473,507 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the Top Left coordinates when drawing text

Hi,
I am new to GDI+ in C# and so excuse me if this sounds silly. I need
to draw text at different places on the form (mainly TopLeft, TopRight,
BottomLeft and BottomRight). I can use either DrawString or DrawText
methods to do this. My problem is how do I calculate the TopLeft point
that I need to supply to these methods? In case we need to pass a
Rectangle parameter how do I calculate the UpperLeft point, width and
height of the Rectangle?

Do I have to do this manually by calculating the width of the string
(which can be multiline) and then based on my desired location
calculate the point or are there any methods in the SDK that do this
for us? Also if anyone has done this before some sample code would be
very much appreciated.

thanks,
Satya.

Apr 14 '06 #1
1 2221
Hi Satya,

Use the Graphics.MeasureString method to get the dimensions of the text
rectangle. The TopLeft, TopRight, BottomLeft and BottomRight corners of a
ClientRectangle (the rectangle in which you want to draw the text)
correspond to (0,0), (Width, 0), (0, Height), and (Width, Height)
respectively. To calculate the upper-lefthand corner of the text rectangle
relative to the ClientRectangle, you would use (employing upper-case to
represent the ClientRectangle, and lower-case to represent the text
rectangle), you would use (0,0), (Width - width, 0), (0, Height - height),
and (Width-width, Height-height) respectively.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Satya" <sa*********@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Hi,
I am new to GDI+ in C# and so excuse me if this sounds silly. I need
to draw text at different places on the form (mainly TopLeft, TopRight,
BottomLeft and BottomRight). I can use either DrawString or DrawText
methods to do this. My problem is how do I calculate the TopLeft point
that I need to supply to these methods? In case we need to pass a
Rectangle parameter how do I calculate the UpperLeft point, width and
height of the Rectangle?

Do I have to do this manually by calculating the width of the string
(which can be multiline) and then based on my desired location
calculate the point or are there any methods in the SDK that do this
for us? Also if anyone has done this before some sample code would be
very much appreciated.

thanks,
Satya.

Apr 15 '06 #2

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

Similar topics

19
4781
by: Atif | last post by:
Hello all, In my html page I want to add an image say of 800x600. Now I want that when ever I am given two coordinates on this image say (x1, y1)=(50, 100) and (x2, y2)=(200, 300), the java script...
3
3591
by: mitsura | last post by:
Hi, I have included a small listing. The test program opens a panel and show a bitmap. What I want is to when the mouse is over the bitmap panel, I want to trap the left mouse click. The...
5
2814
by: Sameh Ahmed | last post by:
Hello there how do I send a mouse click to a specific set of coordinates in the desktop? what do I need to search for? any info is greatly appreciated. Regards Sameh
6
4008
by: Maverick | last post by:
There's a function in Borland C conio.h window (int left, int top, int right, int bottom) how can i provide the same function in VB.Net
0
1796
by: Amiram Korach | last post by:
When you create a MDI form, you can attach a main menu to the parent and to the child. When a child form is active, its menu is merged with the parent menu. The problem is: when the forms are...
1
4221
by: cmac89 | last post by:
Dear Group, I wonder if anyone can help me with a little VB.NET picturebox problem? I want to let the user click on a map and where they click I want to draw a circle. I'm using the...
4
2428
by: Tomasz Bak | last post by:
Hello, I have a simple problem: mark a list of defects on an image. I think the best way to do it is to select a single deffect, then take two coordinates of coursor form an image on a web...
1
3046
by: milbrand | last post by:
I have an IFrame: <IFRAME id="BIssues" title="issues" src="BIssues.aspx" frameBorder="no"style="position:absolute;width:100%;height: 150px;border:0px"> In this iframe I have onmouseover that...
3
3963
by: =?Utf-8?B?U3RldmVU?= | last post by:
I want to create tabs in the TabControl that are aligned on either the right or left side, but no text shows when doing this. Is there an issue here or a work around. Text for tabs on top or...
0
7223
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
7319
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
7376
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...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.