如何在c#中使用矩形的抽象字符串中使用两种字体 [英] How to use two font in drawstring with rectangle in c#

查看:52
本文介绍了如何在c#中使用矩形的抽象字符串中使用两种字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  string  drawString =  代码项目; 
//
字体drawFont = new 字体( Arial 16 );
//
RectangleF drawRect = new RectangleF(x,y,width,height);
//
e.Graphics.DrawString(drawString,drawFont,Brush。黑色,drawRect);







如何在单个矩形中使用两种字体???



粗体字体中的代码和普通字体中的项目。



谢谢&问候

Manmohan Jha

解决方案

您似乎在使用Windows窗体。

请看这里:

  private   void  Form1_Paint(< span class =code-keyword> object  sender,PaintEventArgs e)
{
Font fontNormal = new 字体( Arial 16 );
Font fontBold = new 字体( Arial 16 ,FontStyle.Bold);

SolidBrush drawBrush = new SolidBrush(Color.Black);

e.Graphics.DrawString( Code,fontBold,drawBrush, new PointF( 0 0 )) ;
e.Graphics.DrawString( Project,fontNormal,drawBrush, new PointF( 60 0 ));
}



这将在粗体字体中绘制代码,在普通字体中绘制项目。

在表单上当Paint事件发生时。





中所定义https://msdn.microsoft.com/en-us/library/19sb1bw6(v=vs.110).aspx [ ^ ]

RectangleF结构指定绘制文本的位置。



如果你将两个字符串写入同一个矩形resp。位置

然后你会在同一个位置看到这两个字符串,因此不可读。



所以你可以认为这个解决方案是变通方法


string drawString="Code Project";
//
Font drawFont = new Font("Arial", 16);
//
RectangleF drawRect = new RectangleF(x, y, width, height);
//
e.Graphics.DrawString(drawString, drawFont, Brush.Black, drawRect);




How to use two font in single rectangle???

"Code" in Bold Font and "Project" in Normal Font.

Thanks & Regards
Manmohan Jha

解决方案

It seems that you are using Windows Forms.
Please have a look here:

private void Form1_Paint(object sender, PaintEventArgs e)
{
    Font fontNormal = new Font("Arial", 16);
    Font fontBold = new Font("Arial", 16, FontStyle.Bold);

    SolidBrush drawBrush = new SolidBrush(Color.Black);

    e.Graphics.DrawString("Code", fontBold, drawBrush, new PointF(0, 0));
    e.Graphics.DrawString("Project", fontNormal, drawBrush, new PointF(60, 0));
}


This will draw ""Code" in Bold Font and "Project" in Normal Font."
on your form when Paint event occured.

As defined in
https://msdn.microsoft.com/en-us/library/19sb1bw6(v=vs.110).aspx[^]
the RectangleF structure specifies the location of the drawn text.

If you write two strings into the same rectangle resp. location
then you will see these two strings on the same location and are therefore not readable.

So you can consider this solution as workaround.


这篇关于如何在c#中使用矩形的抽象字符串中使用两种字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