Здравствуйте
Не уж-то не возможно ToolTIp-у fontname и fontsize назначить
Спасибо
Multiline = True
Денис писал(а):
- Код: Выделить всё
Multiline = True
Public Class MyTooltip
Inherits ToolTip
Sub New()
MyBase.New()
Me.OwnerDraw = True
AddHandler Me.Draw, AddressOf OnDraw
End Sub
Public Sub New(ByVal Cont As System.ComponentModel.IContainer)
MyBase.New(Cont)
Me.OwnerDraw = True
AddHandler Me.Draw, AddressOf OnDraw
End Sub
Private f As New Font("Arial", 16, FontStyle.Bold, GraphicsUnit.Pixel)
Private sf As New StringFormat With {.FormatFlags = StringFormatFlags.NoWrap}
Private Sub OnDraw(ByVal sender As Object, ByVal e As DrawToolTipEventArgs)
Using b As New SolidBrush(Me.ForeColor)
Dim newArgs As DrawToolTipEventArgs = New DrawToolTipEventArgs( _
e.Graphics, _
e.AssociatedWindow, _
e.AssociatedControl, _
e.Bounds, _
e.ToolTipText, _
Me.BackColor, _
Me.ForeColor, _
f)
newArgs.DrawBackground()
newArgs.DrawBorder()
e.Graphics.DrawString(newArgs.ToolTipText, newArgs.Font, b, newArgs.Bounds, sf)
End Using
End Sub
Private Sub MyTooltip_Popup(ByVal sender As Object, ByVal e As System.Windows.Forms.PopupEventArgs) Handles Me.Popup
Using img As New Bitmap(1, 1), g As Graphics = Graphics.FromImage(img)
Dim s As SizeF = g.MeasureString(MyBase.GetToolTip(e.AssociatedControl), f, New SizeF(500, Single.PositiveInfinity), sf, Nothing, Nothing)
s.Width += 1
e.ToolTipSize = S2S(s)
End Using
End Sub
Private Function S2S(ByVal s As SizeF) As Size
Return New Size(s.Width, s.Height)
End Function
Private Function S2S(ByVal s As Size) As SizeF
Return New Size(s.Width, s.Height)
End Function
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
If disposing Then
sf.Dispose()
f.Dispose()
End If
End Sub
End Class
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Class ToolTipClass
Inherits Form
Shared Sub Main()
Application.Run(New ToolTipClass)
End Sub
Sub New
Dim Button1 As New Button
Button1.Parent = Me
Button1.Size = New Size (100, 50)
Button1.Location = New Point((Me.ClientSize.Width - 100) / 2, (Me.ClientSize.Height - 50) / 2)
Button1.Text = "Button1"
Dim ToolTip1 As New ToolTip
ToolTip1.SetToolTip (Button1, "Проверка всплывающей подсказки")
ToolTip1.Active = True
AddHandler ToolTip1.Popup, AddressOf ToolTip1_Popup
End Sub
Private Sub ToolTip1_Popup(ByVal Obj As Object, ByVal Pea As PopupEventArgs)
Dim g As Graphics = Me.CreateGraphics
End Sub
End Class
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 13