CodePanic! > C#.NET Tips > 今ここ
■文字列を縦に描画する
PictureBox内に文字列を縦に描画する例です。
頭に@が付く縦書き用フォントを利用することに注意です。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.BackColor = Color.White;
}
private void button1_Click(object sender, EventArgs e)
{
using (Graphics g = pictureBox1.CreateGraphics())
{
// 縦書き用フォントを利用
using (Font font = new Font("@MS ゴシック", 24))
{
// 縦方向にフォーマット
StringFormat sf = new StringFormat(StringFormatFlags.DirectionVertical);
g.DrawString("てすと", font, Brushes.Black, 10, 10, sf);
}
}
}
}
}
Copyright © 2008.07 - shougo suzaki
|