天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

WPF 員工卡條形碼

     大家都知道條形碼(Barcode)是一種可以由機(jī)器識(shí)別的特殊編碼,在生產(chǎn)、生活中也常常會(huì)見到并使用它。條形碼的類型和種類很多感興趣的朋友可以詳細(xì)了解一下。其中Code 39 可以說是一種最為常見并廣泛使用的字符與數(shù)字結(jié)合的編碼類型,本篇也將利用它制作一個(gè)帶有條形碼的員工卡應(yīng)用程序。

     在公司內(nèi)部員工卡是員工身份唯一的識(shí)別工具,同時(shí)也是考勤及門禁系統(tǒng)的主要信息來源。首先在WPF 中設(shè)計(jì)一個(gè)簡單的員工卡樣式,具備員工卡標(biāo)識(shí)、員工相片、員工姓名等。

<Border CornerRadius="3" BorderBrush="Gray" BorderThickness="2" Background="White"        MouseLeftButtonDown="Border_MouseLeftButtonDown">    <Canvas x:Name="mainCanvas">        <Grid x:Name="closeBtn" Canvas.Left="330" Canvas.Top="0"               MouseLeftButtonDown="Close_MouseLeftButtonDown">            <Ellipse Height="15" Width="15" HorizontalAlignment="Center">                <Ellipse.Fill>                    <SolidColorBrush x:Name="ellipseColor"/>                </Ellipse.Fill>            </Ellipse>            <TextBlock Text="x" Margin="2,-2,2,2" HorizontalAlignment="Center">                <TextBlock.Foreground>                    <SolidColorBrush x:Name="textColor" Color="Gray"/>                </TextBlock.Foreground>            </TextBlock>        </Grid>        <Border BorderBrush="#FF54545C" Canvas.Top="25" CornerRadius="5"                Height="49" Width="339" Background="#FF2192C4" Canvas.Left="5">            <TextBlock Text="EMPLOYEE   CARD" Foreground="White" FontSize="20"                       VerticalAlignment="Center" HorizontalAlignment="Center"                       FontWeight="Black" FontFamily="Microsoft Sans Serif"/>        </Border>        <Grid Canvas.Left="96" Canvas.Top="78">            <Grid.RowDefinitions>                <RowDefinition />                <RowDefinition />            </Grid.RowDefinitions>            <Image Source="Images/cardpic.png" Grid.Row="0"/>            <TextBlock Text="Li Jing Ran" FontSize="30" FontWeight="Black"                        Grid.Row="1" HorizontalAlignment="Center"/>        </Grid>    </Canvas></Border>

Image

     代碼內(nèi)容比較簡單,其中需要提一下的是x:Name 為closeBtn 的<Grid>,可以看到它包含了一個(gè)<Ellipse>和<Textblock>,它們的顏色填充方式看上去做的很復(fù)雜。其實(shí)是為了實(shí)現(xiàn)一個(gè)動(dòng)態(tài)效果:當(dāng)鼠標(biāo)移動(dòng)到關(guān)閉圖標(biāo)上時(shí),其<Ellipse>和<Textblock>會(huì)改變顏色(如下圖對(duì)比)。

normal   change

     該效果代碼如下,通過Window.Resources 設(shè)置一個(gè)ColorAnimation Storyboard,再通過MouseEnter、MouseLeave 來觸發(fā)Storyboard 動(dòng)畫效果。

<Window.Resources>    <Storyboard x:Key="flashClose">        <ColorAnimation Storyboard.TargetName="ellipseColor"                         Storyboard.TargetProperty="Color"                        From="White" To="Gray" Duration="0:0:0.1"/>        <ColorAnimation Storyboard.TargetName="textColor"                         Storyboard.TargetProperty="Color"                        From="Gray" To="White" Duration="0:0:0.1"/>    </Storyboard></Window.Resources><Window.Triggers>    <EventTrigger SourceName="closeBtn" RoutedEvent="Grid.MouseEnter">        <BeginStoryboard x:Name="showClosBtn" Storyboard="{StaticResource flashClose}"/>    </EventTrigger>    <EventTrigger SourceName="closeBtn" RoutedEvent="Grid.MouseLeave">        <StopStoryboard BeginStoryboardName="showClosBtn"/>    </EventTrigger></Window.Triggers>

     完成上面的界面設(shè)計(jì),最后只需在員工卡下放的空白處添加員工編號(hào)條形碼即可。首先在項(xiàng)目中加入Barcode 和Code39 類,我們要通過這兩個(gè)類完成條形碼的繪制工作。打開C#程序,編寫如下代碼。

