SDK里面的示例也有问题?

fulcrumtian 2005-12-22 05:24:31
大家看看sdk里面的一个示例,好像我这边运行的有点问题
Microsoft.NET/SDK/v1.1/QuickStart/winforms/samples/writingcontrols/simplecontrol/vb

hostapp.vb 里面的
simpleControl1_DrawingModeChanged事件没有被触发

我才开始学vb.net,看不出有什么问题,高手帮忙分析一下啊!
最好告诉我为什么在simplecontrol.vb里面定义的事件
到hostapp.vb里面就不能捕捉到了。示例代码的问题在什么地方?
...全文
82 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fulcrumtian 2005-12-27
  • 打赏
  • 举报
回复
'simplecontorl.vb 里面的代码
Imports System
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Drawing
Namespace Microsoft.Samples.WinForms.VB.SimpleControl
<DefaultProperty("DrawingMode"), DefaultEvent("DrawingModeChanged")> _
Public Class SimpleControl
Inherits System.Windows.Forms.Control
Private Sub InitializeComponent()
End Sub
Private myDrawingMode As DrawingModeStyle
Private myOnDrawingModeChanged As EventHandler
'*** Constructors
Public Sub New()
MyBase.New()
'Initialise drawingMode
myDrawingMode = DrawingModeStyle.Happy
'Initialise BackColor and ForeColor based on DrawingMode
SetColors()
'Make sure the control repaints as it is resized
SetStyle(ControlStyles.ResizeRedraw, True)
End Sub
'*** Properties
'Remove the BackColor property from the properties window
<Browsable(False)> Public Overrides Property BackColor() As Color
Get
Return MyBase.BackColor
End Get
Set(ByVal Value As Color)
'No Action
End Set
End Property
'DrawingMode - controls how the control paints
<Category("Appearance"), _
Description("Controls how the control paints"), _
DefaultValue(DrawingModeStyle.Happy), _
Bindable(True)> _
Public Property _
DrawingMode() As DrawingModeStyle
Get
Return myDrawingMode
End Get
Set(ByVal Value As DrawingModeStyle)
myDrawingMode = Value
'Set BackColor and ForeColor based on DrawingMode
SetColors()
'Raise property changed event for DrawingMode
OnDrawingModeChanged(EventArgs.Empty)
End Set
End Property
'Remove the ForeColor property from the properties window
<Browsable(False)> Public Overrides Property ForeColor() As Color
Get
Return MyBase.ForeColor
End Get
Set(ByVal Value As Color)
'No Action
End Set
End Property
'*** Events
'Handle the paint event
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
e.Graphics.FillRectangle(New SolidBrush(BackColor), ClientRectangle)
Dim textSize As SizeF = e.Graphics.MeasureString(Me.Text, Font)
Dim xPos As Single = CSng((ClientRectangle.Width / 2) - (textSize.Width / 2))
Dim yPos As Single = CSng((ClientRectangle.Height / 2) - (textSize.Height / 2))
e.Graphics.DrawString(Me.Text, Font, New SolidBrush(ForeColor), xPos, yPos)
End Sub
Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
MyBase.OnTextChanged(e)
Invalidate()
End Sub
'Catch property changed event for DrawingMode to fire DrawingMoe changed
'and repaint the control
Protected Overridable Sub OnDrawingModeChanged(ByVal E As EventArgs)
'Set BackColor and ForeColor based on DrawingMode
SetColors()
Invalidate()
If Not (myOnDrawingModeChanged Is Nothing) Then myOnDrawingModeChanged.Invoke(Me, E)
End Sub
'DrawingModeChanged Event
<Description("Raised when the DrawingMode changes")> _
Public Event _
DrawingModeChanged(ByVal sender As Object, ByVal ev As EventArgs) 'As EventHandler
'Set the ForeColor and BackColor based on the value of DrawingMode
Private Sub SetColors()
Select Case myDrawingMode
Case DrawingModeStyle.Happy
MyBase.BackColor = Color.Yellow
MyBase.ForeColor = Color.Green
Case DrawingModeStyle.Sad
MyBase.BackColor = Color.LightSlateGray
MyBase.ForeColor = Color.White
Case DrawingModeStyle.Angry
MyBase.BackColor = Color.Red
MyBase.ForeColor = Color.Teal
Case Else
MyBase.BackColor = Color.Black
MyBase.ForeColor = Color.White
End Select
End Sub
End Class
End Namespace
fulcrumtian 2005-12-27
  • 打赏
  • 举报
回复
算了,来个人接分,估计是分少了
fulcrumtian 2005-12-23
  • 打赏
  • 举报
回复
郁闷,怎么没人看啊

我顶

16,549

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