Me.ParentForm.AcceptButton使用继承的控件导致设计时错误 [英] Me.ParentForm.AcceptButton causing design time error with an inherited control

查看:73
本文介绍了Me.ParentForm.AcceptButton使用继承的控件导致设计时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是带有两个按钮的继承的winforms控件.

在设计期间,代码"Me.ParentForm.AcceptButton"错误.
我尝试了DesignerSerializationVisibility标记以及LicenseUsageMode,但没有运气,以防止在打开继承了以下控件的用户控件时运行它.如何防止错误?

Below is a inherited winforms control with two buttons.

The code, ''Me.ParentForm.AcceptButton'' errors during design time.
I''ve tried the DesignerSerializationVisibility tag as well as the LicenseUsageMode with no luck to prevent it from running when opening a user control that is inherits the control below. How do I prevent the errors?

Public Class CalculationPanelBase

	<System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)> _
	Private Sub CalculationPanelBase_Load(sender As Object, e As EventArgs) Handles MyBase.Load
		''TODO:  Uncomment out during runtime to have the default button enabled
		If Not System.ComponentModel.LicenseManager.UsageMode.Equals(System.ComponentModel.LicenseUsageMode.Designtime) Then
			Me.ParentForm.AcceptButton = Calculate
		End If
	End Sub
	Protected Friend Overridable Sub Calculate_Click(sender As Object, e As EventArgs) Handles Calculate.Click
	End Sub
	Protected Friend Overridable Sub Reset_Click(sender As Object, e As EventArgs) Handles Reset.Click
	End Sub
	Public Overloads WriteOnly Property Visible As Boolean
		Set(value As Boolean)
			MyBase.Visible = value
		End Set
	End Property
End Class

推荐答案

经过更多研究后,我发现这是以下解决方法的普遍问题.基本上,请避免在基类中包含任何handle子句.
After a bit more research, I found this is a prevalent issue with the work-around below. Basically, avoid having any handles clauses from your base class.
Public Class CalculationPanelBase
  Private Sub CalculationPanelBase_Load(sender As Object, e As EventArgs) Handles MyBase.Load
		ParentForm.AcceptButton = CalculateMe
	End Sub
	Protected Friend Sub Calculate_Click(sender As Object, e As EventArgs) Handles CalculateMe.Click
		Calculate(sender, e)
	End Sub
	Protected Friend Overridable Sub Calculate(sender As Object, e As EventArgs)
	End Sub
	Protected Friend Sub Reset_Click(sender As Object, e As EventArgs) Handles ResetMe.Click
		Reset(sender, e)
	End Sub
	Protected Friend Overridable Sub Reset(sender As Object, e As EventArgs)
	End Sub
	Public Overloads WriteOnly Property Visible As Boolean
		Set(value As Boolean)
			MyBase.Visible = value
		End Set
	End Property
End Class


这篇关于Me.ParentForm.AcceptButton使用继承的控件导致设计时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