2011-08-26 66 views
0

我想繪製多行字符串,並且我想知道有多少行給定的字符串將採取。 我正在使用以下方法。Graphics.drawString在vb.net

e.Graphics.DrawString(msg.msgBody, e.Font, New SolidBrush(Color.Black), RectangleF.op_Implicit(newRect)) 

我知道給定字符串多少大小採取通過計算

Dim siz As SizeF = e.Graphics.MeasureString(msg.msgBody, ListBox1.Font, e.ItemWidth) 

有什麼辦法通過傳遞矩形就可以計算出給定的字符串將採取的行數?

感謝

+0

您是否在Paint事件過程中直接將字符串繪製到窗體上? – jonsca

回答

0

在​​快速瀏覽發現一個返回字符串中的文本行數爲ByRef參數:

Public Function MeasureString (_ 
    text As String, _ 
    font As Font, _ 
    layoutArea As SizeF, _ 
    stringFormat As StringFormat, _ 
    <OutAttribute> ByRef charactersFitted As Integer, _ 
    <OutAttribute> ByRef linesFilled As Integer _ 
) As SizeF 

直接鏈接的文檔,以特定的過載能被發現here,完整的工作示例代碼。