473,889 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DrawString right aligned

GTi
This must be the simplest question on the web.
How can I right align text with DrawString ?

Normal (left aligned):
1234567890
123456789
12345678
1234567
123456
12345
1234
123
12
1

Right aligned:
1234567890
123456789
12345678
1234567
123456
12345
1234
123
12
1

(it may not look right on some readers)

Jan 21 '06 #1
4 12010
Use one of the overloads of the DrawString method that accepts a
StringFormat and ensure that the Alignment property of the StringFormat
instance is set to Far.

--
Tim Wilson
..NET Compact Framework MVP

"GTi" <tu****@gmail.c om> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
This must be the simplest question on the web.
How can I right align text with DrawString ?

Normal (left aligned):
1234567890
123456789
12345678
1234567
123456
12345
1234
123
12
1

Right aligned:
1234567890
123456789
12345678
1234567
123456
12345
1234
123
12
1

(it may not look right on some readers)

Jan 22 '06 #2
GTi
Yeeeeh -
Why do they have to change it to near / far ???
Whats wrong with left/right and top/bottom?
Only to make old dogs more confused ?

Jan 22 '06 #3
The StringFormat class also has a LineAlignment property that uses the
StringAlignment enum. The LineAlignment is the vertical alignment. So it
would be top, middle, and bottom. However, by calling the enum values near,
center, and far they can reuse this enum across both alignment properties.
Used in the context of the LineAlignment property the "far" value would mean
bottom. There is also the notion of left-to-right versus right-to-left
layout. So based on the layout, "far" means the opposite side, or far side,
from the origin position, which could be left or right depending on the
layout. I'm in no way attempting to defend this decision, nor am I stating
that these are the reasons why it was done. I'm merely stating that these
might be possible reasons for this naming decision.

--
Tim Wilson
..NET Compact Framework MVP

"GTi" <tu****@gmail.c om> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Yeeeeh -
Why do they have to change it to near / far ???
Whats wrong with left/right and top/bottom?
Only to make old dogs more confused ?

Jan 22 '06 #4
I believe "near" and "far" were chosen to provide compatibility with
right-to-left (RTL) languages such as Hebrew and Arabic. For example,
"near" means to align the text to the left edge in a Left-to-right
language, and align to the right on a RTL language.

However, this use of near and far is not consistent across the .NET
platform; see Control.RightTo Left property
(http://msdn.microsoft.com/library/de...oLeftTopic.asp)
and its interaction with child control's HorizontalAlign ment
properties.

-- Tim Scott
http://geekswithblogs.net/tscott

Jan 22 '06 #5

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

Similar topics

22
11113
by: Marek Mand | last post by:
How to create a functional *flexible* UL-menu list <div> <ul> <li><a href=""></li> <li><a href=""></li> <li><a href=""></li> </ul> </div> (working in IE, Mozilla1.6, Opera7 (or maybe even in Opera6))
1
4371
by: David Lindgren | last post by:
Hello! I am using the DrawString method with different StringAlignments passed to it and the result varies alot! Take a look at this screenshot: http://www.lowrad.net/files/alignment_screenshot.jpg As you can see I am printing four different text in each of the the parts of this image. ( The three parts are three images)
6
9413
by: Sam Sungshik Kong | last post by:
Hello! I'm testing Graphics.DrawString and it's very strange. I created an event handler for the form.s Paint event. (There's no other code in the form.) private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics;
19
2039
by: JB | last post by:
Hi All, Why doesn't this work in Firefox but is perfect in IE6? In IE6, the text is on the same line but in Firefox, the left aligned text is on the line above the right aligned text. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>
3
7886
by: Sjef Janssen | last post by:
Is it possible to have a box (div) which sets a background-color and which contains (on the same line) text which is left aligned and text which is right aligned. (as in a table: two td's left one left aligned, right one right aligned). Thanxs!!
2
2547
by: ChrisNightingale | last post by:
Hi everybody, I have an odd issue which I'm not sure how to resolve. I'm basically implementing a print mechanism which takes a series of controls and reproduces them on a print document. So what I'm trying to do is print out a label so what I basically did is use Graphics.DrawString passing in the text of the label, the font of the label and the rectangle which represents the label (because it's set to autosize this should be the right...
2
14979
by: Siv | last post by:
Hi, I want to print using the Graphics.Drawstring method but instead of using either bold or underline I want to combine both so the printed text is bold and underline?? The way I send the drawstring command is as follows: Somewhere in my declarations I have: Private ra As System.Drawing.StringFormat
4
6193
by: Sin Jeong-hun | last post by:
Hello. It seems like the default behavior of DrawString is trying to keep the whole word if possible. I'd like the string to be drawn in multilines, but filling the entire line width. For example I'm using a fixed-width font, and the width of the layout rectangle is that of 12 characters, the result I want is, This is a sa mple text. not, This is a
9
2977
by: kynos | last post by:
I would like to paint a box using DrawString, standard Unicode characters (box drawings characters) and monospaced font. Unfortunately for some fonts painted lines contain a break. Example code, in whom one can see the error: private void Form1_Paint (object sender, PaintEventArgs e) ( Font font = new Font ( "Courier New", 9);
0
9966
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9810
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10791
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10442
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9610
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4647
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 we have to send another system
3
3256
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.