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

การใช้งาน keyof type operator ใน TypeScript

สวัสดีครับ ในบทความนี้เราจะมาทําความรู้จักกับ keyof type operator ใน TypeScript กันครับ

Go EP.2 ทําความรู้จักกับ Go module

สวัสดีครับ ในบทความนี้ก็เป็น EP.2 แล้วนะครับ โดยเนื้อหาจะเป็นเรื่องเกี่ยวกับ Go module ว่าคืออะไร ใช้ทําอะไร และมีประโยชน์อย่างไรสําหรับท่านใดที่ยังไม่ได้อ่าน EP.1 ท่านสามารถกลับไปอ่านก่อนได้นะครับที่นี่ Go EP.1 เริ่มต้นเรียนรู้ภาษา Go

Vue.js เริ่มต้น ตอน5 (ทําความรู้จักกับ Props)

หลังจากที่เราเรียนรู้ Component กันไปแล้ว ถ้ายังจํากันได้ภายใน Component มี Option ตัวนึงชื่อว่า Props ซึ่งมีหน้าที่ รับข้อมูลจากภายนอก Component เข้ามาใช้งานภายใน Component โดยจะรับข้อมูลผ่านทาง Attribute การใช้งาน Props สามารถใช้งานได้หลายรูปแบบ เราจะมาเรียนรู้ไปทีละแบบนะครับ


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

Build with ❤️ and Astro.

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