vc++图形界面文本框
In Advance Learning Tutorial, today we will learn about the colors in C / C + +. So far, you have used only two colors in your program Black and White, Black color in Background and White color foreground, i.e. to print the character.
在高级学习教程中,今天我们将学习C / C ++中的颜色。 到目前为止,您在程序中仅使用了两种颜色:黑色和白色,背景中的黑色和白色前景,即打印字符。
By default, all compilers use these two colors. But if you want to print any character on your screen from the color of your choice, then you can do it with the help of the functions described below. Keep in mind that the functions described below will only run on Text Mode. Using the colors, you can make your program more attractive in C /C++.
默认情况下,所有编译器都使用这两种颜色。 但是,如果您想从您选择的颜色上在屏幕上打印任何字符,则可以借助下面描述的功能来完成。 请记住,下面描述的功能将仅在文本模式下运行。 使用颜色,可以使您的程序在C / C ++中更具吸引力。
Total 15 colors have been defined in C++. To use any color, you can use the name of that color or the corresponding value of that color. This value is already defined in the compiler.
在C ++中总共定义了15种颜色。 要使用任何颜色,可以使用该颜色的名称或该颜色的相应值。 此值已在编译器中定义。
All the 15 colors and their values are given in the table below.
下表列出了所有15种颜色及其值。
Values of Colors
颜色的价值
1. BLACK 0
2. BLUE 1
3. GREEN 2
4. CYAN 3
5. RED 4
6. MAGENTA 5
7. BROWN 6
8. LIGHTGRAY 7
9. DARKGRAY 8
10. LIGHTBLUE 9
11. LIGHTGREEN 10
12. LIGHTCYAN 11
13. LIGHTRED 12
14. LIGHTMAGENTA 13
15. YELLOW 14
16. WHITE 15
Note:
注意:
Before using Colors, you must include an important header file <conio.h> in your program.
使用颜色之前,必须在程序中包含重要的头文件<conio.h> 。
The two Basic Functions for using colors in the Text Mode have been defined in C / C ++ and both these Functions are also declared in conio.h Header file.
在C / C ++中定义了在文本模式下使用颜色的两个基本功能,并且这两个功能也在conio.h头文件中声明。
textcolor (int color)
textcolor(int颜色)
textbackground (int color)
textbackground(int颜色)
That is why you are required to include this file. Otherwise, the program will show errors while compiling.
这就是为什么要求您包含此文件的原因。 否则,程序将在编译时显示错误。
textcolor (int color):
textcolor(int颜色):
It is used to set the color of the character in Text Mode. You will have to pass the name of the color or corresponding value (which is shown in the table) in the parameter of the function, in which color you want to display the character on the screen or print it.
它用于在文本模式下设置字符的颜色。 您必须在函数的参数中传递颜色的名称或相应的值(在表中显示),您要在屏幕上显示或打印字符时使用哪种颜色。
textbackground (int color):
textbackground(int颜色):
With the help of this function, you can set the background color of the character in Text Mode. This function will also be used in the same way, pass the color or color of the color you want to the background in the function's parameter.
借助此功能,您可以在文本模式下设置字符的背景颜色。 此函数也将以相同的方式使用,将颜色或所需颜色的颜色传递给函数参数中的背景。
Have a look at the example below to know the syntax more properly.
请看下面的示例,以更正确地了解语法。
textcolor( RED );
textbackgrond( YELLOW );
Or you can use:
或者您可以使用:
textcolor( 4 );
textbackgrond( 14 );
You can use any of the two syntaxes in your program. Both will give the same output. An example of the program is mentioned below. You run this program on your computer to understand better.
您可以在程序中使用两种语法中的任何一种。 两者将给出相同的输出。 程序示例如下。 您可以在计算机上运行该程序以更好地理解。
#include <conio.h>
void main()
{
clrscr();
textcolor(RED);
cprintf ("Welcome to Tutorial of Graphics in C/C++\n");
textcolor(LIGHTBLUE);
cprintf("Hello\n");
getch();
}
Note:
注意:
The main thing to note in the above-given program is that instead of printf the cprintf function has been used. If you use only the printf function, the color will not have any impact on the character in the output, and by default, the character in white color will be printed. cprintf is a console output function. This function works for functions that produce a direct text mode output on the screen.
在上面给出的程序中要注意的主要事情是,使用了cprintf函数代替了printf 。 如果仅使用printf函数,则颜色不会对输出中的字符产生任何影响,默认情况下,将打印白色字符。 cprintf是一个控制台输出功能。 此功能适用于在屏幕上产生直接文本模式输出的功能。
翻译自: https://www.includehelp.com/c/graphics-in-c-cpp-using-colors-in-text-mode.aspx
vc++图形界面文本框