<window x:Name="closing" x:Class="BBdemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/bled/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BBdemo"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Closing="closing_Closing">
<Grid>
<Grid.Background>
<ImageBrush>
</Grid.Background>
<Button Name="btnl" Content="同意" HorizontalAlignment="Left"
Margin="168,326,0,0" VerticalAlignment="Top" Width="93" Height="42"
Click="Button_Click"
/>
<Label Name="lab1" Content="表白信" HorizontalAlignment="Left"
Margin="33,44,0,0"
VerticalAlignment="Top" Height="59" Width="129" FontSize="36" FontStyle="Italic"
/>
<Label Name="lab2" Content="你愿意做我女朋友么? 
	"
HorizontalAlignment="Left" Height="60" Margin="493,200,0,0"
VerticalAlignment="Top"
width="281" FontSize="36"/>
<Button Name="btn3" Visibility="Hidden" Content="退出" HorizontalAlignment="left"
Height="42" Margin="326,326,0,0" VerticalAlignment="Top" Width="90"
Click="Button_Click_1"/>
<Image Margin="206,10,316,6,109" Source="biaobai.png" Stretch="Fill">
<Button Name="btn2" Content="不同意" HorizontalAlignment="Left"
Margin="493,326,0,0" VerticalAlignment="Top" Width="93" Height="42"
MouseEnter="Button_MouseEnter"/>
</Grid>
/window>
using System;
using System Collections.Generic;
using System Linq;
using System Text;
using System Threading Tasks;
using System Windows;
using System Windows.Controls;
using System Windows.Data;
using System Windows.Documents;
using System Windows.Input;
using System Windows.Media;
using System Windows.Media.Imaging;
using System Windows.Navigation ;
using System Windows.Shapes;
namespace BBdemo
{
public partial class MainWindow:Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_MouseEnter(object,sender,MouseEventArgs e)
{
Random rd=new Random();
Button btn=sender as Button;
double maxW=this.Width;
double maxH=this.Height;
double w=btn.Width;
double h=btn.Height;
double l=rd.Next(0,(int)(maxW-w));
double t=rd.Next(0,(int)(maxH-h));
btn.Margin=new Thickness(1,t,0,0);
}
private void closing_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBox.Show("关不掉!");
e.Cancel=true;
}
private Button_Click(object sender , RoutedEventArgs e)
{
lab1.Visibility=System.Windows.Visibility.Hidden;
lab2.Content="谢谢女朋友";
btn3.Visibility=System.Windows.Visibility.Visible;
btn1.Visibility=System.Windows.Visibility.Hidden;
btn2.Visibility=System.Windows.Visibility.Hidden;
}
private void Button_Click_1(object sender , RoutedEventArgs e )
{
System.Environment.Exit(0);
}
}
}
在网上抄了一个让人虎躯一震的代码。。。谁能教教我怎么运行wpf的代码。。。。。。(侵删)
最新推荐文章于 2022-06-02 14:00:04 发布