私はサーバーマネージャを作成しています。サーバーを追加したり、サーバーを削除する必要があります。私はそれがかなりのインターフェイスを持っているので、サーバーのさまざまな統計情報を印刷する4つのラベルを含むピクチャボックスに表示されるサーバーに決めました。私の問題は、プログラムのユーザーが500台のサーバーを持っているとしましょう。実装するには、作成方法、定義方法、およびコード内のラベルの作成方法のみがわかります。 EX:(これは私のヘッダであるが、これは私がサーバー「カード」を実装する方法をである)コードを使用してウィンドウのフォームコントロールを追加する
private PictureBox headerArea = new PictureBox();
private PictureBox dropShadow = new PictureBox();
private Label headerText = new Label();
public Suite()
{
InitializeComponent();
}
private void Suite_Load(object sender, EventArgs e)
{
guiInit();
}
private void guiInit()
{
//Header Text
this.headerText.AutoSize = true;
this.headerText.BackColor = System.Drawing.Color.DarkSlateBlue;
this.headerText.Font = new System.Drawing.Font("Roboto Lt", 22F);
this.headerText.ForeColor = System.Drawing.SystemColors.ButtonFace;
this.headerText.Location = new System.Drawing.Point(12, 10);
this.headerText.Name = "headerText";
this.headerText.Size = new System.Drawing.Size(178, 29);
this.headerText.TabIndex = 0;
this.headerText.Text = "Server Manager";
this.Controls.Add(headerText);
//Background GUI
this.headerArea.BackColor = Color.DarkSlateBlue;
this.headerArea.Size = new System.Drawing.Size(1920, 60);
this.headerArea.Location = new System.Drawing.Point(0, 0);
this.Controls.Add(headerArea);
//Drop Shadow
this.dropShadow.Image =
global::ServerManager.Properties.Resources.dropshadow2;
this.dropShadow.BackgroundImageLayout =
System.Windows.Forms.ImageLayout.Stretch;
this.dropShadow.Location = new System.Drawing.Point(0, 47);
this.dropShadow.Name = "dropShadow";
this.dropShadow.Size = new System.Drawing.Size(1920, 65);
this.dropShadow.TabIndex = 0;
this.dropShadow.TabStop = false;
this.Controls.Add(dropShadow);
}
これに伴う問題は、私は表示された500台のサーバーを持っている必要があれば、私は、コードの2500行を持っているだろうということです。 これらのフォームを生成する方法やこれを行うためのより良い方法を作る方法はありますか?
何を試しましたか?方法はこれに適しています。あなたがそれを試してみると、SOのコミュニティがより助けになるでしょう。 –
これを行う方法を作るつもりなら、どこから始めたらいいか分からない。 – Jumbofile
必要なアクションを行い、変更する値にパラメーターを使用するメソッドを作成します。 –