吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3815|回复: 14
收起左侧

[C&C++ 原创] WPF 仿鹅厂登录界面,带有程序打开渐显动画 C#运气修仙代码公开

[复制链接]
kololi 发表于 2023-1-12 21:35
1,没找到C# title ,所以用了这个C&C++
2.程序中部份代码来自网络
3.本次分享只是界面部份.但也写了文本框的鼠标事件判定,除了不能登录
4.环境  win10_x64 + vs2022 + .net6

上图 .图上的背景是会动的哦
2023-01-12_212059.png


想直接看运行效果的,下载这个(没有.net6也是跑不起来的) .
WpfAppUpdate.rar (65.05 KB, 下载次数: 22)

程序源码+编译好的
WpfAppUpdate.rar (855.44 KB, 下载次数: 82)


上主要代码
界面:
[XML] 纯文本查看 复制代码
<Window x:Class="WpfAppUpdate.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
       
        mc:Ignorable="d"
        WindowStartupLocation="CenterScreen" 
        WindowStyle="None"
        AllowsTransparency="True"    
        Background="Transparent"    Loaded="Window_Loaded"
        Title="运气修仙" Height="370" Width="490">
    <!-- Loaded="Window_Loaded" -->
    <Window.Resources>
        <Style x:Key="btn_close" TargetType="Button">
            <Setter Property="OverridesDefaultStyle" Value="True" />
            <Setter Property="FontFamily" Value="{StaticResource icoFont}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Name="border" BorderThickness="0" BorderBrush="{x:Null}" Background="{TemplateBinding Background}">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Opacity" Value="1" />
                                <Setter Property="Background" Value="#FF7F00"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="TextICON" TargetType="TextBlock">
            <Setter Property="FontSize" Value="24" />
            <Setter Property="FontFamily" Value="{StaticResource icoFont}" />
            <Setter Property="TextAlignment" Value="Center" />
            <Setter Property="Foreground" Value="#FFACB0AF" />
        </Style>
        <Style x:Key="MyButton" TargetType="Button">
            <Setter Property="OverridesDefaultStyle" Value="True" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Name="border" BorderThickness="0" BorderBrush="Black" Background="{TemplateBinding Background}">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Opacity" Value="1" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>



        <Style x:Key="textHint" TargetType="TextBlock">
            <Setter Property="FontSize" Value="14" />
            <Setter Property="Grid.Column" Value="1" />
            <Setter Property="Panel.ZIndex" Value="1" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Margin" Value="6 0 0 0" />
            <Setter Property="Foreground" Value="#ACB0AF" />
        </Style>


        <Style x:Key="textBox" TargetType="Control">
            <Setter Property="FontSize" Value="14" />
            <Setter Property="Grid.Column" Value="1" />
            <Setter Property="Margin" Value="10 0 0 0" />
            <Setter Property="Foreground" Value="#878787" />
            <Setter Property="BorderBrush" Value="Transparent" />
            <Setter Property="BorderThickness" Value="0" />
        </Style>

        <Style x:Key="loginButton" TargetType="{x:Type Button}">
            <Setter Property="FontSize" Value="14" />
            <Setter Property="Margin" Value="0 20 0 0" />
            <Setter Property="Width" Value="200" />
            <Setter Property="Background" Value="#FF00B2DE" />
            <Setter Property="Foreground" Value="#FDFEFE" />
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border Background="{TemplateBinding Background}" CornerRadius="25" BorderBrush="#49B7A3" Padding="15" BorderThickness="1">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#FF3CC3F5" />
                    <Setter Property="Foreground" Value="White" />
                </Trigger>
                <Trigger Property="IsMouseCaptured" Value="True">
                    <Setter Property="Background" Value="#FF09A3DC" />
                    <Setter Property="Foreground" Value="White" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Border>
        <Grid  x:Name="loginBox">
            <Grid.RowDefinitions>
                <RowDefinition Height="5*"/>
                <RowDefinition Height="50*"/>
                <RowDefinition Height="19*"/>
                <RowDefinition Height="111*"/>
            </Grid.RowDefinitions>
          
            <Grid.OpacityMask>
                <LinearGradientBrush StartPoint="0.5,1" EndPoint="0.5,0">
                    <GradientStop Color="#00000000" Offset="0"/>
                    <GradientStop Color="#00000000" Offset="1"/>
                    <GradientStop Color="#00000000" Offset="1"/>
                </LinearGradientBrush>
            </Grid.OpacityMask>
            <Grid.Triggers>
                <EventTrigger RoutedEvent="Loaded">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation From="1" To="0" Duration="0:0:0.8" Storyboard.TargetProperty="OpacityMask.(GradientBrush.GradientStops)[1].Offset"/>
                                <DoubleAnimation From="1" To="0" Duration="0:0:0.6" BeginTime="0:0:0.2" Storyboard.TargetProperty="OpacityMask.(GradientBrush.GradientStops)[2].Offset"/>
                                <ColorAnimation To="#FF000000" Duration="0" Storyboard.TargetProperty="OpacityMask.(GradientBrush.GradientStops)[2].Color"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Grid.Triggers>
    
            <Border Background="#ffffff"   CornerRadius=" 10 10 10 10" Grid.RowSpan="3" >

                <Grid >
                    <Grid  MouseDown="Border_MouseDown" >
                        <Grid Name="layout" Width="490" Height="210" Background="#19000000"  >
                            <Grid.Clip>
                                <RectangleGeometry Rect="0,0,490,210"/>
                            </Grid.Clip>
                        </Grid>
                    </Grid>

                    <Button x:Name="btn_close" ToolTip="关闭" Content="&#60146;"  FontFamily="{StaticResource icoFont}" Style="{StaticResource btn_close}" Click="btn_close_Click" BorderBrush="{x:Null}" Foreground="white" FontSize="20" Width="24" Height="24" VerticalAlignment="Top" HorizontalAlignment="Right" />

                    <Image HorizontalAlignment="Center"    VerticalAlignment="Center"  Source="/res/yunqixiuxian.png" Opacity="1" Panel.ZIndex="0" Width="228" Margin="0,28,0,0" />
                </Grid>
            </Border>
            <Border Background="#ffffff"    CornerRadius=" 0 0 10 10"   MouseDown="Border_MouseDown" Grid.Row="3">

                <StackPanel VerticalAlignment="Center" Height="188" Margin="0,16,0,0">


                    <!--<TextBlock Text="进入修仙世界"  Foreground="#878787" Style="{StaticResource NormalText}" />-->
                    <Border BorderBrush="#ACB0AF" BorderThickness="1" Margin="70,0,70,7" CornerRadius="5" Width="230">
                        <Grid Margin="7 9">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="24" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>


                            <TextBlock  Text="" Style="{StaticResource TextICON}" FontSize="24"  />
                            <TextBlock x:Name="textEmail" MouseDown="textEmail_MouseDown" Text="账号" Style="{StaticResource textHint}"    />
                            <TextBox Name="txtEmail" TextChanged="txtEmail_TextChanged" Style="{StaticResource textBox}" />
                        </Grid>
                    </Border>

                    <Border BorderBrush="#ACB0AF" BorderThickness="1" Margin="70,0,70,7" CornerRadius="5" Width="234">
                        <Grid Margin="7 9">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="24" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <TextBlock x:Name="xpwdicon"  Text="" Style="{StaticResource TextICON}"  FontSize="18"  />
                            <TextBlock x:Name="textPassword" MouseDown="textPassword_MouseDown" Text="密码" Style="{StaticResource textHint}" />
                            <PasswordBox x:Name="passwordBox" PasswordChanged="PasswordBox_PasswordChanged" Style="{StaticResource textBox}" />
                        </Grid>
                    </Border>
                    <TextBlock x:Name="btn_serveronline" Text="测试服务在线" Style="{StaticResource textHint}" HorizontalAlignment="Center"    />
                    <Button x:Name="btn_login" Content="进入修仙世界" Click="Button_ClickAsync" Style="{StaticResource loginButton}" Margin="0,6,0,0"/>
                    <Button x:Name="btn_register" Content="注册账号" Height="20" Width="80" Style="{StaticResource MyButton}" HorizontalAlignment="Left"   Click="btn_register_ClickAsync" Opacity="0.5"/>
                    <Button x:Name="btn_forpassword" Content="找回密码" Height="20" Width="80" Style="{StaticResource MyButton}" HorizontalAlignment="Right"   Click="btn_register_ClickAsync"  Opacity="0.5" Margin="0,-19,0,31"/>

                </StackPanel>

            </Border>

        </Grid>
    </Border>
