Get size of text in pixel C#

21 Mar 2018,
Share: 

วิธีหาขนาดของข้อความ ว่ามีขนาดความกว้าง และความสูงกี่ Pixel ทําได้ด้วยตัวอย่าง Function นี้

private SizeF getsizeFont(string text, Font drawFont) {
    Bitmap textBitmap = new Bitmap(1, 1);
    Graphics drawGraphics = Graphics.FromImage(textBitmap);

    return drawGraphics.MeasureString(text, drawFont);
}

วิธีใช้ function คือ

//Width size
float w = getsizeFont("", new Font("Arial", 16)).Width;
//Height size
float h = getsizeFont("", new Font("Arial", 16)).Height;

Suggestion blogs

[ภาษาซี] การแสดงผลข้อมูล

function ที่ใช้ในการแสดงผลข้อมูลออกทางหน้าจอคือ printf (print formatted) ทําหน้าที่แปลงในลักษณะของเลขฐานสอง ที่คอมพิวเตอร์ประมวลผลได้ ให้อยู่ในรูปที่มนุษย์เข้าใจ และแสดงผลออกทางจอภาพ

copy โฟลเดอร์ที่ภายในมีข้อมูลอยู่ ubuntu

โดยปกติแล้วถ้าเราต้องการจะ Copy อะไรซักอย่างเราจะใช้คําสั่ง cp แต่จะไม่สามารถใช้กับโฟลเดอร์ที่มีข้อมูลอยู่ภายในได้ เราจะต้องเพื่ม option -avr เข้าไปดังนี้

วิธีปิด update google chrome

Google chrome จะ update อัตโนมัติ แต่ในบ้างครั้งเราไม่ต้องการจะใช้ version ใหม่ เพราะบางที่ version ใหม่อาจจะยังไม่ stable ดังนั้นเราจะมาปิด Google chrome update โดยมีขั้นตอนดังนี้ครับ


Copyright © 2019 - 2025 thiti.dev |  v1.56.0 |  Privacy policy | 

Build with ❤️ and Astro.

Github profile   Linkedin profile   Instagram   X profile   Nostr   Youtube channel   Telegram   Email contact   วงแหวนเว็บ