level 13
Nukepayload2
楼主
一楼不喂熊,直接上教程和链接!
这篇文章我首次发布是在
http://www.cnblogs.com/Nukepayload2/p/uwp_libfuncs_remake_vbnet.html
在博客可以看代码的解释。
使用MsgBox前,把这段代码放到某个模块里面
Public Async Function MsgBoxAsync(Prompt$, HasCancel As Boolean, Title$, Optional OK$ = "确定", Optional Cancel$ = "取消") As Task(Of Boolean?)
Dim dlg As New MessageDialog(Prompt, Title)
Dim Result As Boolean?
If HasCancel Then
Dim msg As New MessageDialog(Prompt, Title)
msg.Commands.Add(New UICommand(OK, Sub(command) Result = True))
msg.Commands.Add(New UICommand(Cancel, Sub(command) Result = False))
msg.DefaultCommandIndex = 0
msg.CancelCommandIndex = 1
Dim tsk = msg.ShowAsync
Await tsk
Return Result
Else
Await New MessageDialog(Prompt, Title).ShowAsync
Return True
End If
End Function
这是个精简的MsgBox,可以单按钮和双按钮,能修改按钮上的文字。
用法示例:

Await MsgBoxAsync("未找到VeteranSpeed的符号", False, "未找到")
InputBox稍微麻烦一点。先新建xaml对话框
<ContentDialog
x:Class="Nukepayload2.VisualBasicExtensions.UWP.InputBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<ContentDialog.Content>
<Grid MinWidth="100" MinHeight="100">
<Grid.RowDefinitions>
<RowDefinition Height="13*"/>
<RowDefinition Height="7*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="71*"/>
<ColumnDefinition Width="19*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="TxtPrompt"></TextBlock>
<TextBox x:Name="TxtOutput" Grid.Row="1"></TextBox>
<Button Grid.Row="1" Grid.Column="1" Click="BtnOk_Click">确定</Button>
</Grid>
</ContentDialog.Content>
</ContentDialog>
然后写逻辑代码
Public NotInheritable Class InputBox
Inherits ContentDialog
Public Overloads Async Function ShowAsync(Prompt As String, Title As String, Optional InputScope As InputScopeNameValue = InputScopeNameValue.Text) As Task(Of String)
Me.Title = Title
TxtPrompt.Text = Prompt
TxtOutput.Text = ""
TxtOutput.InputScope = New InputScope
TxtOutput.InputScope.Names.Add(New InputScopeName(InputScope))
Await ShowAsync()
Return TxtOutput.Text
End Function
Private Sub BtnOk_Click(sender As Object, e As RoutedEventArgs)
Hide()
End Sub
End Class
在模块里把它变成静态的
Dim inputbox As New InputBox()
Public Async Function InputBoxAsync(Prompt$, Title$, Optional InputScope As InputScopeNameValue = InputScopeNameValue.Text) As Task(Of String)
Return Await inputbox.ShowAsync(Prompt, Title, InputScope)
End Function
一个能够显示帮助文本,能设置虚拟键盘的精简版InputBox诞生了!
用法示例:
Dim YourName=Await InputBox("你叫什么名字?", "输入姓名")
我的博客里还写了StrConv和Rnd怎么实现。想用它们的话就进博客看代码吧。
---贴吧极速版 For UWP
2016年03月07日 04点03分
1
这篇文章我首次发布是在
http://www.cnblogs.com/Nukepayload2/p/uwp_libfuncs_remake_vbnet.html
在博客可以看代码的解释。
使用MsgBox前,把这段代码放到某个模块里面
Public Async Function MsgBoxAsync(Prompt$, HasCancel As Boolean, Title$, Optional OK$ = "确定", Optional Cancel$ = "取消") As Task(Of Boolean?)
Dim dlg As New MessageDialog(Prompt, Title)
Dim Result As Boolean?
If HasCancel Then
Dim msg As New MessageDialog(Prompt, Title)
msg.Commands.Add(New UICommand(OK, Sub(command) Result = True))
msg.Commands.Add(New UICommand(Cancel, Sub(command) Result = False))
msg.DefaultCommandIndex = 0
msg.CancelCommandIndex = 1
Dim tsk = msg.ShowAsync
Await tsk
Return Result
Else
Await New MessageDialog(Prompt, Title).ShowAsync
Return True
End If
End Function
这是个精简的MsgBox,可以单按钮和双按钮,能修改按钮上的文字。
用法示例:

Await MsgBoxAsync("未找到VeteranSpeed的符号", False, "未找到")InputBox稍微麻烦一点。先新建xaml对话框
<ContentDialog
x:Class="Nukepayload2.VisualBasicExtensions.UWP.InputBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<ContentDialog.Content>
<Grid MinWidth="100" MinHeight="100">
<Grid.RowDefinitions>
<RowDefinition Height="13*"/>
<RowDefinition Height="7*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="71*"/>
<ColumnDefinition Width="19*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="TxtPrompt"></TextBlock>
<TextBox x:Name="TxtOutput" Grid.Row="1"></TextBox>
<Button Grid.Row="1" Grid.Column="1" Click="BtnOk_Click">确定</Button>
</Grid>
</ContentDialog.Content>
</ContentDialog>
然后写逻辑代码
Public NotInheritable Class InputBox
Inherits ContentDialog
Public Overloads Async Function ShowAsync(Prompt As String, Title As String, Optional InputScope As InputScopeNameValue = InputScopeNameValue.Text) As Task(Of String)
Me.Title = Title
TxtPrompt.Text = Prompt
TxtOutput.Text = ""
TxtOutput.InputScope = New InputScope
TxtOutput.InputScope.Names.Add(New InputScopeName(InputScope))
Await ShowAsync()
Return TxtOutput.Text
End Function
Private Sub BtnOk_Click(sender As Object, e As RoutedEventArgs)
Hide()
End Sub
End Class
在模块里把它变成静态的
Dim inputbox As New InputBox()
Public Async Function InputBoxAsync(Prompt$, Title$, Optional InputScope As InputScopeNameValue = InputScopeNameValue.Text) As Task(Of String)
Return Await inputbox.ShowAsync(Prompt, Title, InputScope)
End Function
一个能够显示帮助文本,能设置虚拟键盘的精简版InputBox诞生了!
用法示例:
Dim YourName=Await InputBox("你叫什么名字?", "输入姓名")
我的博客里还写了StrConv和Rnd怎么实现。想用它们的话就进博客看代码吧。
---贴吧极速版 For UWP