如何在我的表单中为图片框使用WndProc函数?我像这样试了试,但它不起作用,也没有任何消息发送给我的公众: virtual void WndProc( Message% m)
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace MyProject {
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void) {
InitializeComponent();
//TODO: Add the constructor code here
}
protected:
~Form1() {
if (components)
delete components;
}
private:
System::Windows::Forms::PictureBox^ pictureBox1;
System::ComponentModel::Container ^components;
void InitializeComponent(void) {
this->pictureBox1 = gcnew System::Windows::Forms::PictureBox();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(
this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Location = System::Drawing::Point(41, 27);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(206, 203);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 265);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(
this->pictureBox1))->EndInit();
this->ResumeLayout(false);
}
};
ref class pictureBox1 : PictureBox {
public:
virtual void WndProc( Message% m ) override {
__super::WndProc(m);
}
};
}//close NameSpace发布于 2011-01-26 23:17:17
SLaks提供的答案是正确的,我100%同意他的意见,即您需要理解代码的含义,而不是从Stack Overflow复制和粘贴一个神奇的代码片段。
但是我看到您仍然在抱怨应该如何编写代码来使用您的自定义PictureBox类(覆盖了WndProc函数的类),而不是内置的类。将所有对System::Windows::Forms::PictureBox的引用更改为pictureBox1 (您的自定义类)实际上很简单。当然,您需要更改其中之一的名称,但我建议您为所有内容选择比默认名称更好的名称。
例如,尝试执行以下操作:
namespace MyProject {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: pictureBox1^ myPictureBox;
protected:
private:
System::ComponentModel::Container ^components;
void InitializeComponent(void)
{
this->myPictureBox = (gcnew pictureBox1());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->myPictureBox))->BeginInit();
this->SuspendLayout();
//
// myPictureBox
//
this->myPictureBox->Location = System::Drawing::Point(41, 27);
this->myPictureBox->Name = L"myPictureBox";
this->myPictureBox->Size = System::Drawing::Size(206, 203);
this->myPictureBox->TabIndex = 0;
this->myPictureBox->TabStop = false;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 265);
this->Controls->Add(this->myPictureBox);
this->Name = L"Form1";
this->Text = L"Form1";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->myPictureBox))->EndInit();
this->ResumeLayout(false);
}
};
ref class pictureBox1 : PictureBox {
//protected:
public:
virtual void WndProc( Message% m ) override {
__super::WndProc(m);
}
};
}//close NameSpacehttps://stackoverflow.com/questions/4805400
复制相似问题