2016-04-13 11 views
0

バーコードを生成するアプリケーションを作成しようとしています。これまでのところ、私はそれが正しく動作するようにすることはできません。 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()); 
      } 
     } 
    } 
+2

'using(MemoryStream ms = MemoryStream())'は ' MemoryStream ms = new MemoryStream()) ' - ローカルメソッドを呼び出さないオブジェクトをインスタンス化しています – Rhumborl

+0

エラーを生成するには、すべてのコードを持っていない可能性があります。どこでもあなたのコードに単語生成が表示されない – Wjdavis5

+0

申し訳ありません、program.csからコードを追加しました – Truex

答えて

4

変更このラインこれに

Application.Run(new generate()); 

Application.Run(new Form1()); 

また、名前空間をインポートする必要があるとしているがForm1のProgram.csファイルに次の行番号

これに

using (MemoryStream ms = MemoryStream()) 

:ここで起こったキーワードnewそうでMemoryStreamのインスタンスを初期化に失敗しました何

using (MemoryStream ms = new MemoryStream()) 

MemoryStreamエラーについては

using barcode; 

、この行を変更コンパイラはそれをメソッドとして扱いました

+0

それは素晴らしいです!ご協力ありがとうございました。アプリは今動作し、画像を生成しますが、バーコードは作成されません。何か案は?ありがとうございました – Truex

+0

@Truex私はあなたの新しい問題に関連するすべての重要なデータで新しい質問を投稿することをお勧めします。お役に立てて嬉しいです! :) –

+0

私はちょうど別の質問を投稿しています。もう一度、あなたの助けに感謝します – Truex

関連する問題