0

やあ、

私がやっているのは、特定のフォルダーから画像を表示する方法ですが、デバッグすると、コードの最後の行でこのエラーが発生し、理由がわかりません.**

Error 3 'MBKiosk.classTools' does not contain a definition for 'Controls' and no extension    
method 'Controls' accepting a first argument of type 'MBKiosk.classTools' could be found (are you 
missing a using directive or an assembly reference?)

助けてくれてありがとう。

コードは次のとおりです。

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.Collections.ObjectModel;
using MBKiosk;

namespace MBKiosk
{
    class classTools
    {
        public void ShowImages(string path)
        {
            FlowLayoutPanel imagePanel = new FlowLayoutPanel();
            imagPanel.FlowDirection = FlowDirection.LeftToRight;
            imagePanel.Size = new Size(1240, 630);
            imagePanel.Location = new Point(12, 344);
            imagePanel.WrapContents = true;
            imagePanel.AutoScroll = false;
            DirectoryInfo dInfo = new DirectoryInfo(path);
            foreach (FileInfo file in dInfo.GetFiles())
            {
                System.Diagnostics.Debug.Print(file.Extension);
                if ((file.Extension == ".jpg") || (file.Extension == ".gif") || (file.Extension == 
                    ".png"))
                {
                    PictureBox image = new PictureBox();
                    image.Image = Image.FromFile(file.FullName);
                    image.SizeMode = PictureBoxSizeMode.Normal;
                    image.Size = new Size(180, 108);
                    imagePanel.Controls.Add(image);
                    imagePanel.Refresh();
                }
            }
            this.Controls.Add(imagePanel);
        }   
    }
}
4

3 に答える 3

1

これは、コードをコピーして貼り付けるときに発生する可能性があります。this.Controls は、クラス 'classTools' にメンバー Controls があることを想定しています。目的のメンバー変数を「classTools」に追加するか、別のクラスから派生させてください。

于 2012-04-28T23:33:25.030 に答える
0

インポートSystem.Windows.Formsしましたが、実際には使用していません。クラス定義を に変更すると、そのクラスclass classTools : Formsを使用できるようになります。Controls

に拡張メソッドを追加しない限り、クラスにメソッドがないAddControlsように見えますが、エラーが発生します。AddControls

于 2016-01-26T20:05:39.383 に答える