定義編碼

     通過Barcodes 類創(chuàng)建一個(gè)新的條形碼,定義BarcodeType 為"Code39",編碼Data 為“10001”,如果需要校驗(yàn)則將CheckDigit 設(shè)為"Yes"。其中thinWidth、thickWidth 用于定義黑白條碼的寬窄度。

Barcodes bb = new Barcodes();bb.BarcodeType = Barcodes.BarcodeEnum.Code39;bb.Data = "10001";bb.CheckDigit = Barcodes.YesNoEnum.Yes;bb.encode();int thinWidth;int thickWidth;thinWidth = 2;thickWidth = 3 * thinWidth;string outputString = bb.EncodedData;string humanText = bb.HumanText;

繪制條形碼

根據(jù)編碼(EncodedData)的長度利用Rectangle 類逐一繪制黑、白條碼,t 表示窄碼,w 表示寬碼。

int len = outputString.Length;int currentPos = 50;int currentTop = 340;int currentColor = 0;            for (int i = 0; i < len; i++){    Rectangle rect = new Rectangle();    rect.Height = 80;    if (currentColor == 0)    {        currentColor =  1;        rect.Fill = new SolidColorBrush(Colors.Black);    }    else    {        currentColor = 0;        rect.Fill = new SolidColorBrush(Colors.White);    }    Canvas.SetLeft(rect, currentPos);    Canvas.SetTop(rect, currentTop);    if (outputString[i] == 't')    {        rect.Width = thinWidth;        currentPos += thinWidth;    }    else if (outputString[i] == 'w')    {        rect.Width = thickWidth;        currentPos += thickWidth;    }                 mainCanvas.Children.Add(rect);}

添加可讀碼

最后在條形碼下方添加一行可讀碼,方便員工認(rèn)讀條形碼內(nèi)容,也就是將“10001”員工編號(hào)顯示出來。

TextBlock tb = new TextBlock();tb.Text = humanText;tb.FontSize = 25;tb.FontFamily = new FontFamily("Consolas");Rect rx = new Rect(0, 0, 0, 0);tb.Arrange(rx);Canvas.SetLeft(tb, 120);Canvas.SetTop(tb, currentTop + 80);mainCanvas.Children.Add(tb);

效果圖

最后運(yùn)行下程序看看效果如何,當(dāng)然條形碼內(nèi)容可按各自需求添加任何字符或數(shù)字。

Image

源代碼下載

WPFBarcode.zip

NET技術(shù)WPF 員工卡條形碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 被老头下药玩好爽 | 亚洲va在线va天堂XX xX | 91成品视频 | 伦理片天堂eeuss影院2o12 | 国产成人久久AV免费看澳门 | 囯产精品一品二区三区 | 国产亚洲日韩另类在线观看 | 99亚洲精品色情无码久久 | 蜜芽最新域名解析网站 | 久久视频在线视频观看天天看视频 | 国产乱妇乱子在线播视频播放网站 | 国产人成无码视频在线观看 | 99热国产这里只有精品免费 | 蜜柚在线观看免费高清官网视频 | 亚洲男人在线观看 | 亚洲精品成人久久久影院 | 色爰情人网站 | avv天堂| 亚洲日本天堂在线 | 国产亚洲欧洲日韩在线观看 | 2021乱码精品公司 | 992交通广播| 亚洲国产精品第一影院在线观看 | 日产精品高潮呻吟AV久久 | 国产精品亚洲视频在线观看 | 成人精品在线视频 | 秋霞电影网午夜一级鲁丝片 | 色中色入口2015 | 久久精品电影院 | 久久无码人妻AV精品一区 | 快播最新电影网站 | 亚洲日产2020乱码草莓毕 | 国产精品爽爽久久久久久竹菊 | 亚洲欧美在无码片一区二区 | 欧美精品久久久久性色AV苍井 | 91福利国产在线观看网站 | 亚洲AV无码专区国产乱码网站 | 亚洲伊人久久网 | 国产成人免费 | 92看看福利午夜影院 | 日韩成人在线视频 |