</Window>



程序代码

[C#] 纯文本查看 复制代码
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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace WpfAppUpdate
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(passwordBox.Password) && passwordBox.Password.Length > 0)
                textPassword.Visibility = Visibility.Collapsed;
            else
                textPassword.Visibility = Visibility.Visible;
        }

        private void textPassword_MouseDown(object sender, MouseButtonEventArgs e)
        {
            passwordBox.Focus();
        }
        private void txtEmail_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            if (!string.IsNullOrEmpty(txtEmail.Text) && txtEmail.Text.Length > 0)
                textEmail.Visibility = Visibility.Collapsed;
            else
                textEmail.Visibility = Visibility.Visible;
        }

        private void textEmail_MouseDown(object sender, MouseButtonEventArgs e)
        {
            txtEmail.Focus();
        }

        private void Border_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
                this.DragMove();
        }

        private void Image_MouseUp(object sender, MouseButtonEventArgs e)
        {

            System.Windows.Application.Current.Shutdown();
        }
        private void btn_close_Click(object sender, RoutedEventArgs e)
        {
             System.Windows.Application.Current.Shutdown();
        }
        private Random _random = new Random();

        //布局宽490 高210 显示宽430 高180
        //阵距4行8列 点之间的距离 X轴Y轴都是70
        /// <summary>
        /// 点信息阵距
        /// </summary>
        private PointInfo[,] _points = new PointInfo[8, 4];

        /// <summary>
        /// 计时器
        /// </summary>
        private DispatcherTimer _timer;

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Init();
            //注册帧动画
            _timer = new System.Windows.Threading.DispatcherTimer();
            _timer.Tick += new EventHandler(PolyAnimation);
            _timer.Interval = new TimeSpan(0, 0, 0, 0, 1000 / 24);//一秒钟刷新24次
            _timer.Start();
        }

        /// <summary>
        /// 初始化阵距
        /// </summary>
        private void Init()
        {
            //生成阵距的点
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    double x = _random.Next(-11, 11);
                    double y = _random.Next(-6, 6);
                    _points[i, j] = new PointInfo()
                    {
                        X = i * 70,
                        Y = j * 70,
                        SpeedX = x / 24,
                        SpeedY = y / 24,
                        DistanceX = _random.Next(35, 106),
                        DistanceY = _random.Next(20, 40),
                        MovedX = 0,
                        MovedY = 0,
                        PolygonInfoList = new List<PolygonInfo>()
                    };
                }
            }

            byte r = (byte)_random.Next(0, 11);
            byte g = (byte)_random.Next(100, 201);
            int intb = g + _random.Next(50, 101);
            if (intb > 255)
                intb = 255;
            byte b = (byte)intb;

            //上一行取2个点 下一行取1个点
            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Polygon poly = new Polygon();
                    poly.Points.Add(new Point(_points[i, j].X, _points[i, j].Y));
                    _points[i, j].PolygonInfoList.Add(new PolygonInfo() { PolygonRef = poly, PointIndex = 0 });
                    poly.Points.Add(new Point(_points[i + 1, j].X, _points[i + 1, j].Y));
                    _points[i + 1, j].PolygonInfoList.Add(new PolygonInfo() { PolygonRef = poly, PointIndex = 1 });
                    poly.Points.Add(new Point(_points[i + 1, j + 1].X, _points[i + 1, j + 1].Y));
                    _points[i + 1, j + 1].PolygonInfoList.Add(new PolygonInfo() { PolygonRef = poly, PointIndex = 2 });
                    poly.Fill = new SolidColorBrush(Color.FromRgb(r, g, (byte)b));
                    SetColorAnimation(poly);
                    layout.Children.Add(poly);
                }
            }

            //上一行取1个点 下一行取2个点
            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Polygon poly = new Polygon();
                    poly.Points.Add(new Point(_points[i, j].X, _points[i, j].Y));
                    _points[i, j].PolygonInfoList.Add(new PolygonInfo() { PolygonRef = poly, PointIndex = 0 });
                    poly.Points.Add(new Point(_points[i, j + 1].X, _points[i, j + 1].Y));
                    _points[i, j + 1].PolygonInfoList.Add(new PolygonInfo() { PolygonRef = poly, PointIndex = 1 });
                    poly.Points.Add(new Point(_points[i + 1, j + 1].X, _points[i + 1, j + 1].Y));
                    _points[i + 1, j + 1].PolygonInfoList.Add(new PolygonInfo() { PolygonRef = poly, PointIndex = 2 });
                    poly.Fill = new SolidColorBrush(Color.FromRgb(r, g, (byte)b));
                    SetColorAnimation(poly);
                    layout.Children.Add(poly);
                }
            }
        }

        /// <summary>
        /// 设置颜色动画
        /// </summary>
        /// <param name="polygon">多边形</param>
        private void SetColorAnimation(UIElement polygon)
        {
            //颜色动画的时间 1-4秒随机
            Duration dur = new Duration(new TimeSpan(0, 0, _random.Next(1, 5)));
            //故事版
            Storyboard sb = new Storyboard()
            {
                Duration = dur
            };
            sb.Completed += (S, E) => //动画执行完成事件
            {
                //颜色动画完成之后 重新set一个颜色动画
                SetColorAnimation(polygon);
            };
            //颜色动画
            //颜色的RGB
            byte r = (byte)_random.Next(0, 11);
            byte g = (byte)_random.Next(100, 201);
            int intb = g + _random.Next(50, 101);
            if (intb > 255)
                intb = 255;
            byte b = (byte)intb;
            ColorAnimation ca = new ColorAnimation()
            {
                To = Color.FromRgb(r, g, b),
                Duration = dur
            };
            Storyboard.SetTarget(ca, polygon);
            Storyboard.SetTargetProperty(ca, new PropertyPath("Fill.Color"));
            sb.Children.Add(ca);
            sb.Begin(this);
        }

        /// <summary>
        /// 多边形变化动画
        /// </summary>
        void PolyAnimation(object sender, EventArgs e)
        {
            //不改变阵距最外边一层的点
            for (int i = 1; i < 7; i++)
            {
                for (int j = 1; j < 3; j++)
                {
                    PointInfo pointInfo = _points[i, j];
                    pointInfo.X += pointInfo.SpeedX;
                    pointInfo.Y += pointInfo.SpeedY;
                    pointInfo.MovedX += pointInfo.SpeedX;
                    pointInfo.MovedY += pointInfo.SpeedY;
                    if (pointInfo.MovedX >= pointInfo.DistanceX || pointInfo.MovedX <= -pointInfo.DistanceX)
                    {
                        pointInfo.SpeedX = -pointInfo.SpeedX;
                        pointInfo.MovedX = 0;
                    }
                    if (pointInfo.MovedY >= pointInfo.DistanceY || pointInfo.MovedY <= -pointInfo.DistanceY)
                    {
                        pointInfo.SpeedY = -pointInfo.SpeedY;
                        pointInfo.MovedY = 0;
                    }
                    //改变多边形的点
                    foreach (PolygonInfo pInfo in _points[i, j].PolygonInfoList)
                    {
                        pInfo.PolygonRef.Points[pInfo.PointIndex] = new Point(pointInfo.X, pointInfo.Y);
                    }
                }
            }
        }
    

    /// <summary>
    /// 阵距点信息
    /// </summary>
    public class PointInfo
    {
        /// <summary>
        /// X坐标
        /// </summary>
        public double X { get; set; }

        /// <summary>
        /// Y坐标
        /// </summary>
        public double Y { get; set; }

        /// <summary>
        /// X轴速度 wpf距离单位/二十四分之一秒
        /// </summary>
        public double SpeedX { get; set; }

        /// <summary>
        /// Y轴速度 wpf距离单位/二十四分之一秒
        /// </summary>
        public double SpeedY { get; set; }

        /// <summary>
        /// X轴需要移动的距离
        /// </summary>
        public double DistanceX { get; set; }

        /// <summary>
        /// Y轴需要移动的距离
        /// </summary>
        public double DistanceY { get; set; }

        /// <summary>
        /// X轴已经移动的距离
        /// </summary>
        public double MovedX { get; set; }

        /// <summary>
        /// Y轴已经移动的距离
        /// </summary>
        public double MovedY { get; set; }

        /// <summary>
        /// 多边形信息列表
        /// </summary>
        public List<PolygonInfo> PolygonInfoList { get; set; }
    }

    /// <summary>
    /// 多边形信息
    /// </summary>
    public class PolygonInfo
    {
        /// <summary>
        /// 对多边形的引用
        /// </summary>
        public Polygon PolygonRef { get; set; }

        /// <summary>
        /// 需要改变的点的索引
        /// </summary>
        public int PointIndex { get; set; }
    }

        private void Button_ClickAsync(object sender, RoutedEventArgs e)
        {

        }

        private void btn_register_ClickAsync(object sender, RoutedEventArgs e)
        {

        }
    }
}
 

