本文整理汇总了VB.NET中System.Windows.Forms.MeasureItemEventArgs.ItemHeight属性的典型用法代码示例。如果您正苦于以下问题:VB.NET MeasureItemEventArgs.ItemHeight属性的具体用法?VB.NET MeasureItemEventArgs.ItemHeight怎么用?VB.NET MeasureItemEventArgs.ItemHeight使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.MeasureItemEventArgs 的用法示例。
在下文中一共展示了MeasureItemEventArgs.ItemHeight属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Form1
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents listBox1 As System.Windows.Forms.ListBox
Private components As System.ComponentModel.Container = Nothing
Private FontSize As Single = 12.0F
'
' This sample displays a ListBox that contains a list of all the fonts
' installed on the system and draws each item in its respective font.
'
Public Sub New()
InitializeComponent()
' Populate control with the fonts installed on the system.
Dim families As FontFamily() = FontFamily.Families
Dim family As FontFamily
For Each family In families
Dim style As FontStyle = FontStyle.Regular
' Monotype Corsiva is only available in italic
If family.Name = "Monotype Corsiva" Then
style = style Or FontStyle.Italic
End If
listBox1.Items.Add(New ListBoxFontItem(New Font(family.Name, FontSize, style, GraphicsUnit.Point)))
Next family
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If (components IsNot Nothing) Then
components.Dispose()
End If
If (foreColorBrush IsNot Nothing) Then
foreColorBrush.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private Sub InitializeComponent()
Me.listBox1 = New System.Windows.Forms.ListBox()
Me.SuspendLayout()
'
' listBox1
'
Me.listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable
Me.listBox1.Location = New System.Drawing.Point(16, 48)
Me.listBox1.Name = "listBox1"
Me.listBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended
Me.listBox1.Size = New System.Drawing.Size(256, 134)
Me.listBox1.TabIndex = 0
'
' Form1
'
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.listBox1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
<STAThread()> Shared Sub Main()
Application.Run(New Form1())
End Sub
Private Sub listBox1_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles listBox1.MeasureItem
Dim font As Font = CType(listBox1.Items(e.Index), ListBoxFontItem).Font
Dim stringSize As SizeF = e.Graphics.MeasureString(font.Name, font)
' Set the height and width of the item
e.ItemHeight = CInt(stringSize.Height)
e.ItemWidth = CInt(stringSize.Width)
End Sub
' For efficiency, cache the brush used for drawing.
Private foreColorBrush As SolidBrush
Private Sub listBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles listBox1.DrawItem
Dim brush As Brush
' Create the brush using the ForeColor specified by the DrawItemEventArgs
If foreColorBrush Is Nothing Then
foreColorBrush = New SolidBrush(e.ForeColor)
Else
If Not foreColorBrush.Color.Equals(e.ForeColor) Then
' The control's ForeColor has changed, so dispose of the cached brush and
' create a new one.
foreColorBrush.Dispose()
foreColorBrush = New SolidBrush(e.ForeColor)
End If
End If
' Select the appropriate brush depending on if the item is selected.
' Since State can be a combinateion (bit-flag) of enum values, you can't use
' "==" to compare them.
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
brush = SystemBrushes.HighlightText
Else
brush = foreColorBrush
End If
' Perform the painting.
Dim font As Font = CType(listBox1.Items(e.Index), ListBoxFontItem).Font
e.DrawBackground()
e.Graphics.DrawString(font.Name, font, brush, e.Bounds.X, e.Bounds.Y)
e.DrawFocusRectangle()
End Sub
'
' A wrapper class for use with storing Fonts in a ListBox. Since ListBox uses the
' ToString() of its items for the text it displays, this class is needed to return
' the name of the font, rather than its ToString() value.
'
Public Class ListBoxFontItem
Public Font As Font
Public Sub New(ByVal f As Font)
Font = f
End Sub
Public Overrides Function ToString() As String
Return Font.Name
End Function
End Class
End Class
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:131,代码来源:MeasureItemEventArgs.ItemHeight
示例2: MainClass
' 导入命名空间
Imports System
Imports System.Drawing
Imports System.Reflection
Imports System.Windows.Forms
Imports System.IO
public class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1
Application.Run(form1)
End Sub
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code"
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
'Required by the Windows Form Designer
Private components As System.ComponentModel.Container
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Red As System.Windows.Forms.MenuItem
Friend WithEvents Green As System.Windows.Forms.MenuItem
Friend WithEvents Blue As System.Windows.Forms.MenuItem
Friend WithEvents Yellow As System.Windows.Forms.MenuItem
Friend WithEvents Black As System.Windows.Forms.MenuItem
Friend WithEvents White As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents AlignLeft As System.Windows.Forms.MenuItem
Friend WithEvents AlignCenter As System.Windows.Forms.MenuItem
Friend WithEvents AlignRight As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu()
Me.MenuItem1 = New System.Windows.Forms.MenuItem()
Me.Red = New System.Windows.Forms.MenuItem()
Me.Green = New System.Windows.Forms.MenuItem()
Me.Blue = New System.Windows.Forms.MenuItem()
Me.Yellow = New System.Windows.Forms.MenuItem()
Me.Black = New System.Windows.Forms.MenuItem()
Me.White = New System.Windows.Forms.MenuItem()
Me.MenuItem2 = New System.Windows.Forms.MenuItem()
Me.AlignLeft = New System.Windows.Forms.MenuItem()
Me.AlignCenter = New System.Windows.Forms.MenuItem()
Me.AlignRight = New System.Windows.Forms.MenuItem()
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.Red, Me.Green, Me.Blue, Me.Yellow, Me.Black, Me.White})
Me.MenuItem1.Text = "Color"
'
'Red
'
Me.Red.Index = 0
Me.Red.OwnerDraw = True
Me.Red.Text = ""
'
'Green
'
Me.Green.Index = 1
Me.Green.OwnerDraw = True
Me.Green.Text = ""
'
'Blue
'
Me.Blue.Index = 2
Me.Blue.OwnerDraw = True
Me.Blue.Text = ""
'
'Yellow
'
Me.Yellow.Index = 3
Me.Yellow.OwnerDraw = True
Me.Yellow.Text = ""
'
'Black
'
Me.Black.Index = 4
Me.Black.OwnerDraw = True
Me.Black.Text = ""
'
'White
'
Me.White.Index = 5
Me.White.OwnerDraw = True
Me.White.Text = ""
'
'MenuItem2
'
Me.MenuItem2.Index = 1
Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.AlignLeft, Me.AlignCenter, Me.AlignRight})
Me.MenuItem2.Text = "Alignment"
'
'AlignLeft
'
Me.AlignLeft.Index = 0
Me.AlignLeft.OwnerDraw = True
Me.AlignLeft.Text = "Left"
'
'AlignCenter
'
Me.AlignCenter.Index = 1
Me.AlignCenter.OwnerDraw = True
Me.AlignCenter.Text = "Center"
'
'AlignRight
'
Me.AlignRight.Index = 2
Me.AlignRight.OwnerDraw = True
Me.AlignRight.Text = "Right"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 129)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Owner-Drawn Menu"
End Sub
#End Region
Dim currentFont As Font
Private Sub Red_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Red.DrawItem
Dim R As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
e.Graphics.FillRectangle(Brushes.Red, R)
End Sub
Private Sub Red_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles Red.MeasureItem
Dim itemSize As SizeF
itemSize = New SizeF(80, 18)
e.ItemHeight = itemSize.Height
e.ItemWidth = itemSize.Width
End Sub
Private Sub Green_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles Red.MeasureItem
Dim itemSize As SizeF
itemSize = New SizeF(80, 18)
e.ItemHeight = itemSize.Height
e.ItemWidth = itemSize.Width
End Sub
Private Sub Green_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Green.DrawItem
Dim R As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
e.Graphics.FillRectangle(Brushes.Green, R)
End Sub
Private Sub Blue_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles Blue.MeasureItem
Dim itemSize As SizeF
itemSize = New SizeF(80, 18)
e.ItemHeight = itemSize.Height
e.ItemWidth = itemSize.Width
End Sub
Private Sub Blue_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Blue.DrawItem
Dim R As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
e.Graphics.FillRectangle(Brushes.Blue, R)
End Sub
Private Sub Yellow_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles Yellow.MeasureItem
Dim itemSize As SizeF
itemSize = New SizeF(80, 18)
e.ItemHeight = itemSize.Height
e.ItemWidth = itemSize.Width
End Sub
Private Sub Yellow_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Yellow.DrawItem
Dim R As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
e.Graphics.FillRectangle(Brushes.Yellow, R)
End Sub
Private Sub White_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles White.MeasureItem
Dim itemSize As SizeF
itemSize = New SizeF(80, 18)
e.ItemHeight = itemSize.Height
e.ItemWidth = itemSize.Width
End Sub
Private Sub White_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles White.DrawItem
Dim R As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
e.Graphics.FillRectangle(Brushes.White, R)
End Sub
Private Sub Black_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles Black.MeasureItem
Dim itemSize As SizeF
itemSize = New SizeF(80, 18)
e.ItemHeight = itemSize.Height
e.ItemWidth = itemSize.Width
End Sub
Private Sub Black_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Black.DrawItem
Dim R As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
e.Graphics.FillRectangle(Brushes.Black, R)
End Sub
Private Sub AlignLeft_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles AlignLeft.MeasureItem
Dim itemSize As SizeF
itemSize = New SizeF(40, 14)
e.ItemHeight = itemSize.Height
e.ItemWidth = itemSize.Width
End Sub
Private Sub AlignLeft_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles AlignLeft.DrawItem
Dim R As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
Dim strfmt As New StringFormat()
strfmt.Alignment = StringAlignment.Near
e.Graphics.DrawString("Left", Me.Font, Brushes.Black, R, strfmt)
End Sub
Private Sub AlignRight_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles AlignRight.MeasureItem
Dim itemSize As SizeF
itemSize = New SizeF(40, 14)
e.ItemHeight = itemSize.Height
e.ItemWidth = itemSize.Width
End Sub
Private Sub AlignRight_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles AlignRight.DrawItem
Dim R As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
Dim strfmt As New StringFormat()
strfmt.Alignment = StringAlignment.Far
e.Graphics.DrawString("Right", Me.Font, Brushes.Black, R, strfmt)
End Sub
Private Sub AlignCenter_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles AlignCenter.MeasureItem
Dim itemSize As SizeF
itemSize = New SizeF(40, 14)
e.ItemHeight = itemSize.Height
e.ItemWidth = itemSize.Width
End Sub
Private Sub AlignCenter_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles AlignCenter.DrawItem
Dim R As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
Dim strfmt As New StringFormat()
strfmt.Alignment = StringAlignment.Center
e.Graphics.DrawString("Center", Me.Font, Brushes.Black, R, strfmt)
End Sub
Private Sub Alignment_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlignCenter.Click, AlignLeft.Click, AlignRight.Click,Red.Click,Green.Click,Blue.Click,Yellow.Click,Black.Click,White.Click
MessageBox.Show(sender.Text)
End Sub
End Class
开发者ID:VB程序员,项目名称:System.Windows.Forms,代码行数:279,代码来源:MeasureItemEventArgs.ItemHeight
注:本文中的System.Windows.Forms.MeasureItemEventArgs.ItemHeight属性示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论