473,387 Members | 1,516 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.

Custom color doesn't work in DrawString

I'm sure I've missed the obvious, but when I define a custom color, my
DrawString call from my Paint event doesn't seem to draw anything at
all.

void btnNav_Paint(object sender, PaintEventArgs e)
{
SolidBrush brush1 = new SolidBrush(Color.Blue);
SolidBrush brush2 = new SolidBrush(Color.FromArgb(0x0000FF));
StringFormat format =
(StringFormat)StringFormat.GenericTypographic.Clon e();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
Rectangle drawingRect = ClientRectangle;
drawingRect.Inflate(-15, 0);
e.Graphics.DrawString("Text", this.Font, brush1, drawingRect,
format);
//e.Graphics.DrawString("Text", this.Font, brush2, drawingRect,
format);
}

When I use brush1, the text draws correctly. When I use brush2,
nothing seems to draw at all. Any color I create with Color.FromArgb()
fails, but the standard colors all work.

This code is in an object derived from Label. I just chained in my
Paint event handler, so the base class Paint is still being called:

this.Paint += new PaintEventHandler(btnNav_Paint);

I can't figure out why a custom color behaves differently from a
standard color. Any ideas?
Sep 6 '08 #1
3 5294
TAB

Hi

With SolidBrush(Color.FromArgb(0x0000FF));
you are defining a Color with zero alpha, which means it will be invisible.
This should be either Color.FromArgb(0x000000FF) (32-bit),
or Color.FromArgb(255, 0x0000FF), alpha + color,
or Color.FromArgb(0, 0, 255) for blue, alpha assumed 255.

"Larry" <La****@digis.netskrev i meddelandet
news:9c**********************************@o40g2000 prn.googlegroups.com...
I'm sure I've missed the obvious, but when I define a custom color, my
DrawString call from my Paint event doesn't seem to draw anything at
all.

void btnNav_Paint(object sender, PaintEventArgs e)
{
SolidBrush brush1 = new SolidBrush(Color.Blue);
SolidBrush brush2 = new SolidBrush(Color.FromArgb(0x0000FF));
StringFormat format =
(StringFormat)StringFormat.GenericTypographic.Clon e();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
Rectangle drawingRect = ClientRectangle;
drawingRect.Inflate(-15, 0);
e.Graphics.DrawString("Text", this.Font, brush1, drawingRect,
format);
//e.Graphics.DrawString("Text", this.Font, brush2, drawingRect,
format);
}

When I use brush1, the text draws correctly. When I use brush2,
nothing seems to draw at all. Any color I create with Color.FromArgb()
fails, but the standard colors all work.

This code is in an object derived from Label. I just chained in my
Paint event handler, so the base class Paint is still being called:

this.Paint += new PaintEventHandler(btnNav_Paint);

I can't figure out why a custom color behaves differently from a
standard color. Any ideas?
Sep 6 '08 #2
TAB wrote:
>
Hi

With SolidBrush(Color.FromArgb(0x0000FF));
you are defining a Color with zero alpha, which means it will be invisible.
This should be either Color.FromArgb(0x000000FF) (32-bit),
That still has an alpha component of zero.
or Color.FromArgb(255, 0x0000FF), alpha + color,
There is no such overload. You have to use a Color value:

Color.FromArgb(255, Color.FromArgb(0x0000FF))
or Color.FromArgb(0, 0, 255) for blue, alpha assumed 255.
That works. You can also specify the alpha component:

Color.FromArgb(255, 0, 0, 255)

--
Göran Andersson
_____
http://www.guffa.com
Sep 6 '08 #3
TAB
You are right, I was in a hurry so the answer was without any afterthought.

"Göran Andersson" <gu***@guffa.comskrev i meddelandet
news:OT**************@TK2MSFTNGP03.phx.gbl...
TAB wrote:
>>
Hi

With SolidBrush(Color.FromArgb(0x0000FF));
you are defining a Color with zero alpha, which means it will be
invisible.
This should be either Color.FromArgb(0x000000FF) (32-bit),

That still has an alpha component of zero.
>or Color.FromArgb(255, 0x0000FF), alpha + color,

There is no such overload. You have to use a Color value:

Color.FromArgb(255, Color.FromArgb(0x0000FF))
>or Color.FromArgb(0, 0, 255) for blue, alpha assumed 255.

That works. You can also specify the alpha component:

Color.FromArgb(255, 0, 0, 255)

--
Göran Andersson
_____
http://www.guffa.com
Sep 7 '08 #4

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

Similar topics

2
by: Benny Raymond | last post by:
More problems with this... When I run this code, the main form returns an invalid cast exception as it's executing the line "TreeNode n = (TreeNode) this.Nodes;" Does anyone know what would...
1
by: TT (Tom Tempelaere) | last post by:
Hi there, I made a custom drawn ComboBox. The DrawItem event handler is (explanation follows) <code> private void OnDrawItem ( object sender, System.Windows.Forms.DrawItemEventArgs e ) {
1
by: Brian Henry | last post by:
I am trying to make a custom user control that gets a list of users from our database and populates the list, its an owner drawn control also, the problem is, I placed the item onto a form and...
6
by: Scott Emick | last post by:
similar to: http://overtons.com/lettering/lettering.html I was thinking of writing it myself in either vb6 as an activex dll server component, or vb.net - it does seem more feasable to me in vb...
2
by: Bouxirot Eric | last post by:
hi there ! i'm searching a way to draw a string around a circle (or other forms like line, arc, etc...) and with caracter orientation.. i have found some stranges things on VB6 but i want do it...
0
by: Piotr Strycharz | last post by:
Hi, I need to develop a custom control. The control is going to be something like Properties window in VS - listview (grid?) with resizable columns and collapsable sections. The control needs...
4
by: cashdeskmac | last post by:
I have created a control and added a few properties. One of these is an array of DateTime objects, looking like this: public DateTime MyDates { get { return theDate;} set {theDate =...
2
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...
2
by: DaveL | last post by:
when painting the background of a mdi app window how can i resolve the flicker when it paints from darker to lighter colors below is the code i wrote private void...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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,...

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.