C Graphics में Text
In this page:
outtext("text"); // at the current position
outtextxy(x, y, "text"); // at (x, y)
settextstyle(font, direction, size);
settextjustify(horizontal, vertical);
Text Output करना
outtext() graphics system की current cursor position से शुरू होते हुए एक text string print करता है, जबकि outtextxy() इसकी बजाय आपको exact (X, Y) pixel coordinates specify करने देता है जहाँ text draw होना चाहिए, cursor को manually track किए बिना precise placement देते हुए।
उदाहरण: Outputting Text
#include <graphics.h>
int main() {
initgraph(0, 0, "");
outtextxy(100, 100, "Hello");
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Fonts और Text Styles
settextstyle() font, size, और orientation बदलता है जो बाद के text output में इस्तेमाल होता है, normal left-to-right text के लिए HORIZ_DIR और vertically पढ़ने के लिए rotated text के लिए VERT_DIR जैसे orientations support करते हुए, जो एक chart के vertical axes label करने के लिए handy है।
उदाहरण: Fonts and Text Styles
#include <graphics.h>
int main() {
initgraph(0, 0, "");
settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
outtextxy(50, 50, "Styled");
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Text Alignment
settextjustify() control करता है कि text आपके दिए coordinate के relative कैसे align होता है, अलग horizontal (LEFT_TEXT, CENTER_TEXT, RIGHT_TEXT) और vertical justification constants accept करते हुए, इसलिए same outtextxy() call एक fixed point के around text center, left-align, या right-align कर सकती है।
उदाहरण: Text Alignment
#include <graphics.h>
int main() {
initgraph(0, 0, "");
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(150, 150, "Centered");
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Numeric Values Display करना
क्योंकि outtext() और outtextxy() सिर्फ plain string arguments accept करते हैं, एक numeric value display करने के लिए पहले उस number को खुद एक string में convert करना होगा, आमतौर पर एक character buffer में लिखने वाले sprintf() से, उस buffer को text-drawing function को pass करने से पहले।
उदाहरण: Displaying Numeric Values
#include <graphics.h>
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
initgraph(0, 0, "");
char buffer[10];
sprintf(buffer, "%d", 42);
outtextxy(100, 100, buffer);
getch();
closegraph();
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Text और Shapes मिलाना
positioned text को drawn shapes के साथ combine करना — जैसे एक centered label के पीछे एक rectangle — BGI drawing primitives से पूरी तरह menus, labeled buttons, और dashboards जैसे simple graphical interfaces बनाने के पीछे basic technique है।
उदाहरण: Mixing Text and Shapes
#include <graphics.h>
int main() {
initgraph(0, 0, "");
rectangle(50, 50, 150, 100);
outtextxy(70, 70, "Label");
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
- graphics mode में
printfइस्तेमाल करना और window में text की उम्मीद करना, जब आपकोouttextxyइस्तेमाल करना चाहिए। outtextxyको पहलेsprintfसे string में convert किए बिना एक number pass करना।- text draw करने के बाद text style set करना, ताकि इसका कोई असर न हो।
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: