【发布时间】:2014-12-16 12:36:40
【问题描述】:
我想创建一个 Picturebox,使其形状适应特定字体的字符串。我需要这个,以便以后可以创建文本并将其放置在 AxWindowsMediaPlayer 控件上。
因此我创建了以下类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
namespace myProject
{
class ShapedPictureBoxes : PictureBox
{
public ShapedPictureBoxes()
{
this.Paint += this.shapedPaint;
}
void shapedPaint(object sender, PaintEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
Font font = new Font("Arial", 14f);
float emSize = e.Graphics.DpiY*font.Size/72;
graphicsPath.AddString(text, new FontFamily("Arial"), (int)System.Drawing.FontStyle.Regular, emSize, new Point(0,0), new StringFormat());
e.Graphics.DrawString(text, font, Brushes.Red, new Point(0, 0));
this.Region = new Region(graphicsPath);
}
public string text = "Here comes the sun, doo da doo do";
}
}
现在的问题是,“Graphics.DrawString”与 graphicspath.AddString 不匹配,可能是因为 FontFamily 与 Font 不同。我怎样才能匹配它们?
那么:如何将 Fontfamily 转换为 Font 或反之亦然?
看起来是这样的:
【问题讨论】:
标签: c# fonts picturebox font-family