バーコードを生成するアプリケーションを作成しようとしています。これまでのところ、私はそれが正しく動作するようにすることはできません。 2つのエラーが発生します。バーコードを生成する
-Error CS0118 'generate'は名前空間ですが、生成されるタイプのように使用されます。 -Error CS1955呼び出し不可能なメンバー 'MemoryStream'はメソッドのように使用できません。
を生成する以下のコードを参照してください:
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());
}
}
}
'using(MemoryStream ms = MemoryStream())'は ' MemoryStream ms = new MemoryStream()) ' - ローカルメソッドを呼び出さないオブジェクトをインスタンス化しています – Rhumborl
エラーを生成するには、すべてのコードを持っていない可能性があります。どこでもあなたのコードに単語生成が表示されない – Wjdavis5
申し訳ありません、program.csからコードを追加しました – Truex