473,698 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing font color in C++

5 New Member
I am writing a program for my Computer Science class and I am making a game for extra credit. What I need to know is how do you change the font color so that when it prints out on the screen the text is not just the regular white color but maybe blue, red, green, etc.

Thanks
Erik
Nov 27 '06 #1
3 40013
Ganon11
3,652 Recognized Expert Specialist
If you are using windows, and your output is in a standard DOS command prompt, you can use the following function call:

Expand|Select|Wrap|Line Numbers
  1. system("color fg");
where f and g are color values. f is the background color, and g is the text color. The color values are as follows:

Expand|Select|Wrap|Line Numbers
  1. 0 = Black       8 = Gray
  2. 1 = Blue        9 = Light Blue
  3. 2 = Green       A = Light Green
  4. 3 = Aqua        B = Light Aqua
  5. 4 = Red         C = Light Red
  6. 5 = Purple      D = Light Purple
  7. 6 = Yellow      E = Light Yellow
  8. 7 = White       F = Bright White
For instance, if you wanted black background with red text, the function call would be

Expand|Select|Wrap|Line Numbers
  1. system("color 0c");
If your output is not in a command prompt, you may wish to consider using the conio library.
Nov 27 '06 #2
manontheedge
175 New Member
Is it possible to have for example, one line that is red, while the rest of the text is white? or does all of the text ( or background ) have to be the same color at any given time?
Nov 28 '06 #3
smithan
16 New Member
I am writing a program for my Computer Science class and I am making a game for extra credit. What I need to know is how do you change the font color so that when it prints out on the screen the text is not just the regular white color but maybe blue, red, green, etc.

Thanks
Erik
if u are working on linux, u may be using gtkmm, then these links may be of help
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/index.html
http://gtkmm.sourcefor ge.net/docs/gtkmm-2.4/docs/reference/html/group__Widgets. html

thanks
smitha
Nov 28 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
6645
by: Cengiz Ulku | last post by:
Hi all, I know now how to change the font name of a RTF file in a RTB control using, for example: RTextBox1.SelFontName = cmbFonts.Text I have a RTF file -created with Word- displayed in a RTB control. Whenever I change the font type during the runtime by selecting a font name from a combobox -of all system fonts, the text changes its font correctly but I loose some formatting such as a bold text and/or titles become normal text.
0
2944
by: Paul D. Sullivan | last post by:
I've been trying to find out how to increase the font size in the text entry fields in Invision Power Board 1.3 for a while. The part where you enter your post and do the quick reply and all that has a really small font by comparision to the display font in the forum, and I wanted to at least have the same size if possible. After some hours of working the issue, I tested about every relevant entry in the Style Sheet. I found one line...
6
10491
by: Ioannis Demetriades | last post by:
Hi, I need to change the printer's font to "control" -a printer font, and then send a sequence of characters to the printer. My problem is that I cannot change the printer's font. Can this be done without API calls? Thanks Ioannis
3
1848
by: Sakharam Phapale | last post by:
Hi All, I am using a richTextBox control for text editing purpose. I have written following procedure which change the font style of richTextBox. Dim f as font = rtbData.selectionFont() rtbData.SelectionFont = New Font(f, f.Style + (IIf(f.Bold, FontStyle.Bold * -1, FontStyle.Bold)))
7
2965
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and already formatted as "Shopping" ---Bold "for" -----Regular Now I want to underline whole text by preserving old style i.e. Bold and
15
40977
by: mart2006 | last post by:
Hi, This is probably really simple to most of you but I have a PHP based website that I want to change the font (of the outputted HTML) and I'm really struggling! Here is a snippet of my code: echo "<font face='arial' size='1'>"; echo " <TABLE BORDER=1> <TR>
15
3898
by: phillip.s.powell | last post by:
<style> div div table tr td a.navbar, div div table tr td font {display: none;} </style> <div class="navigationbar" style="background-color:Black; position: absolute; left:50%; top:127px; margin-left: -400px; width: 800px; height: 26px"> <!-- CODE GOES HERE --> </div>
1
1864
by: Blasting Cap | last post by:
I am having trouble changing the font for a PushButton control in a datagrid button column. I have seen several posts refer to styles and simple changes to the HTML for font changes but most of those referred to a LinkButton type of control. But in cases where someone is using the PushButton there are no posted solutions. Whenever these changes are made to the PushButton control they do not make any requested changes. I have seen one...
0
1359
by: nitehawk416 | last post by:
I want to change the font of my rich text box to a font I downloaded. In the properties the font isn't there, so I tried changing it through the code with this variable declaration Font MUDFONT = new Font("MUD 10",8, FontStyle.Regular); and then calling it in the text changed function private void DisplayBox_TextChanged(object sender, EventArgs e) { DisplayBox.Font = MUDFONT;
4
3341
by: gubbachchi | last post by:
Hi all, Please anybody help me solve this problem. I am stuck up with this from past 2 weeks. I am developing an application where, when the user selects date from javascript datepicker and enters the comments and clicks the save button then the date and the date will be stored in the mysql database. This is working fine. But my problem is when, after the user had made an entry the date in the calendar for which an entry has made should be...
0
8609
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
9166
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
8871
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
7737
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
5861
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
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.