转自:http://www.cnblogs.com/LonelyShadow/p/3893743.html

C#以两种方法实现文字阴影效果,同时还实现了简单的动画效果:
  一种是对文本使用去锯齿的边缘处理,在两个不同的位置绘制文本,形成阴影;
  另一个是以阴影为线条,构造影线画刷,先画背景再画前景,使用graphics.DrawString来绘制文字的阴影。

实现效果如下:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Windows.Forms; namespace Guying.Project.DrawFontShadow
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics graphics = e.Graphics;
graphics.Clear(Color.White);
//对文本使用去锯齿的边缘处理
FontFamily fontFamily = new FontFamily("宋体");
Font font = new Font(fontFamily, , FontStyle.Bold, GraphicsUnit.Pixel);
//文本输出框
RectangleF textout = new RectangleF(font.Height, this.ClientSize.Height / , this.ClientSize.Width, this.ClientSize.Height);
//在两个不同的位置绘制文本,形成阴影
//solidBrush的色彩透明度为100,暗黑
SolidBrush solidBrush = new SolidBrush(Color.FromArgb(, Color.Black));
SolidBrush redBrush = new SolidBrush(Color.Blue);
graphics.DrawString("孤影", font, solidBrush,
new PointF(27.0f, 27.0f));
graphics.DrawString("孤影", font, redBrush,
new PointF(12.0f, 20.0f));
//另一种阴影字,阴影为线条
//构造影线画刷
HatchBrush brush_tmp = new HatchBrush(
HatchStyle.DarkDownwardDiagonal, Color.Black, Color.White);
int reptime = ;
//先画背景
for (int i = ; i < reptime; i++)
graphics.DrawString("您好", font, brush_tmp,
new PointF(textout.X + i + , textout.Y + i + ));
//再画前景
graphics.DrawString("您好", font, Brushes.Blue, new PointF(textout.X, textout.Y));
}
} 使用Graphics绘制字体阴影

【转】WinForms 使用Graphics绘制字体阴影的更多相关文章

  1. WinForms 使用Graphics绘制字体阴影

    C#以两种方法实现文字阴影效果,同时还实现了简单的动画效果: 一种是对文本使用去锯齿的边缘处理,在两个不同的位置绘制文本,形成阴影: 另一个是以阴影为线条,构造影线画刷,先画背景再画前景,使用grap ...

  2. 解决html5 canvas 绘制字体、图片与图形模糊问题

    html5 canvas 绘制字体.图片与图形模糊问题 发生情况 多出现在高dpi设备,这意味着每平方英寸有更多的像素,如手机,平板电脑.当然很多高端台式电脑也有高分辨率高dpi的显示器. canva ...

  3. wpf设置字体颜色渐变和字体阴影

    <StackPanel Orientation="Horizontal" Grid.Column="1" HorizontalAlignment=&quo ...

  4. iOS圆角view的Swift实现(利用Core Graphics绘制)

    iOS圆角view的Swift实现(利用Core Graphics绘制) 因为app的列表用用到了圆形图片的头像,所以去探究并思考了一下这个问题.首先这个问题有两个方向的解决方案: 把图片弄成圆形的. ...

  5. css 字体阴影和边框阴影

    字体阴影 text-shadow: 2px 2px 2px #7a7e81; 边框阴影 box-shadow: 2px 2px 2px #7a7e81;

  6. 解决C# WinForm Graphics绘制闪烁问题

    不直接使用form的CreateGraphics创建Graphics进行绘制,可以先在Form上面放一个需要大小的PictureBox,再创建一个同大小的Bitmap,将这个Bitmap设置为Pict ...

  7. css3 text-shadow字体阴影讲解

    text-shadow:为字体添加阴影, 可以通过对text-shadow属性设置相关的属性值,来实现现一些需要的字体阴影效果,减少了图片的使用. 基础说明:    text-shadow: X轴  ...

  8. C#一例绘制字体不清晰的解决办法

    public static Bitmap GetPieWithText(String text, Color color, Color fontColor,Font font) { ; Bitmap ...

  9. Graphics绘制类及打印机设置相关

    Graphics 有两个多个方法 这里面介绍3个: 1.Graphics.drawString():绘制.画字符串........... e.Graphics.DrawString("新乡市 ...

随机推荐

  1. Arduino 101/Genuino101使用-第一篇

    1. 函数API说明文档在哪里? 2. 如果我想定义一个引脚做GPIO,不是库里有的. 3. digitalWrite(13, lighting); 这个函数里面 13代表的是啥? 4. setup( ...

  2. 移动端推广APP防作弊机制之依我见

    本文来自网易云社区 在广告投放过程中,虚假流量常常给广告运营人员带来麻烦,影响广告投放的效果,如何预防作弊,不妨先来重现一下流量产生的场景,用户点击广告之后,一般都会落到广告主的网页,或者安装广告主的 ...

  3. SOAPUI参数中xml中CDATA包含问题

    <![CDATA[ <Request> <CardNo>000002629518</CardNo> <SecrityNo/> <BankTr ...

  4. 【word基础】如何取消word首字母大写

  5. Intellij IDEA 热部署插件Jrebel激活

    激活前请确保已经安装好了Jrebel插件,本文通过反向代理激活. 第一步:下载激活工具(即代理工具),下载地址:https://github.com/ilanyu/ReverseProxy/relea ...

  6. (转)使用Python和OpenCV检测图像中的物体并将物体裁剪下来

    原文链接:https://blog.csdn.net/liqiancao/article/details/55670749 介绍 硕士阶段的毕设是关于昆虫图像分类的,代码写到一半,上周五导师又给我新的 ...

  7. Echarts-K线图提示框改头换面

    工作: 使用Hbuilder建web工程,加入echarts相关库,根据需要更改K线图及其的提示样式,去除默认提示,使用异步加载echarts的数据,数据格式为json. 需要注意的K线图和5日均线, ...

  8. 解决登录linux输入密码问题

    1.使用密钥 ssh-keyssh -i .ssh/*.key root@<ip_addr> 2.使用sshpass 安装 rpm 包:yum install sshpass 配置文件: ...

  9. Hyperledger_Fabric_Model

    Hyperledger_Fabric_Model 本部分描述了Hyperledger Fabric的主要设计特点 Assets: 资产定义使得任何东西都可以通过货币值在网络中交易,从食物到老爷车再到期 ...

  10. c# richBox内容转图片

    1.自定义控件,继承richBox public class RichTextBoxPrintCtrl : RichTextBox { //private const double anInch = ...