简体   繁体   English

使用 PaintEventHandler - Visual C++ (Studio 2010) Windows Forms 应用程序

[英]Using PaintEventHandler - Visual C++ (Studio 2010) Windows Forms Application

So, I am creating a Windows Forms Application in Visual C++ 2010, and I want to add an event to a text box.所以,我正在 Visual C++ 2010 中创建一个 Windows Forms 应用程序,并且我想在文本框中添加一个事件。 When the program loads, a letter A is printed onto the screen.当程序加载时,一个字母 A 会打印到屏幕上。 When you enter the text box, the letter is supposed to turn red.当您输入文本框时,该字母应该变为红色。

The name of the textbox is AngleA, and this is the code I have so far:文本框的名称是 AngleA,这是我到目前为止的代码:

this->AngleA->Enter += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::AngleA_Enter);
//many lines later
this->Controls->Add(this->AngleA);
//many lines later
public: System::Void Form1::AngleA_Enter(System::Object^  sender, PaintEventArgs^  e) 
     {
         System::Drawing::Font^ textFontA = gcnew System::Drawing::Font("Arial", 16);
         System::Drawing::SolidBrush^ textBrushA = gcnew System::Drawing::SolidBrush(Color::Red);
         e->Graphics->DrawString("A", textFontA, textBrushA, 300, 120);
     }

The original drawing of the letter happens in a separate function, here:这封信的原图发生在一个单独的 function 中,这里:

    public: virtual Void Form1::OnPaint(PaintEventArgs^ pe ) override
{
   Graphics^ g = pe->Graphics;

   System::Drawing::Font^ textFont = gcnew System::Drawing::Font("Times New Roman", 16);

   SolidBrush^ textBrushA = gcnew SolidBrush(Color::Black);

   g->DrawString("A", textFont, textBrushA, 300, 120);

}

So, the drawing of the original letter works great, but every time I try to build the program with the Enter event, I get the following error:因此,原始字母的绘制效果很好,但是每次我尝试使用 Enter 事件构建程序时,都会出现以下错误:

error C2664: 'System::Windows::Forms::Control::Enter::add' : cannot convert parameter 1 from 'System::Windows::Forms::PaintEventHandler ^' to 'System::EventHandler ^'
1>          No user-defined-conversion operator available, or
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

It seems to me that the form1 object (default name for class in windows forms apps) will only accept an EventHandler parameter for the "this->AngleA->Enter += gcnew " and not PaintEventHandler, but I dont understand why. It seems to me that the form1 object (default name for class in windows forms apps) will only accept an EventHandler parameter for the "this->AngleA->Enter += gcnew " and not PaintEventHandler, but I dont understand why. Is there any way to create an Enter event function that will allow me to paint after the program has already loaded, based on an event?有什么方法可以创建一个 Enter 事件 function 允许我在程序加载后根据事件进行绘画?

Thanks for the help, I hope I was clear in my question:)感谢您的帮助,我希望我的问题很清楚:)

You can only add a PaintEventHandler to the Paint event;您只能将PaintEventHandler添加到Paint事件; not to the Enter event.不是Enter事件。

You probably want to add a normal EventHandler to the Enter event and call Invalidate() in the handler.您可能希望向Enter事件添加一个普通的EventHandler并在处理程序中调用Invalidate()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Visual Studio 2010中向Windows窗体应用程序添加用户控件? - How do I add a user control to a Windows Forms application in Visual Studio 2010? 使用C#在Visual Studio中的3个Windows窗体之间传递数据 - passing data between 3 windows forms in visual studio using C# Visual Studio c ++ 2010中的参数 - Parameters in Visual Studio c++ 2010 是否有任何理由切换到Visual Studio 2010 for Windows Forms开发? - Is there any reason to switch to Visual Studio 2010 for Windows Forms development? 在 Windows Forms 应用程序中使用 C++/CLI 的命名空间混淆 - Namespace confusion using C++/CLI in Windows Forms Application 应用程序Windows窗体,Visual Studio 2012 - Application Windows Forms, Visual Studio 2012 无法使用 Windows 上的 Visual Studio Express 2010 在 ASP.Net MVC 应用程序中加载 Oracle 程序集 - Cannot Load Oracle Assembly in ASP.Net MVC Application using Visual Studio Express 2010 on Windows 7 Visual Studio 2013 Windows窗体应用程序无法在Windows 7上运行 - Visual Studio 2013 Windows forms application not working on windows 7 如何使用ClickOnce部署我的C#(4.0)Visual Studio 2010基于Windows窗体的应用程序? - How to use ClickOnce to deploy my C#(4.0)Visual studio 2010 windows form based Application? 使用Visual Studio 2012创建的C#Windows窗体应用程序无法在Windows XP上运行 - C# Windows forms app created using Visual Studio 2012 not working on windows xp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM