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

わんくま同盟

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

C# と VB.NET の入門サイト


(過去ログ 66 を表示中)
■38577 / )  複数のオブジェクトの操作
□投稿者/ aion (1回)-(2009/07/19(Sun) 15:41:38)

分類:[.NET 全般] 

Microsoft Visual Basic 2008で
txtrowsとtxtcolmnsに入力された数字分PictureBoxを生成するプログラムを作りました。
そこで生成されたPictureBoxをクリックするとが変わるようにしたいのですが、
どのように書いたらいいのかわかりません。ご指南お願いします。

このような感じです
http://www.dotup.org/uploda/www.dotup.org256643.bmp

*****コード*****


Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer = 0
        Dim x As Integer = 10
        Dim y As Integer = 10
        Dim count As Integer = Txtcolumns.Text * Txtrows.Text
        Dim pic(count) As PictureBox
        Dim rows, columns As Integer

        For rows = 0 To Txtrows.Text - 1

            For columns = 0 To Txtcolumns.Text - 1
                pic(i) = New PictureBox
                With pic(i)
                    .Size = New Size(10, 10)
                    .Location = New Point(x, y)
                    .BackColor = Color.Aqua
                End With
                Me.Controls.Add(pic(i))
                x += 11
                i += 1
            Next
            y += 11
            x = 10
        Next
    End Sub
End Class

返信 編集キー/


管理者用

- Child Tree -