WPF界面设计技巧(2)—自定义漂亮的按钮样式

上次做了个很酷的不规则窗体,这次我们来弄点好看的按钮出来,此次将采用纯代码来设计按钮样式,不需要 Microsoft Expression Design 辅助了。

 

首先打开 Microsoft Visual Studio 2008 ,新建一个WPF项目,在上面随便放几个按钮:

 

 

然后给各个按钮设置不同的背景颜色:

 

 

设置好之后就是这样啦:

 

 

然后我们就开始在 App.xaml 文件中定义按钮样式了:

 

 

定义的样式代码如下:

 

Code
<Application x:Class="WPFButton.App"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri
="Window1.xaml">
    
<Application.Resources>
        
<!--定义按钮样式-->
        
<Style TargetType="Button">
            
<Setter Property="Foreground" Value="Black"/>
            
<!--修改模板属性-->
            
<Setter Property="Template">
                
<Setter.Value>
                    
<!--控件模板-->
                    
<ControlTemplate TargetType="Button">
                        
<!--背景色-->
                        
<Border x:Name="back" Opacity="0.8" CornerRadius="3">
                            
<Border.BitmapEffect>
                                
<OuterGlowBitmapEffect Opacity="0.7" GlowSize="0" GlowColor="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" />
                            
</Border.BitmapEffect>
                            
<Border.Background>
                                
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1.5">
                                    
<GradientBrush.GradientStops>
                                        
<GradientStopCollection>
                                            
<GradientStop Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" Offset="0"/>
                                            
<GradientStop Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" Offset="0.4"/>
                                            
<GradientStop Color="#FFF" Offset="1"/>
                                        
</GradientStopCollection>
                                    
</GradientBrush.GradientStops>
                                
</LinearGradientBrush>
                            
</Border.Background>
                            
<!--前景色及边框-->
                            
<Border x:Name="fore" BorderThickness="1" CornerRadius="3" BorderBrush="#5555">
                                
<Border.Background>
                                    
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                        
<GradientBrush.GradientStops>
                                            
<GradientStopCollection>
                                                
<GradientStop Color="#6FFF" Offset="0.5"/>
                                                
<GradientStop Color="#1111" Offset="0.51"/>
                                            
</GradientStopCollection>
                                        
</GradientBrush.GradientStops>
                                    
</LinearGradientBrush>
                                
</Border.Background>
                                
<!--按钮内容-->
                                
<ContentPresenter x:Name="content" HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBinding  Content}">
                                    
<ContentPresenter.BitmapEffect>
                                        
<DropShadowBitmapEffect Color="#000" Direction="-90" ShadowDepth="2" Softness="0.1" Opacity="0.3" />
                                    
</ContentPresenter.BitmapEffect>
                                
</ContentPresenter>
                            
</Border>
                        
</Border>
                        
<!--触发器-->
                        
<ControlTemplate.Triggers>
                            
<!--鼠标移入移出-->
                            
<Trigger Property="IsMouseOver" Value="True">
                                
<Trigger.EnterActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation To="6" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<ColorAnimation To="#AFFF" BeginTime="0:0:0.2" Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation To="#3FFF" BeginTime="0:0:0.2" Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.EnterActions>
                                
<Trigger.ExitActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.ExitActions>
                            
</Trigger>
                            
<!--按钮按下弹起-->
                            
<Trigger Property="IsPressed" Value="True">
                                
<Trigger.EnterActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation To="3" Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<ColorAnimation To="#3AAA" Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation To="#2111" Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.EnterActions>
                                
<Trigger.ExitActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.ExitActions>
                            
</Trigger>
                            
<!--按钮失效-->
                            
<Trigger Property="IsEnabled" Value="False">
                                
<Setter Property="Foreground" Value="#B444"/>
                                
<Trigger.EnterActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation To="0" Duration="0:0:0.3" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<DoubleAnimation To="1" Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Opacity)" />
                                            
<DoubleAnimation To="-135" Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Direction)" />
                                            
<ColorAnimation To="#FFF" Duration="0:0:0.3" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Color)" />
                                            
<ColorAnimation To="#D555" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
                                            
<ColorAnimation To="#CEEE" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation To="#CDDD" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.EnterActions>
                                
<Trigger.ExitActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Opacity)" />
                                            
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Direction)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Color)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.ExitActions>
                            
</Trigger>
                        
</ControlTemplate.Triggers>
                    
</ControlTemplate>
                
</Setter.Value>
            
</Setter>
        
</Style>
    
