• 締切済み

BackColorをPenの型で使用するには?

backColorをpenの型に変換したいのですが、教えてください。

みんなの回答

回答No.1

Option Explicit On Option Strict On Option Infer Off Option Compare Binary '難しく見えるのは認める。 'が,IDEが何をするのか,ちゃんと考えて調べるかで力の伸びが違うのだ. Class Q5186728 Inherits System.Windows.Forms.Form Private PictureBox1 As System.Windows.Forms.PictureBox Public Sub New() PictureBox1 = new System.Windows.Forms.PictureBox PictureBox1.Top = 0 PictureBox1.Left = 0 PictureBox1.Width = Me.Width PictureBox1.Height = Me.Height AddHandler PictureBox1.Paint, AddressOf Me.PictureBox1_Paint Me.Controls.Add(PictureBox1) End Sub Private Sub PictureBox1_Paint(sender As Object,e As System.Windows.Forms.PaintEventArgs) '質問の本題そのものはここから 'Meはフォーム(Q5186728のクラスのインスタンス)そのもの Dim p As System.Drawing.Pen = new System.Drawing.Pen(Me.BackColor) e.Graphics.Clear(System.Drawing.Color.White) e.Graphics.DrawLine(p,0,0,PictureBox1.Width,PictureBox1.Height) End Sub Shared Sub Main() Dim f As Q5186728 = new Q5186728() f.ShowDialog End Sub End Class

gcqd75ce
質問者

お礼

解決しました。 初心者なんで。^^

gcqd75ce
質問者

補足

ちょっとコードを変更しました。(質問者) Option Strict On 'ゲームキャラクター制作エディター 'VisualBasic2008(無料版) Public Class Form1 Private bt() As PictureBox Const my_color_suu As Integer = 11 Private my_color(my_color_suu - 1) As Color Const kyara_data_suu As Integer = 2500 Private kyara_data(kyara_data_suu - 1) As Integer Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As EventArgs) Handles MyBase.Load Array.Resize(Me.bt, 2500) Dim a, b As Integer : a = 0 : b = 0 For i As Integer = 0 To 2499 Me.bt(i) = New PictureBox() With Me.bt(i) .Name = i.ToString .BackColor = Color.White .Location = New Point(a * 11, b * 11) .Size = New Size(10, 10) End With Me.Controls.Add(Me.bt(i)) AddHandler Me.bt(i).Click, AddressOf Me.bt_Click a += 1 : If a = 50 Then a = 0 : b += 1 Next With Me.ListBox1.Items .Add("Red") .Add("Blue") .Add("Skyblue") .Add("Green") .Add("Yellow") .Add("Orange") .Add("Pink") .Add("Brown") .Add("Gray") .Add("White") .Add("Black") End With ListBox1.SelectedIndex = 0 my_color(0) = Color.Red : my_color(1) = Color.Blue : my_color(2) = Color.SkyBlue my_color(3) = Color.Green : my_color(4) = Color.Yellow : my_color(5) = Color.Orange my_color(6) = Color.Pink : my_color(7) = Color.Brown : my_color(8) = Color.Gray my_color(9) = Color.White : my_color(10) = Color.Black For i As Integer = 0 To 2499 kyara_data(i) = 9 Next End Sub Private Sub bt_Click(ByVal sender As Object, ByVal e As EventArgs) Dim colorName As String = CStr(ListBox1.SelectedItem) CType(sender, PictureBox).BackColor = Color.FromName(colorName) Dim x As Integer = CInt(CType(sender, PictureBox).Name) kyara_data(x) = ListBox1.SelectedIndex End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Dim colorName As String = CStr(ListBox1.SelectedItem) If colorName IsNot Nothing Then Me.TextBox1.BackColor = Color.FromName(colorName) End If End Sub Private Sub MyPictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyPictureBox1.Paint Dim a, b As Integer : a = 0 : b = 0 For i As Integer = 0 To 2499 Dim x As Integer = kyara_data(i) e.Graphics.DrawRectangle(Pens.my_color(x), a, b, a + 1, b + 1) a += 1 : If a = 50 Then a = 0 : b += 1 Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click End Sub End Class ☆pensのトコがエラーします。 教えてください。

関連するQ&A