473,385 Members | 2,210 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,385 software developers and data experts.

Converting Color.Black to Brushes.Black

JJ
Hi all,

I am using the color dialog box to select a colour
to print with. However, the

e.Graphics.DrawString

method uses Brushes.Black, not Color.Black.

How do I convert from Brushes to Colors and back
again so that my program will run correctly?

Any help much appreciated,

Jason.
Nov 20 '05 #1
5 3455
You could try something like:

'Determine the font to use
Dim MyFont As New Font(Drawing.FontFamily.GenericSansSerif, 8.0F,
FontStyle.Bold, GraphicsUnit.Point, 0, False)
'Determine which color you are going to use
Dim MyColor As Color = Color.Black
'Create a brush based on the color
Dim MyBrush As New SolidBrush(MyColor)
'Draw the string
e.Graphics.DrawString("Test String", MyFont, MyBrush, 0, 0)
'Dispose of the brush object.
MyBrush.Dispose
'Dispose of the font object
MyFont.Dispose

With this method, you don't need to return the color from the brush since
you have already defined the color before creating the brush. You simply
access MyColor to determine which color the text was drawn in.

Hope this helps,
Jody
"JJ" <ja***@nospam.divemaster.org> wrote in message
news:h1********************************@4ax.com...
Hi all,

I am using the color dialog box to select a colour
to print with. However, the

e.Graphics.DrawString

method uses Brushes.Black, not Color.Black.

How do I convert from Brushes to Colors and back
again so that my program will run correctly?

Any help much appreciated,

Jason.

Nov 20 '05 #2
You could try something like:

'Determine the font to use
Dim MyFont As New Font(Drawing.FontFamily.GenericSansSerif, 8.0F,
FontStyle.Bold, GraphicsUnit.Point, 0, False)
'Determine which color you are going to use
Dim MyColor As Color = Color.Black
'Create a brush based on the color
Dim MyBrush As New SolidBrush(MyColor)
'Draw the string
e.Graphics.DrawString("Test String", MyFont, MyBrush, 0, 0)
'Dispose of the brush object.
MyBrush.Dispose
'Dispose of the font object
MyFont.Dispose

With this method, you don't need to return the color from the brush since
you have already defined the color before creating the brush. You simply
access MyColor to determine which color the text was drawn in.

Hope this helps,
Jody
"JJ" <ja***@nospam.divemaster.org> wrote in message
news:h1********************************@4ax.com...
Hi all,

I am using the color dialog box to select a colour
to print with. However, the

e.Graphics.DrawString

method uses Brushes.Black, not Color.Black.

How do I convert from Brushes to Colors and back
again so that my program will run correctly?

Any help much appreciated,

Jason.

Nov 20 '05 #3
* JJ <ja***@nospam.divemaster.org> scripsit:
I am using the color dialog box to select a colour
to print with. However, the

e.Graphics.DrawString

method uses Brushes.Black, not Color.Black.


Color -> Brush:

\\\
Dim b As New Brush(Color.Black)
..
..
..
b.Dispose()
///

Why do you need the reverse "conversion"?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
JJ
Thanks for the help with the color to brush cast.

Using
dim myBRush as new SoldiBrush(myLabels.Colour)

did the trick, but

Dim myBrush As New Brush(Color.Black)
did not!

myLabels is a class and Colour is a shared property that
stores its value in a private shared field that is defined as

Color.

Do you have any ideas when one method should work
and the other not? I get a message that says

'New' cannot be used on a class that is declared 'MustInherit'.

I have the program segment working now but it would be
useful to understand what the difference is between your
two suggestions!

Thanks,

Jason.

On Fri, 23 Jan 2004 15:59:18 +0000, JJ <ja***@nospam.divemaster.org>
wrote:
Hi all,

I am using the color dialog box to select a colour
to print with. However, the

e.Graphics.DrawString

method uses Brushes.Black, not Color.Black.

How do I convert from Brushes to Colors and back
again so that my program will run correctly?

Any help much appreciated,

Jason.


Nov 20 '05 #5
"JJ" <ja***@nospam.divemaster.org> schrieb
Thanks for the help with the color to brush cast.

Using
dim myBRush as new SoldiBrush(myLabels.Colour)

did the trick, but

Dim myBrush As New Brush(Color.Black)
did not!

myLabels is a class and Colour is a shared property that
stores its value in a private shared field that is defined as

Color.

Do you have any ideas when one method should work
and the other not? I get a message that says

'New' cannot be used on a class that is declared 'MustInherit'.

I have the program segment working now but it would be
useful to understand what the difference is between your
two suggestions!

Brush is an abstract class, i.e. you can not create an instance. You can
only create an instance of classes derived from Brush, like SolidBrush.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6

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

Similar topics

6
by: Robert P. Stearns | last post by:
I have been trying to convert the following simple table into CSS. <table> <tr><th colspan=2>Header Area</th></tr> <tr><th>Navigation Area</th><th>Information Area</th></tr> <tr><th...
1
by: Einar Høst | last post by:
Well, subject says it all really... Thanks, Einar -- "If it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic" -- Lewis Carroll
2
by: boxim | last post by:
having a moment, cant you just Brush br = new Brush(Color.Black);??? saying you cant cos it's an abstract class need to get to a brush from a color tia sam martin
3
by: Dennis | last post by:
I have a bitmap and make the color transparent; mybitmap.MakeTransparent(Color.Black) When I save it as a Icon, the black color is not transparent. However, if I save it as a bitmap then...
2
by: Shane Stewart | last post by:
I've created a user control inheriting a picturebox. I want to set a non-rectangular area to the current system color.control. I'm looking for either a "fill" command that will set all contiguous...
3
by: fripper | last post by:
I think I am using the proper terminology here ... I am using VB 2003 and have a DataGrid to which I then attach a TableStyle ... then I set the properties of the TableStyle (BackColor,...
0
by: benfly08 | last post by:
Hi, guys. I have a program to draw bar/pie chart based on the data i hard coded in it. However, my image comes with "BLACK" background color. I don't know how to fix this. The code snippet is...
25
by: Blasting Cap | last post by:
I keep getting errors that pop up when I am trying to convert an application from dotnet framework 1.1 to framework 2.0. The old project was saved in sourcesafe from Visual Studio 2003, and I have...
2
by: Ben Voigt [C++ MVP] | last post by:
I guess this must be a well-known issue that I just hit my head on. Color.Equals doesn't apply the usual equality test. For example: using (g = Graphics.FromImage(bmp))...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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?
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
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
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...

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.