免费评分

参与人数 2吾爱币 +11 热心值 +2 收起 理由
苏紫方璇 + 10 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
purusi + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

ok667 发表于 2023-1-12 22:44
感谢楼主
恶魔天尊 发表于 2023-1-13 08:56
RURUKnight 发表于 2023-1-12 23:49
我怎么好像见过这个代码……以前的说……

https://www.52pojie.cn/forum.php ... hlight=%D0%DE%CF%C9

应该是在这里看到的把,这个也是楼主本人发的
 楼主| kololi 发表于 2023-1-12 21:38
我不感相信啊.这么效率吗,我刚发完就审核好了.

我以前发点东西,可都是至少审核四小时以上~~~

lizf2019 发表于 2023-1-12 21:44
kololi 发表于 2023-1-12 21:38
我不感相信啊.这么效率吗,我刚发完就审核好了.

我以前发点东西,可都是至少审核四小时以上~~~

审核只有前几次会
往后就直接通过的
 楼主| kololi 发表于 2023-1-12 21:49
lizf2019 发表于 2023-1-12 21:44
审核只有前几次会
往后就直接通过的

原来如此啊,在这混的时间短,还真不知道
lzqhyzz 发表于 2023-1-12 22:10
这太棒了吧,对于我菜狗来说
叫我小白呀 发表于 2023-1-12 23:48
看到没,兄弟们,多不容易啊,一个简单的界面代码量都这么大了,多造点轮子啊
RURUKnight 发表于 2023-1-12 23:49
我怎么好像见过这个代码……以前的说……
purusi 发表于 2023-1-13 08:21
支持一下,谢谢分享
aa2923821a 发表于 2023-1-13 08:39
哦哦,明白了  。正好需要,谢谢
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 23:43

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表