</Application.Resources>
</Application>

 

看了先不要头大,我们先看看最终效果,然后回过头来再解释代码:

 

 

这是常规样式

 

 

这个是鼠标移到上面时的样式

 

 

 

这个是鼠标点击时的样式

 

 

还有就是按钮失效时的样式

 

 

效果还算不错吧,下面来讲解代码喽,头晕的同学可以现在就收拾东西回家了哈。

 

 

我们先来看这个命名为“back”的 Border 元素,它用它的 Background 属性充当了整个按钮的背景色。

 

 

<Border.Background>
                                
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1.5">
                                    
<GradientBrush.GradientStops>
                                        
<GradientStopCollection>
                                            
<GradientStop Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" Offset="0"/>
                                            
<GradientStop Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" Offset="0.4"/>
                                            
<GradientStop Color="#FFF" Offset="1"/>
                                        
</GradientStopCollection>
                                    
</GradientBrush.GradientStops>
                                
</LinearGradientBrush>
                            
</Border.Background>

 

其背景所用的是一个渐变笔刷,起始值和中间值都是引用的按钮本身的背景色,就是我们之前设置过的颜色啦,终止值是白色,这样通过位置调整,我们可以在按钮最下部产生一些向白色的过度色彩效果。

 

 

<Border.BitmapEffect>
                                
<OuterGlowBitmapEffect Opacity="0.7" GlowSize="0" GlowColor="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" />
                            
</Border.BitmapEffect>

 

它的 BitmapEffect 属性我们设置了一个大小为 0 的外发光效果,平常是看不见这效果的,在这里预先设置好,是为了在鼠标移入、按下时实现动画使用。

 

 

再来看看这个命名为“fore”的 Border 元素,它实现的是按钮的边框和高亮反光效果,我为它设置了一个半透明的黑色1像素边框,使得这个边框的色彩可以和背景色混合起来。

 

 

                                <Border.Background>
                                    
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                        
<GradientBrush.GradientStops>
                                            
<GradientStopCollection>
                                                
<GradientStop Color="#6FFF" Offset="0.5"/>
                                                
<GradientStop Color="#1111" Offset="0.51"/>
                                            
</GradientStopCollection>
                                        
</GradientBrush.GradientStops>
                                    
</LinearGradientBrush>
                                
</Border.Background>

 

它的背景同样采用的渐变笔刷,起始值和终止值的位置几乎贴在一起,从而形成比较鲜明的反光度对比。

 

 

ContentPresenter 元素用于呈现按钮原本的内容,对于按钮来说就是按钮上的文字了,当然也可能会存在图片或其它东西。

 

 

                                    <ContentPresenter.BitmapEffect>
                                        
<DropShadowBitmapEffect Color="#000" Direction="-90" ShadowDepth="2" Softness="0.1" Opacity="0.3" />
                                    
</ContentPresenter.BitmapEffect>

 

我为之加了一个不太明显的阴影滤镜以增强显示效果。

 

 

剩下的就是些可爱又该死的 Trigger ,我们通过这些触发器来改变按钮在不同状态时的外观。

 

 

                            <!--鼠标移入移出-->
                            
<Trigger Property="IsMouseOver" Value="True">
                                
<Trigger.EnterActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation To="6" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<ColorAnimation To="#AFFF" BeginTime="0:0:0.2" Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation To="#3FFF" BeginTime="0:0:0.2" Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.EnterActions>
                                
<Trigger.ExitActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.ExitActions>
                            
</Trigger>

 

在鼠标移入按钮时,我依次创建了改变外发光效果大小、改变上部反光区域颜色、改变下部反光区域颜色的动画,这里的要点就在于“Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)"”属性设置语句,琢磨一下你就能看出这是对属性路径的描述,只不过它们写起来和看起来都很让人生气。

 

 

                            <!--按钮按下弹起-->
                            
<Trigger Property="IsPressed" Value="True">
                                
<Trigger.EnterActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation To="3" Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<ColorAnimation To="#3AAA" Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation To="#2111" Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.EnterActions>
                                
<Trigger.ExitActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.ExitActions>
                            
</Trigger>

 

按下和弹起按钮时,我们做了相似的动画改变,与前面相比只是数值略微不同。

 

 

                            <!--按钮失效-->
                            
<Trigger Property="IsEnabled" Value="False">
                                
<Setter Property="Foreground" Value="#B444"/>
                                
<Trigger.EnterActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation To="0" Duration="0:0:0.3" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<DoubleAnimation To="1" Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Opacity)" />
                                            
