问题描述
我创建了一个自定义 CheckBox 控件并将其编译为 .dll。当我尝试将控件添加到表单时,出现“Type Expected”错误。
Public Class CustomCheckBox
Inherits UserControl
Public Sub New()
InitializeComponent()
displayUnChecked()
End Sub
Public Property BoxColor As Color = Color.Red
Public Property BoxSize As Size = New Size(32,32)
Public Property Checked As Boolean = False
Public Property CheckedColor As Color = Color.Black
Public Property FillBox As Boolean = False
Public Property UncheckedColor As Color = Color.White
Private Sub Me_Click(sender As Object,e As EventArgs) Handles Me.Click
Checked = Not Checked
Me.Refresh()
End Sub
Private Sub displayChecked()
Dim g As Graphics = Me.CreateGraphics
Dim border As New Rectangle(0,BoxSize.Width,BoxSize.Height)
Dim FillArea As New Rectangle(2,2,BoxSize.Width - 2,BoxSize.Height - 2)
g.DrawRectangle(New Pen(New SolidBrush(BoxColor),3),border)
g.FillRectangle(New SolidBrush(CheckedColor),FillArea)
g.dispose()
End Sub
Private Sub displayUnChecked()
Dim g As Graphics = Me.CreateGraphics
Dim border As New Rectangle(0,border)
g.FillRectangle(New SolidBrush(UncheckedColor),FillArea)
g.dispose()
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
If Checked Then
displayChecked()
Else
displayUnChecked()
End If
End Sub
Private Function MeasureText(ByVal _text As String,_font As Font) As Size
Dim g As Graphics = Me.CreateGraphics
Return TextRenderer.MeasureText(g,_text,_font)
End Function
'required by the Windows Form Designer
' *** the usual stuff to add controls to the custom control go here ***
End Class
测试申请表的代码为:
Imports CustomCheckBox
Public Class frmTest
Private Sub frmTest_Load(sender As Object,e As EventArgs) Handles Me.Load
Dim X As New CustomCheckBox
Me.Controls.Add(X)
Me.Show()
End Sub
End Class
我在测试项目中添加了对 CustomTextBox.dll 的引用。 当我尝试编译测试项目时,我在“Dim X As New CustomCheckBox”语句中收到“Type Expected”错误。
如果我将 CustomCheckBox 类添加到测试项目而不是尝试使用 .dll,它可以正常工作。
我错过了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)