掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
pictureBoxへの描画について (ID:71011)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
Visual C++2008 Express Editionを使用しています。 フォーム上にpictureBoxを置いて、四角い枠を描画 させようとしています。ボタン1でサイズの変更しています。 Graphicsオブジェクトを取得するのに2つの方法を試すと 下記の e->Graphics のほうは思ったとおり描画されますが、 gr のほうは、paintイベント、Refreshメソッドでは描画 されません。 ボタン2での gr での描画は可能です。 e のほうを使用すればいいのですが、この差が何か知りたい と思い質問させていただきました。お願いします。 ------------------------------------------------------- public ref class Form1 : public System::Windows::Forms::Form { <略> private: Graphics^ gr; int w, h; <略> private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { gr = pictureBox1->CreateGraphics(); w = 100; h = 80; } private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { gr->DrawRectangle(Pens::Gray, 20, 20, w, h); //その1 e->Graphics->DrawRectangle(Pens::Red, 10, 10, w, h);//その2 } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { w = 200; h = 160; //描画する枠のサイズ変更 this->pictureBox1->Refresh(); } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { gr->DrawRectangle(Pens::Gray, 20, 20, w, h); } };
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.