用C语言打印不同字体和大小的彩色消息

在C/C++中,我们可以使用图形。h头文件,用于创建使用图形功能的程序,如创建不同对象、设置文本颜色、以不同字体和大小打印消息、更改输出控制台的背景等等。 在这里,我们将创建一个程序,将打印信息(“极客”)的彩色形式在不同的字体风格和大小。下面列出了使用的一些功能:

null
  • setcolor(): 它将设置光标颜色,因此输出屏幕上写入的任何内容都将使用setcolor()规定的颜色。 功能原型:
    setcolor(int)
  • settextstyle(): 它设置文本字体样式、方向(水平/垂直)和字体大小。 功能原型:
    settextstyle(int style, int orientation, int size);
  • outtextxy(): 它将打印在某个特定坐标(x,y)传递给它的消息。 功能原型:
    settextstyle(int style, int orientation, int size);
  • 更多功能: TextHeight():
    textheight();

    TextWidth():

    textwidth();

    SetUserCharSize():-

    setusercharsize(x1,y1,x2,y2);

注意:给定的程序不会在IDE上运行,请在编译器上尝试

// C program to print
// message as colored characters
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
// function for printing
// message as colored character
void printMsg()
{
// auto detection
int gdriver = DETECT,gmode,i;
// initialize graphics mode
initgraph(&gdriver,&gmode, "C:\Turboc3\BGI" );
for (i=3; i<7; i++)
{
// setcolor of cursor
setcolor(i);
// set text style as
// settextstyle(font, orientation, size)
settextstyle(i,0,i);
// print text at coordinate x,y;
outtextxy(100,20*i, "Geeks" );
delay(500);
}
delay(2000);
}
// driver program
int main()
{
printMsg();
return 0;
}


输出:

color

本文由 希瓦姆·普拉丹(anuj_charm) .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享