如何使用自动调整的字体创建自定义窗口磁贴 [英] how to create custom windows tile with autosized font on it
本文介绍了如何使用自动调整的字体创建自定义窗口磁贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Windows磁贴将通过接受磁贴大小来调整字体大小或文本。也可以通过接受矩形区域来调整字体大小。我的主要意图是,当字体大小变长时,不要获得truncate font @ windows tile。而我想要的是自动最小化或使瓷砖形状自动变为矩形,以使字体大小适合瓷砖大小。我一直在寻找解决方案,但我无法做到。
请帮帮我吧!!!
问候,
Windows tile will adjust the font size or text by accepting tile size. also adjust the font size By accepting a rectangular region. the main intention of mine is that ,not to get truncate font @ windows tile when the font size got longer. instead what I want is to auto minimize or make the tile shape to rectangle automaticaly inorder to make the font size to fit with tile size. i have been searching the solution but i cant make it.
please help me guy's!!!
with a regards,
推荐答案
使用System.Windows.Forms.TextRenderer.MeassureString方法可以很容易地完成。
你给它你的文字和你的字体,它给你一个大小。
现在你必须建立一个方法,比较(通过尝试)哪个最大字体大小匹配。
你必须增加或减少try-fontsize,直到TextRenderer-Size与你的Control-Size最匹配。
This could be done very easy with the System.Windows.Forms.TextRenderer.MeassureString-method.
You give it your text and your font and it gives you a size.
Now you have to build a method, which compares (by trying) which maximum fontsize would match.
You have to increase or decrease the try-fontsize until the TextRenderer-Size matches best to your Control-Size.
Function GetFontSizeMatch(ByVal myText As String, ByVal myFont As Font, ByVal mySize As Size) As Single
If Trim(myText).Length <= 0 Then myText = "X"
Dim currentSize As Single = CSng(myFont.Size)
Dim workFont As Font = New Font(myFont.Name, currentSize, myFont.Style, myFont.Unit)
Dim Nutzbreite As Single = CSng(mySize.Width)
Dim Nutzhöhe As Single = CSng(mySize.Height)
Dim myTextSize As SizeF
If (Nutzbreite >= 1) AndAlso (Nutzhöhe >= 1) Then
Do
currentSize += 4.0 : If currentSize > 50 Then Exit Do
workFont = New Font(workFont.Name, currentSize, workFont.Style, workFont.Unit)
myTextSize = TextRenderer.MeasureText(myText, workFont)
Loop Until (myTextSize.Width > Nutzbreite) Or (myTextSize.Height > Nutzhöhe)
Do
currentSize -= 0.5 : If currentSize < 5 Then Exit Do
workFont = New Font(workFont.Name, currentSize, workFont.Style, workFont.Unit)
myTextSize = TextRenderer.MeasureText(myText, workFont)
Loop Until (myTextSize.Width <= Nutzbreite) AndAlso (myTextSize.Height <= Nutzhöhe)
End If
Return currentSize
End Function
这篇关于如何使用自动调整的字体创建自定义窗口磁贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文