我正在使用VS2015,Windows窗体应用程序。我希望以垂直方向显示我的文本。为此,我在c#中找到了一个类。因此,我希望将该类从c#转换为c++/cli。谢谢。
我的标签类别()
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);
}
}
我试着从我这边把它转换成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
和我的标签. 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.h的get、set和MyLabel.cpp的DrawString()再次感谢
1条答案
按热度按时间ddrv8njm1#
MyLabel.h
MyLabel.cpp
感谢Jimi和Wohlstad..你们的评论对我帮助很大!再次感谢!