473,789 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Draw String

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 3492
You could try something like:

'Determine the font to use
Dim MyFont As New Font(Drawing.Fo ntFamily.Generi cSansSerif, 8.0F,
FontStyle.Bold, GraphicsUnit.Po int, 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(MyCo lor)
'Draw the string
e.Graphics.Draw String("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.d ivemaster.org> wrote in message
news:h1******** *************** *********@4ax.c om...
Hi all,

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

e.Graphics.Draw String

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.Fo ntFamily.Generi cSansSerif, 8.0F,
FontStyle.Bold, GraphicsUnit.Po int, 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(MyCo lor)
'Draw the string
e.Graphics.Draw String("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.d ivemaster.org> wrote in message
news:h1******** *************** *********@4ax.c om...
Hi all,

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

e.Graphics.Draw String

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.d ivemaster.org> scripsit:
I am using the color dialog box to select a colour
to print with. However, the

e.Graphics.Draw String

method uses Brushes.Black, not Color.Black.


Color -> Brush:

\\\
Dim b As New Brush(Color.Bla ck)
..
..
..
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(myLa bels.Colour)

did the trick, but

Dim myBrush As New Brush(Color.Bla ck)
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.d ivemaster.org>
wrote:
Hi all,

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

e.Graphics.Dra wString

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.d ivemaster.org> schrieb
Thanks for the help with the color to brush cast.

Using
dim myBRush as new SoldiBrush(myLa bels.Colour)

did the trick, but

Dim myBrush As New Brush(Color.Bla ck)
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
3063
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 colspan=2>Footer Area</th></tr> </table> |=========================| | Header Area |
1
1325
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
43464
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
4096
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 display it using windows explorer, the black color is in fact transparent. Could it be that the bitmap is not an alpha bitmap that causes the icon to not have the black color transparent? --
2
4497
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 pixels of the same color to a new color, or possibly a command that changes all pixels of a color to a new color; the only instance of color.control in the picture is in the background area. There is a C# edge detection routine that I found on...
3
2674
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, HeaderBackColor, etc.) ... then I create several DataGridTextBoxColumns and set their properties (MappingName, Width, Alignment, etc.) ... then I add these columns to the DataGridStyle. Next, using the MappingNames I add the columns to a DataTable ... then I...
0
2882
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 below: chartGenerator.vb class: Imports System.Drawing.Imaging Public Class chartGenerator Private myImage As Bitmap
25
4395
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 opened it in Visual Studio 2005. I've cleared up most errors, but have one that beats the heck out of me. I have a page: sales/Item.aspx that has several datagrids in it.
2
1611
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)) g.FillRectangle(Brushes.Black, new Rectangle(Point.Empty, bmp.Size)); One might expect that for any (x, y) inside the image bounds,
0
9659
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
9504
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
10400
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...
1
10134
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9011
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
6754
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5413
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5545
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4084
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

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.