<DoubleAnimation To="-135" Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Direction)" />
                                            
<ColorAnimation To="#FFF" Duration="0:0:0.3" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Color)" />
                                            
<ColorAnimation To="#D555" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
                                            
<ColorAnimation To="#CEEE" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation To="#CDDD" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.EnterActions>
                                
<Trigger.ExitActions>
                                    
<BeginStoryboard>
                                        
<Storyboard>
                                            
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
                                            
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Opacity)" />
                                            
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Direction)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Color)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" />
                                            
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" />
                                        
</Storyboard>
                                    
</BeginStoryboard>
                                
</Trigger.ExitActions>
                            
</Trigger>

 

当按钮失效时,我要改变很多东西,首先将文字颜色设为灰色,然后依次创建了改变外发光效果大小、改变内容阴影效果不透明度、改变内容阴影效果角度、改变内容阴影效果颜色、改变按钮边框颜色、改变上部反光区域颜色、改变下部反光区域颜色的动画。

 

这里将先前对内容应用的阴影效果彻底改变,使之产生凹陷的效果。

 

 

好了,到这里就下课啦,文章有点冗长了,但应该对新手很有帮助,老鸟估计现在已经梦游仙境了吧。

 

源文件下载

转载于:https://www.cnblogs.com/SkyD/archive/2008/07/15/1243043.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/379981.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ropgadgets与ret2syscall技术原理

程序&#xff1a; #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <sys/syscall.h> void exploit() { system("/bin/sh"); } void func() { char str[0x20]; read(0,str,0x50); } int…

PHP中单引号和双引号的区别

0x01 单引号 单引号里面的内容不会被解释&#xff0c;不管什么内容&#xff0c;都当做字符串处理 <?php$abc1234; $stradc$abc; echo $str;输出 0x02 双引号 双引号里面的内容会被解释&#xff0c;像一些换行&#xff08;\n)、数据元素等都会被解释 <?php$abc1234;…

关闭页面时执行“退出”的解决方案

在有些应用中我们需要实时的更新站点用户是否在线的状态。比如一些论坛里的在线成员实时显示&#xff0c;或基于网页的聊天、会议系统等。这种情况下&#xff0c;如果用户点击“退出”按钮或链接&#xff0c;我们将之行一系列后台操作&#xff0c;将该用户标识成off line状态&a…

python网络编程---TCP客户端

0x01 环境 python2、 pycharm 0x02 程序 # -*- coding:UTF-8 -*- import sockettarget_hostwww.baidu.com tarfet_port80target_hostlocalhost target_port3345 dataABCDEF# 创建一个socket对象 client socket.socket(socket.AF_INET,socket.SOCK_STREAM) # 连接客户端 clien…

python网络编程---TCP服务器

0x01 环境 python2 pycharm 0x02 程序 客户端程序&#xff1a; # -*- coding:UTF-8 -*- import sockettarget_hostwww.baidu.com target_port80target_hostlocalhost target_port3345 dataABCDEF# 创建一个socket对象 client socket.socket(socket.AF_INET,socket.SOCK_STRE…

sys.argv和getopt

0x01 sys.argv sys.argv用来读取命令行参数&#xff0c;保存程序的文件名和命令参数&#xff0c;读入的参数以列表保存 import sysprint sys.argv print type(sys.argv)可以看到&#xff0c;sys.argv把空格当成分隔符&#xff0c;空格两边的值当做sys.argv的一个元素&#xf…

[导入]《大话设计模式》重印公告

摘要: 《大话设计模式》12月中旬上市&#xff0c;至2008年1月底仅仅一个多月&#xff0c;5000册即销售一空&#xff0c;清华大学出版社已经开始重印&#xff0c;也就是说很快可以在二月底或三月初看到新印刷修正过大部分错误的《大话设计模式》。 阅读全文[新闻]《人民日报市场…

hdu1053 Entropy hdu2527 Safe Or Unsafe

裸裸的哈弗曼编码&#xff0c;求出哈弗曼编码的路径长度&#xff0c;注意整个字符串为一种字符的情况 View Code #include<iostream>#include<queue>#include<algorithm>#include<vector>using namespace std;struct node{int u,w; node(int a0,in…

sys.stdin.read和raw_input函数

sys.stdin.read函数 例子&#xff1a; import sysreadsys.stdin.read() for i in range(len(read)):print i,read[i],-1运行&#xff0c;当执行到readsys.stdin.read()会阻塞&#xff0c;等待我们输入 我们输入&#xff1a; h e当输入&#xff0c;ctrlD结束输入&#xff0c…

