XAML代码
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<TextBox Name="txtName" Height="30" />
<Button Click="Button_Click_1" Height="30" Content="添加" />
</StackPanel>
</Grid>
</Window>
C#代码
namespace WpfApplication1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
//使用Dlllmport 需要引用 using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern int MessageBoxTimeoutA(IntPtr hWnd, string msg, string Caps, int type, int Id, int time);
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(txtName.Text))
{
//错误提示框,定时自动关闭。
MessageBoxTimeoutA((IntPtr)0, "请输入商品名称!!!!!!", "提示框", 0, 0, 1000);
return;
}
}
}
}