黑马程序员技术交流社区
标题:
提示框
[打印本页]
作者:
马林雷
时间:
2014-6-10 10:32
标题:
提示框
1副窗口: Window x:Class="提示框.inputWindow"
xmlns="htt://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="htt://schemas.microsoft.com/winfx/2006/xaml"
Title="inputWindow" Height="200" Width="300"
WindowStartupLocation="CenterScreen" Loaded="Window_Loaded_1">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox Name="txtBox" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Margin="15px" Text=""></TextBox>
<Button Grid.Row="2" Margin="10px" Content="确定" Click="Button_Click_1"></Button>
<Button Grid.Row="2" Grid.Column="1" Margin="10px" Content="取消" Click="Button_Click_2"></Button>
<Button Grid.Row="2" Grid.Column="2" Margin="10px" Content="重试" Click="Button_Click_3"></Button>
</Grid>
</Grid>
</Window>
2副窗口事件属性: public partial class inputWindow : Window
{
public int? i { set; get; }//程序返回到主窗口值
public string txtOut { get; set; }
enum clk {back,No,retry,Ok }
clk pipei = new clk();
public inputWindow()
{
InitializeComponent();
}
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
txtBox.Text= txtOut;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
pipei = clk.Ok;
i = (int)pipei;
Close();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
pipei = clk.No;
i = (int)pipei;
Close();
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
pipei = clk.retry;
i = (int)pipei;
Close();
}
3主窗口: <Grid>
<Button x:Name="btnBox" Content="显示input" VerticalAlignment="Center" Height="50" RenderTransformOrigin="1.115,0.417" Margin="402,167,29,103" Click="btnBox_Click"/>
<TextBox x:Name="txtBox" Text="" HorizontalAlignment="Left" Height="50" Margin="212,90,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="135" RenderTransformOrigin="0.5,-0.522"/>
<Label HorizontalAlignment="Left" Margin="27,90,0,0" VerticalAlignment="top" Height="50" Width="145">
<Label VerticalAlignment="Center" HorizontalAlignment="Center" Content="请设置您的窗口标题:"></Label>
</Label>
<Label HorizontalAlignment="Left" Margin="27,167,0,0" VerticalAlignment="top" Height="50" Width="145">
<Label VerticalAlignment="Center" HorizontalAlignment="Center" Content="请输入您要显示内容:" >
</Label>
</Label>
<TextBox x:Name="txtIpt" HorizontalAlignment="Left" Height="50" Margin="212,167,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="135"/>
</Grid>
4主窗口事件属性: private void btnBox_Click(object sender, RoutedEventArgs e)
{
string txt = txtBox.Text.ToString();
string txtinput = txtIpt.Text.ToString();
inputWindow input = new inputWindow();
if (txt == "")
{
input.Title = "您没有设置标题";
}
else
{
input.Title = txt;
}
if (txtinput == "")
{
input.txtOut = "您没有输入内容";
}
else
{
input.txtOut = txtinput;
}
input.ShowDialog();
if (input.i == 0)
{
MessageBox.Show("您没有点击按钮!");
}
else if (input.i == 1)
{
MessageBox.Show("您点击了取消按钮!");
}
else if (input.i == 2)
{
MessageBox.Show("您点击了重试按钮!");
}
else if (input.i == 3)
{
MessageBox.Show("您点击了确定按钮!");
}
}
作者:
点石fanfl
时间:
2014-6-14 23:20
赞一个,顶起来
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2