利用带关联子查询Update语句更新数据

Update是T-sql中再简单不过的语句了&#xff0c;update table set columnexpression [where condition]&#xff0c;我们都会用到。但update的用法不仅于此&#xff0c;真正在开发的时候&#xff0c;灵活恰当地使用update可以达到事半功倍的效果。 假定有表Table1&#xff08;…

web安全----XSS漏洞之基本原理

0x01 概述 XSS为跨站脚本攻击&#xff0c;XSS攻击针对的是用户层面的攻击&#xff01;类型有反射型XSS、存储型XSS、DOM型XSS&#xff0c;这里的DOM可以理解为页面&#xff0c;或者是所有的标签、内容之和 0x02 反射型XSS 反射型XSS攻击流程为&#xff1a; 即&#xff1a; …

web安全----xss工具使用3

XSSer 0x01 安装 环境&#xff1a;kali、python3&#xff08;必须是python3&#xff0c;kali默认为python2&#xff09; 安装步骤&#xff1a; git clone https://github.com/epsylon/xsser.git cd xsser sudo python3 setup.py install 使用命令&#xff1a; xsser -h查看…

web安全---XSS利用平台BLUE-LOTUS安装与使用

0x01 安装 环境&#xff1a;windows、phpstudy 下载地址&#xff1a;https://gitee.com/gid1314/BlueLotus_XSSReceiver-master 下载后将文件解压&#xff0c;重命名为blue&#xff0c;放在www目录下 访问&#xff1a;http://IP/blue 点击安装 这里只需要修改后台登陆密码和…

使用delphi 开发多层应用(十)安全访问服务器

前面讲了如何建立和访问服务器,但是前面建的服务器都没有安全控制&#xff0c;这里有很大的安全问题,第一是任何人做一个客户端都可以都可以访问 服务器。第二是数据在网络传输过程中都是明码的&#xff0c;没有加密&#xff0c;使用网络侦听器就可以检测到传输的内容。这是一个…

web安全---浏览器解析提交数据的过程

解码规则 html解析器对html文档进行解析&#xff0c;完成解析并创建DOM树JavaScript或者CSS解析器对内联脚本进行解析&#xff0c;完成js、css解码url解码会根据url所在的顺序不同而在JS解码或者解码后 解码顺序 html解析第一步执行&#xff0c;而JS解析和URL解析则要根据情…

利用POI创建OpenOffice中的Excel文件

之所以称为OpenOffice的Excel文件,我发现了一个特点就是: 一些网站严格限定了文件必须为MS的Excel格式的话,用POI的HSSF创建的Excel就会不识别.不知道是什么原因,可能是版本的问题,据说HSSF(令人讨厌的电子表格格式)生成的是MS97的格式.但是97-2003的提示中明显的说明了MS的lib…

web安全-----CSRF漏洞

简述 CSRF&#xff1a;Cross-site request -forgery&#xff0c;跨站请求伪造&#xff0c;是一种web攻击方式&#xff0c;是由于网站的cookie在浏览器中不会过期&#xff0c;只要不关闭浏览器或者退出登录&#xff0c;那以后只要访问这个网站&#xff0c;都会默认你已经登录。…

依赖、关联、聚合、组合还有泛化的关系(转载)

依赖、关联、聚合、组合还有泛化的关系 此文为转载文章:http://zjzkiss.cnblogs.com/世界是普遍联系的&#xff0c;因此程序世界中的类&#xff0c;也不可能是孤立的。UML为我们定义了它们之间的关系&#xff0c;就是&#xff1a;依赖、关联、聚合、组合还有泛化。 泛化关系比…

web安全---SSRF漏洞

简介 SSRF&#xff1a;服务器请求伪造&#xff0c;是一种攻击者构造形成由服务端发起请求 的一个安全漏洞。一般情况下&#xff0c;SSRF攻击的目标是从外网无法访问的内部系统&#xff08;正是因为它是由服务端发起的&#xff0c;所以它能够请求到与它相连而与外网隔离的内部系…

OD使用

0x01 功能界面 序号1是汇编代码对应的地址窗口序号2是汇编对应的十六进制机器码窗口序号3是反汇编窗口序号4是反汇编代码对应的注释信息窗口序号5是寄存器信息窗口序号6是当前执行到的反汇编代码的信息窗口序号7是数据所在的地址序号8是数据的十六进制编码信息&#xff0c;序号…