*.°前提・実現したいこと
複数の四角形が連なっており
その四角形にマウスが乗ると色を変えたい
*.°質問したいこと
四角形が複数表示することろまで出来てます。
それ以降のマウスを四角形に乗ると色を変更するところでつまづいています。
クラスを使用し代入するところまで考えつき、
実践したのですが2日間悩んでもわからないため投稿させて頂きました。
※現段階ではエラー表示なし
主なソースとしては
(Form1)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace C_Level_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) { } private void pictureBox1_Click(object sender, EventArgs e) { Class1 person = new Class1(); //using System.Drawing; //描画先とするImageオブジェクトを作成する Bitmap canvas = new Bitmap(pictureBox1.Width, pictureBox1.Height); //ImageオブジェクトのGraphicsオブジェクトを作成する Graphics g = Graphics.FromImage(canvas); //Penオブジェクトの作成(幅1の黒色) //(この場合はPenを作成せずに、Pens.Blackを使っても良い) Pen p = new Pen(Color.Blue, 1); //3つの長方形の位置と大きさを配列に入れる for (int i = 20; i < 400; i++) { Rectangle[] recst = {new Rectangle(1, 10, 100, 100), new Rectangle(3, 12, 100, 100), new Rectangle(5, 14, 100, 100), new Rectangle(7, 16, 100, 100), new Rectangle(i,i,100,100), }; //3つの長方形を描く g.DrawRectangles(p, recst); Console.WriteLine("recst" + i); } //リソースを解放する p.Dispose(); g.Dispose(); //PictureBox1に表示する pictureBox1.Image = canvas; Console.WriteLine(); } } }
(class1)
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C_Level_1
{
class Class1
{
private string strpictureBox1;
private string strForeColor;
public virtual string pictureBox1 { get { return strpictureBox1; } set { strpictureBox1 = value; } } public virtual string ForeColor { get { return strForeColor; } set { strForeColor = value; } } public System.Drawing.Color BackColor { get; internal set; } public void pictureBox1_Mousemove(object sender, MouseEventArgs e) { this.BackColor = System.Drawing.Color.Red; } public class Application { public static void Run(Class1 class1) { Class1 person = new Class1(); System.Console.WriteLine(); Application.Run(new Class1()); } } public class MouseEventArgs { } }
}
お読み頂きまして有難うございます。
宜しくお願い致します!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/03 08:31