473,499 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[C# 2.0] CustomControl and DrawString (GDI+)

Hello All,

I've created a WinForm control and everything is OK except the look
of the font on my control.

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

SizeF objTextSize = e.Graphics.MeasureString(this.Text,
this.Font);
PointF objTextPosition = new PointF(0, (this.Height -
objTextSize.Height) / 2);

e.Graphics.DrawString(this.Text, this.Font, Brushes.Black,
objTextPosition);
}
}

If I compare my Control to a Label, the text in the Label looks a lot
more sharp, beautiful, clean and clear... Why? For the same font and
size, I should have the same look. No?

What is wrong with my DrawString? Why my control text and font
doesn't have the same look and feel as a Label text and font?

Thanks for you help!

Martin

Sep 15 '06 #1
2 2962
Hi Martin,

Did you test different settings of:

Graphics.TextContrast
or
Graphics.TextRenderingHint

with regards
Marcin

Martin napisał(a):
Hello All,

I've created a WinForm control and everything is OK except the look
of the font on my control.

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

SizeF objTextSize = e.Graphics.MeasureString(this.Text,
this.Font);
PointF objTextPosition = new PointF(0, (this.Height -
objTextSize.Height) / 2);

e.Graphics.DrawString(this.Text, this.Font, Brushes.Black,
objTextPosition);
}
}

If I compare my Control to a Label, the text in the Label looks a lot
more sharp, beautiful, clean and clear... Why? For the same font and
size, I should have the same look. No?

What is wrong with my DrawString? Why my control text and font
doesn't have the same look and feel as a Label text and font?

Thanks for you help!

Martin
Sep 15 '06 #2
I'll give this a try !

Thanks !

Marcin Grzebski wrote:
Hi Martin,

Did you test different settings of:

Graphics.TextContrast
or
Graphics.TextRenderingHint

with regards
Marcin

Martin napisał(a):
Hello All,

I've created a WinForm control and everything is OK except the look
of the font on my control.

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

SizeF objTextSize = e.Graphics.MeasureString(this.Text,
this.Font);
PointF objTextPosition = new PointF(0, (this.Height -
objTextSize.Height) / 2);

e.Graphics.DrawString(this.Text, this.Font, Brushes.Black,
objTextPosition);
}
}

If I compare my Control to a Label, the text in the Label looks a lot
more sharp, beautiful, clean and clear... Why? For the same font and
size, I should have the same look. No?

What is wrong with my DrawString? Why my control text and font
doesn't have the same look and feel as a Label text and font?

Thanks for you help!

Martin
Sep 15 '06 #3

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

Similar topics

1
1308
by: DrDevious | last post by:
Maybe I am doing something wrong but has anyone else here noticed a difference in the positioning of text between the Graphics.DrawString method and the Win32 GDI DrawText function? My text is...
1
4345
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:...
6
9384
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...
5
5021
by: jack | last post by:
In using GDI+ drawstring, if the string to be drawn is in rtf format, how do I make GDI+ to recognize the rtf attributes. In other words, how do I draw one string in GDI+ , within which the...
5
2633
by: Bauer | last post by:
I am new to GDI+.I am drawing a string on the Win form using GDI+. My string content is long and it does not have any "vbcrlf". The whole string is displayed in a single line and is getting...
3
2479
by: Rich | last post by:
Hello, I need to draw some text on a form. No problem .... e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat) My problem is that I want to draw the text on top of some...
3
2821
by: Allen | last post by:
I've got a control that you can resize the contents of one of the text fields inside it. When the contents are resized to smaller than the text, I remove some of the end of the text and...
1
1678
by: Gidi | last post by:
Hi, Is it possible to draw string with few font styls, like in WORD (i.e. Bold and Underline) at the same line, on the same text ? and is it possible that part of the line will be bold and the...
7
10049
by: Brian Ward | last post by:
I am trying to get to grips with some basic graphics, being new to C#. I have this code (see below) in a simple project .. when I run it 6 text strings are drawn, as I expected .. but this happens...
0
7131
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
7174
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
7220
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...
0
7388
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...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4600
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
3099
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
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
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.