中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

WPF 員工卡條形碼

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

     在公司內(nèi)部員工卡是員工身份唯一的識(shí)別工具,同時(shí)也是考勤及門禁系統(tǒng)的主要信息來(lái)源。首先在WPF 中設(shè)計(jì)一個(gè)簡(jiǎn)單的員工卡樣式,具備員工卡標(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)容比較簡(jiǎn)單,其中需要提一下的是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 來(lái)觸發(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)的長(zhǎng)度利用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)顯示出來(lái)。

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)載需保留來(lái)源!

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

主站蜘蛛池模板: 国产精品夜夜春夜夜爽久久电影 | aaaaa毛片| 国产精品久久久久久久一区二区 | 精品av| 国产97视频在线观看 | 91麻豆精品国产91久久久久久 | 日韩精品一区二区三区免费观看 | 国产成人精品久久二区二区91 | 日韩国产免费 | caoporn视频在线 | 国产精品视频网站 | 日韩一级免费大片 | 免费爱爱视频 | 国产欧美一区二区三区免费 | 人人种亚洲 | 四虎最新| 精品国产99 | aⅴ色国产 欧美 | 国产专区视频 | 国产精品污www一区二区三区 | 在线色网| 韩日在线观看视频 | 久久av资源网 | 免费在线观看一区二区三区 | 伊人精品久久久久77777 | 国产露脸国语对白在线 | av夜夜操| 国产伦精品一区二区三区在线 | 精品一二三 | 亚洲激情视频在线 | 国产精品欧美一区二区三区 | 在线亚洲一区 | 午夜在线精品 | 国内自拍真实伦在线观看 | 成人欧美一区二区三区黑人孕妇 | 欧美一级视频免费看 | www.黄色在线观看 | 国产激情免费视频 | 黄网站在线观看 | 久久久久成人精品亚洲国产 | 91成人精品 |