首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >生成条形码

生成条形码
EN

Stack Overflow用户
提问于 2016-04-13 17:01:34
回答 1查看 294关注 0票数 0

我试图创建一个应用程序,将产生一个条形码。到目前为止,我无法使它正常工作。我有两个错误:

-Error CS0118 'generate‘是一个名称空间,但使用起来像类型generate;-Error CS1955不可调用的成员'MemoryStream’不能像方法一样使用。生成

请参阅以下代码:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
namespace barcode
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String barcode = pole.Text;
            Bitmap bitmap = new Bitmap(barcode.Length * 40, 150);
            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                Font ofont = new System.Drawing.Font("IDAutomationHC39M", 20);
                PointF point = new PointF(2f, 2f);
                SolidBrush black = new SolidBrush(Color.Black);
                SolidBrush White = new SolidBrush(Color.White);
                graphics.FillRectangle(White, 0, 0, bitmap.Width, bitmap.Height);
                graphics.DrawString("*" + barcode + "*", ofont, black, point);
            }
            using (MemoryStream ms = MemoryStream()) 
            {
                bitmap.Save(ms, ImageFormat.Png);
                box.Image = bitmap;
                box.Height = bitmap.Height;
                box.Width = bitmap.Width;
            }
        }
    }
    }



PROGRAM.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace generate
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new generate());
            }
        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-13 17:44:21

更改这一行

代码语言:javascript
复制
Application.Run(new generate());

对此:

代码语言:javascript
复制
Application.Run(new Form1());

此外,您还必须使用下面的行将Form1的命名空间导入到Program.cs文件中

代码语言:javascript
复制
using barcode;

对于MemoryStream错误,请更改这一行:

代码语言:javascript
复制
using (MemoryStream ms = MemoryStream())

对此:

代码语言:javascript
复制
using (MemoryStream ms = new MemoryStream()) 

这里发生的事情是,您未能使用关键字MemoryStream初始化new实例,因此编译器将其视为一种方法。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36605024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档