我是 VB.net 的新手,所以请理解。我有一个MainWindow, Frame1, Frame2 (AdFrame1), Page1.
MainWindow
Page1
从Frame1
启动加载。在MainWindow.vb class
我有一个Frame2
可见的公共子。
我将如何共享该公共子,以便我可以使用 Page_Mouseup 事件来显示 Frame2 (AdFrame1)
我尝试了 Public Shared Sub,但出现此错误:“如果没有类的显式实例,则无法从共享方法或共享成员初始化程序中引用类的实例成员”
MainWindow.vb 中的代码:
Private Sub MainWindow2_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseUp
AdClick()
End Sub
Public Sub AdClick()
Try
clicks += 1
If clicks >= 10 Then
'After 5 seconds Adframe CloseLink and TextBlock1 will hide.
AdFrame1.Visibility = Windows.Visibility.Visible
CloseMainButton.Visibility = Windows.Visibility.Visible
InitializeComponent()
dpTimer = New DispatcherTimer
dpTimer.Interval = TimeSpan.FromMilliseconds(10000)
AddHandler dpTimer.Tick, AddressOf TickMe
dpTimer.Start()
clicks = 0
End If
Catch ex As Exception
MessageBox.Show("Oops! Error X0123A1. Please contact us with error ASAP!", "Error!", MessageBoxButton.OK)
End Try
End Sub
'After 10 sesonds auto close
Private Sub TickMe()
AdFrame1.Visibility = Windows.Visibility.Hidden
End Sub
代码页1.vb
Private Sub Page1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseUp
AdClick() (inaccessible due to protection)
End Sub
那么如何与 Page1 共享 AdClick()