验证输入密码解锁字段
本帖最后由 bj_zm 于 2023-12-14 12:57 编辑效果:
Public Sub ButtunClick(sender As Object, e As SpreadsheetGear.Windows.Controls.ShapeActionEventArgs)
If e.Shape.Name = "Button 1" Then
'填写符合条件后执行的代码
Dim W As New C1Window, Childs As New Grid,TB As New TextBlock, PassBox As New PasswordBox, OKButton As New Button
'内部控件
TB.Text = "请输入密码:"
TB.Margin = New Thickness(50, 40, 0, 0)
Childs.Children.Add(TB)'向窗口添加文字控件
PassBox.Width = 300
PassBox.Height = 28
PassBox.VerticalContentAlignment = VerticalAlignment.Center
PassBox.VerticalAlignment = VerticalAlignment.Top
PassBox.Margin = New Thickness(0, 60, 0, 0)
Childs.Children.Add(PassBox)'向窗口添加密码控件
OKButton.Width = 60
OKButton.Height = 28
OKButton.content = "确定"
OKButton.VerticalAlignment = VerticalAlignment.Bottom
OKButton.Margin = New Thickness(0, 0, 0, 30)
AddHandler OKButton.Click, Sub(ss, ee)
If PassBox.password <>"123" Then
C1MessageBox.Show("密码错误!", "提示", OK, C1MessageBoxIcon.Warning)
Return
End If
'解锁单元格
ev.GetLock
ev.ActiveWorksheet.ProtectContents = False
range("C4").Locked = False
ev.ActiveWorksheet.ProtectContents = True
ev.ReleaseLock
'关闭窗口
W.Close()
End Sub
Childs.Children.Add(OKButton)'向窗口添加按钮控件
'窗体设置
W.Style = CType(Application.Current.Resources("C1WindowStyle"), Style)'风格
W.Height = 200'高
W.Width = 400'宽
W.Header = "验证密码"'标题
W.Content = Childs
W.ShowMaximizeButton = False'最大化
W.ShowMinimizeButton = False'最小化
W.IsResizable = False'调整尺寸
W.CenterOnScreen()'居中
W.ShowModal()'显示
End If
End Sub'按钮/标签点击事件
页:
[1]