Iam使用VS2015,Windows窗体应用程序。我希望按垂直方向显示我的文本。为此,我在c#中找到了一个类。因此,我希望将类从c#转换为c++/cli。谢谢
myLabel-Class((
using System.Drawing;
class myLabel:System.Windows.Forms.Label
{
public int RotateAngle { get; set; } // to rotate your text
public string NewText { get; set; } // to draw text
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
Brush b =new SolidBrush(this.ForeColor);
e.Graphics.TranslateTransform(this.Width / 2, this.Height / 2);
e.Graphics.RotateTransform(this.RotateAngle);
e.Graphics.DrawString(this.NewText, this.Font,b , 0f, 0f);
base.OnPaint(e);
}
}
我试着从myside将其转换为c++/cli,如下所示,有人能帮我纠正吗?谢谢MyLabel.h
#ifndef MyLabel_H
#define MyLabel_H
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class MyLabel : Label
{
public:
property int RotateAngle {
int get() { return RotateAngle; }
void set(int value) { RotateAngle = value; }
}
property String^ NewText {
String^ get() { return NewText; }
void set(String^ value) { NewText = value; }
}
protected:
virtual bool OnPaint(PaintEventArgs keydata) override;
};
#endif
和MyLabel.cpp
#include "MyLabel.h"
using namespace System::Drawing;
using namespace System::Windows::Forms;
bool MyLabel::OnPaint(PaintEventArgs^ keydata) {
Brush^ b = gcnew SolidBrush(this->ForeColor);
keydata->Graphics->TranslateTransform(this->Width / 2, this->Height / 2);
keydata->Graphics->RotateTransform(this->RotateAngle);
keydata->Graphics->DrawString(this->NewText, this->Font, b, 0f, 0f);
Label::OnPaint(keydata);
}
注意:从上面的代码中,我不清楚MyLabel.hget、set和MyLabel.cpp DrawString((再次感谢
MyLabel.h
#ifndef MyLabel_H
#define MyLabel_H
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class MyLabel : Label
{
public: property float RotateAngle;
public: property System::String^ NewText;
protected:
virtual void OnPaint(PaintEventArgs^ keydata) override;
};
#endif
MyLabel.cpp
#include "MyLabel.h"
using namespace System::Windows::Forms;
void MyLabel::OnPaint(PaintEventArgs^ keydata) {
Brush^ b = gcnew SolidBrush(this->ForeColor);
keydata->Graphics->TranslateTransform(this->Width / 2, this->Height / 2);
keydata->Graphics->RotateTransform(this->RotateAngle);
keydata->Graphics->DrawString(this->NewText, this->Font, b, .0F, .0F);
Label::OnPaint(keydata);
}
感谢吉米;沃尔斯塔德。。你的评论对我帮助很大!再次感谢!