C# 实现文子从上到下,从右到左
对OnPaint()方法的重写:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OverrideOnPaint
{
public partial class Form1 : Form
{
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Rectangle r = new Rectangle(new Point(40, 40), new Size(70, 70));
StringFormat f = new StringFormat(StringFormatFlags.DirectionRightToLeft | StringFormatFlags.DirectionVertical);
e.Graphics.DrawRectangle(Pens.Green, r);
e.Graphics.DrawString("祝大家国庆节快乐!", Font, Brushes.Blue, (RectangleF)r, f);
}
public Form1()
{
InitializeComponent();
}
}
}
本文介绍了一种使用C#实现文字从上到下、从右到左显示的方法。通过对OnPaint()方法进行重写,利用Graphics类的DrawString方法结合StringFormat属性设置文字的方向为垂直并从右向左显示。
1万+

被折叠的 条评论
为什么被折叠?



