C# と VB.NET の質問掲示板

ASP.NET、C++/CLI、Java 何でもどうぞ

ログ内検索
  • キーワードを複数指定する場合は 半角スペース で区切ってください。
  • 検索条件は、(AND)=[A かつ B] (OR)=[A または B] となっています。
  • [返信]をクリックすると返信ページへ移動します。
キーワード/ 検索条件 /
検索範囲/ 強調表示/ ON (自動リンクOFF)
結果表示件数/ 記事No検索/ ON
大文字と小文字を区別する

No.83798 の関連記事表示

<< 0 >>
■83798  動的コントロール配置
□投稿者/ Users -(2017/04/10(Mon) 18:10:42)

    分類:[C#] 

    Windows 7 / Visual Basic 2010 C#

    Textboxで多次元配列を用いた方法をご教示お願い致します。

    Formロード時に9列×10行=計90個のTextboxを表示したいのですが、下記のような9列×1行までしかうまく対応出来ていません。行を増やすにはどうしたら良いでしょうか?

    private System.Windows.Forms.TextBox[] testTextBox;
    private void Main_frm_Load(object sender, EventArgs e)
    {
    //ボタンコントロール配列の作成(ここでは5つ作成)
    this.testTextBox = new System.Windows.Forms.TextBox[9];
    //ボタンコントロールのインスタンス作成し、プロパティを設定する
    this.SuspendLayout();
    for (int i = 0; i < this.testTextBox.Length; i++)
    {
    //インスタンス作成
    this.testTextBox[i] = new System.Windows.Forms.TextBox();
    //プロパティ設定
    this.testTextBox[i].Size = new Size(30, 30);
    this.testTextBox[i].Location = new Point(i * 30, 10);
    }
    //フォームにコントロールを追加
    this.Controls.AddRange(this.testTextBox);
    this.ResumeLayout(false);
    }
親記事 /過去ログ143より / 関連記事表示
削除チェック/

■83800  Re[1]: 動的コントロール配置
□投稿者/ 魔界の仮面弁士 -(2017/04/10(Mon) 18:37:25)
    No83798 (Users さん) に返信
    > Formロード時に9列×10行=計90個のTextboxを表示したいのですが、
    「90 個の TextBox」の代わりに、9列10行な
    「1個の DataGridView」でまかなえないでしょうか?

    > 下記のような9列×1行までしかうまく対応出来ていません。行を増やすにはどうしたら良いでしょうか?
    > this.testTextBox[i].Location = new Point(i * 30, 10);

    X 座標は「i * 30」という変動値なのに、
    Y 座標が「10」という固定値だからでしょう。

    this.testTextBox = new System.Windows.Forms.TextBox[90];
    this.SuspendLayout();

    for (int y = 0; y < 10; y++)
    for (int x = 0; x < 9; x++)
    {
      int i = y * 9 + x;
      this.testTextBox[i] = new System.Windows.Forms.TextBox();
      this.testTextBox[i].Name = "textTextBox" + i;
      this.testTextBox[i].Text = y + ":" + x;
      this.testTextBox[i].Size = new Size(30, 20);
      this.testTextBox[i].Location = new Point(x * 30, y * 20);
    }
    this.Controls.AddRange(this.testTextBox);
    this.ResumeLayout(false);
記事No.83798 のレス /過去ログ143より / 関連記事表示
削除チェック/

■83812  Re[2]: 動的コントロール配置
□投稿者/ Users -(2017/04/11(Tue) 11:32:16)
    DataGridViewを使用する方が後の処理で面倒になるため、シンプルな形を取ることとしました。

    無事に解決しました。ありがとうございました。


    No83800 (魔界の仮面弁士 さん) に返信
    > ■No83798 (Users さん) に返信
    >>Formロード時に9列×10行=計90個のTextboxを表示したいのですが、
    > 「90 個の TextBox」の代わりに、9列10行な
    > 「1個の DataGridView」でまかなえないでしょうか?
    >
    >>下記のような9列×1行までしかうまく対応出来ていません。行を増やすにはどうしたら良いでしょうか?
    >>this.testTextBox[i].Location = new Point(i * 30, 10);
    >
    > X 座標は「i * 30」という変動値なのに、
    > Y 座標が「10」という固定値だからでしょう。
    >
    > this.testTextBox = new System.Windows.Forms.TextBox[90];
    > this.SuspendLayout();
    >
    > for (int y = 0; y < 10; y++)
    > for (int x = 0; x < 9; x++)
    > {
    >   int i = y * 9 + x;
    >   this.testTextBox[i] = new System.Windows.Forms.TextBox();
    >   this.testTextBox[i].Name = "textTextBox" + i;
    >   this.testTextBox[i].Text = y + ":" + x;
    >   this.testTextBox[i].Size = new Size(30, 20);
    >   this.testTextBox[i].Location = new Point(x * 30, y * 20);
    > }
    > this.Controls.AddRange(this.testTextBox);
    > this.ResumeLayout(false);
記事No.83798 のレス / END /過去ログ143より / 関連記事表示
削除チェック/



<< 0 >>

パスワード/

- Child Tree -