本文整理汇总了VB.NET中System.Windows.Forms.CheckBoxRenderer类的典型用法代码示例。如果您正苦于以下问题:VB.NET CheckBoxRenderer类的具体用法?VB.NET CheckBoxRenderer怎么用?VB.NET CheckBoxRenderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CheckBoxRenderer类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: New
' 导入命名空间
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.VisualStyles
Namespace CheckBoxRendererSample
Class Form1
Inherits Form
Public Sub New()
Dim CheckBox1 As New CustomCheckBox()
Controls.Add(CheckBox1)
If Application.RenderWithVisualStyles Then
Me.Text = "Visual Styles Enabled"
Else
Me.Text = "Visual Styles Disabled"
End If
End Sub
<STAThread()> _
Shared Sub Main()
' If you do not call EnableVisualStyles below, then
' CheckBoxRenderer.DrawCheckBox automatically detects
' this and draws the check box without visual styles.
Application.EnableVisualStyles()
Application.Run(New Form1())
End Sub
End Class
Public Class CustomCheckBox
Inherits Control
Private textRectangleValue As New Rectangle()
Private clickedLocationValue As New Point()
Private clicked As Boolean = False
Private state As CheckBoxState = CheckBoxState.UncheckedNormal
Public Sub New()
With Me
.Location = New Point(50, 50)
.Size = New Size(100, 20)
.Text = "Click here"
.Font = SystemFonts.IconTitleFont
End With
End Sub
' Calculate the text bounds, exluding the check box.
Public ReadOnly Property TextRectangle() As Rectangle
Get
Using g As Graphics = Me.CreateGraphics()
With textRectangleValue
.X = Me.ClientRectangle.X + _
CheckBoxRenderer.GetGlyphSize(g, _
CheckBoxState.UncheckedNormal).Width
.Y = Me.ClientRectangle.Y
.Width = Me.ClientRectangle.Width - _
CheckBoxRenderer.GetGlyphSize(g, _
CheckBoxState.UncheckedNormal).Width
.Height = Me.ClientRectangle.Height
End With
End Using
Return textRectangleValue
End Get
End Property
' Draw the check box in the current state.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
CheckBoxRenderer.DrawCheckBox(e.Graphics, _
Me.ClientRectangle.Location, TextRectangle, Me.Text, _
Me.Font, TextFormatFlags.HorizontalCenter, _
clicked, state)
End Sub
' Draw the check box in the checked or unchecked state, alternately.
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
MyBase.OnMouseDown(e)
If Not clicked Then
With Me
.clicked = True
.Text = "Clicked!"
.state = CheckBoxState.CheckedPressed
End With
Invalidate()
Else
With Me
.clicked = False
.Text = "Click here"
.state = CheckBoxState.UncheckedNormal
End With
Invalidate()
End If
End Sub
' Draw the check box in the hot state.
Protected Overrides Sub OnMouseHover(ByVal e As EventArgs)
MyBase.OnMouseHover(e)
If clicked Then
state = CheckBoxState.CheckedHot
Else
state = CheckBoxState.UncheckedHot
End If
Invalidate()
End Sub
' Draw the check box in the hot state.
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
MyBase.OnMouseUp(e)
Me.OnMouseHover(e)
End Sub
' Draw the check box in the unpressed state.
Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
MyBase.OnMouseLeave(e)
If clicked Then
state = CheckBoxState.CheckedNormal
Else
state = CheckBoxState.UncheckedNormal
End If
Invalidate()
End Sub
End Class
End Namespace
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:126,代码来源:CheckBoxRenderer
注:本文中的System.Windows.Forms.CheckBoxRenderer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论