2010-08-20 5 views
4

사용자 지정 글꼴이있는 툴팁이 필요합니다.변경 도구 설명 글꼴

다음 코드가 있는데이 방법은 작동하지만 툴팁 크기가 텍스트에 맞지 않습니다.

어디서 오류가 있습니까? 합니다 (MSDN 페이지에서)

Public Class KeolisTooltip 
    Inherits ToolTip 

    Sub New() 
    MyBase.New() 
    Me.OwnerDraw = True 
    AddHandler Me.Draw, AddressOf OnDraw 
    End Sub 

    Private _Font As Font 
    Public Property Font() As Font 
    Get 
     Return _Font 
    End Get 
    Set(ByVal value As Font) 
     _Font = value 
    End Set 
    End Property 

    Public Sub New(ByVal Cont As System.ComponentModel.IContainer) 
    MyBase.New(Cont) 
    Me.OwnerDraw = True 
    AddHandler Me.Draw, AddressOf OnDraw 
    End Sub 


    Private Sub OnDraw(ByVal sender As Object, ByVal e As DrawToolTipEventArgs) 
    Dim newArgs As DrawToolTipEventArgs 

    If _Font Is Nothing Then 
     newArgs = e 
    Else 
     Dim newSize As Size = Size.Round(e.Graphics.MeasureString(e.ToolTipText, Me._Font)) 
     Dim newBounds As New Rectangle(e.Bounds.Location, newSize) 

     newArgs = New DrawToolTipEventArgs(_ 
     e.Graphics, _ 
     e.AssociatedWindow, _ 
     e.AssociatedControl, _ 
     newBounds, _ 
     e.ToolTipText, _ 
     Me.BackColor, _ 
     Me.ForeColor, _ 
     Me._Font) 
    End If 

    newArgs.DrawBackground() 
    newArgs.DrawBorder() 
    newArgs.DrawText() 
    End Sub 

End Class 
+0

실제로 글꼴을 인스턴스화하는 위치가 표시되지 않습니다. – JustBoo

+0

@JustBoo : 코드에서 "_Font가 Nothing 일 경우" – serhio

답변

2

Size.Round

가까운 정수 값으로 SizeF 구조체의 값을 반올림하여 공간 구조에 지정된 SizeF 구조 변환.

(필자의 강조).

e.Graphics.MeasureString(e.ToolTipText, Me._Font) 

23.4 및 42.1 (말) 그 후에 23으로 반올림한다, 42의 값을 생성하는 경우

따라서 각각하므로 툴팁 약간 너무 작을 것이다.

+0

sow, 어떤 해결책을 제안합니까? – serhio

+0

@serhio - 다음 정수로 올림해야합니다 (또는 조금 더 패딩을 추가 할 필요가 있습니다). – ChrisF

0

OnDraw 이벤트 외에도 OnResize 이벤트에 크기 조정 논리를 추가 할 수 있습니까? 나는 그 사건에 대한 올바른 가치를 얻을 것이라고 생각합니다. 시도해보고 작동하는지 확인하십시오.