笔记-CppCLR_WinForms操作BarcodeLib.Barcode.WinForms.dll条形码生成

1.在VS中下载BarcodeLib.Barcode.WinForms.dll
笔记-CppCLR_WinForms操作BarcodeLib.Barcode.WinForms.dll条形码生成_第1张图片
2.条形码生成函数,返回为Bitmap

private: Image^ DrawBarCode(String^ serialNum, int width, int height)
{
    BarcodeLib::Barcode::Linear ^barcode =gcnew BarcodeLib::Barcode::Linear();
    BarcodeLib::Barcode::BarcodeType^mBarcodeType = gcnew BarcodeLib::Barcode::BarcodeType;

    barcode->Type =(BarcodeLib::Barcode::BarcodeType)Enum::Parse(mBarcodeType->GetType(), this->comboBox1->Text) ;
    barcode->Data = serialNum;// "";

    barcode->UOM = BarcodeLib::Barcode::UnitOfMeasure::PIXEL;
    barcode->BarWidth = width;
    barcode->BarHeight = height;
    barcode->LeftMargin = mleft;
    barcode->RightMargin = mright;
    barcode->TopMargin = mtop;
    barcode->BottomMargin = mbottom;

    barcode->ImageFormat = System::Drawing::Imaging::ImageFormat::Png;
    // more barcode settings here

    // generate barcode and output to Bitmap object
    Bitmap^ barcodeInBitmap = barcode->drawBarcode();

    return barcodeInBitmap;
}

3.生成条形码并显示

private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) 
{
    Image^mImage= DrawBarCode(this->textBox1->Text, 1, this->mheight);
    this->pictureBox1->Image = mImage;
    if (mImage->Size.Width > this->pictureBox1->Size.Width)
    {
        this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;

    }
    else
    {
        this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::CenterImage;

    }
}

4.运行效果
笔记-CppCLR_WinForms操作BarcodeLib.Barcode.WinForms.dll条形码生成_第2张图片

你可能感兴趣的:(Windows窗体应用,Winform,CLR,C++,条形码,Barcode)