c#用GDI+绘制文字,实现选择其中一个字符功能 c#用GDI+绘制文字(DrawString),实现选择其中一个字符功能如图:大家看看怎么实现?不用TextBox等控件。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本帖最后由 bdmh 于 2012-05-03 16:47:40 编辑 写了一个代码,但是有些偏差。 private void SelectText(string text,int selectindex) { if (string.IsNullOrEmpty(text)) { new ArgumentNullException("text", "不能为空"); } Bitmap parent = (Bitmap)Image.FromFile("1.jpg"); Graphics parentgp = Graphics.FromImage(parent); parentgp.PageUnit = GraphicsUnit.Pixel; Font f = new Font("宋体", 300); SizeF sizesingle = parentgp.MeasureString(text[0].ToString (), f); SizeF sizesub = parentgp.MeasureString(text.Substring(0, selectindex), f); float width = sizesingle.Width * ( 2.0F /3.0F ); float height = sizesingle.Height; float x = (sizesub.Width - sizesingle.Width ) + ((sizesingle.Width - width) / 2.0f); //float x = sizesingle.Width * (selectindex - 1) + ((sizesingle.Width - width) / 2.0f); ; float y = 0.0f; parentgp.FillRectangle(new SolidBrush(Color.Blue), new RectangleF(x, y, width, height)); parentgp.DrawString(text, f, new SolidBrush(Color.Black), 0.0F, 0.0F); this.pictureBox1.Image = parent; } VS2005.NET编写的组建COM注册regasm时出错误,RegAsm : error RA0000 : 未能加载文件或程序集“DevExpress.Data.v6.3, 序列化的一个问题 怎么判断固定时间内没有出发时间 如何解决richlistbox中文乱码问题 求一正则表达 c的结构在c#怎么定义? 如何在WPF做画坐标,并且可以让这三维坐标系的轴会随着鼠标移动而转动? C#如何去开发windows自带的远程桌面连接这个软件? 关于 .net remoting 中远程对象SingleCall自动回收问题 初学.net数据库问题,希望用c#解答 关于用户组件内访问父窗体的问题! 使用webchart怎样把一个二维数组中的值图上显示?
private void SelectText(string text,int selectindex)
{ if (string.IsNullOrEmpty(text))
{
new ArgumentNullException("text", "不能为空");
} Bitmap parent = (Bitmap)Image.FromFile("1.jpg");
Graphics parentgp = Graphics.FromImage(parent);
parentgp.PageUnit = GraphicsUnit.Pixel; Font f = new Font("宋体", 300); SizeF sizesingle = parentgp.MeasureString(text[0].ToString (), f); SizeF sizesub = parentgp.MeasureString(text.Substring(0, selectindex), f); float width = sizesingle.Width * ( 2.0F /3.0F );
float height = sizesingle.Height; float x = (sizesub.Width - sizesingle.Width ) + ((sizesingle.Width - width) / 2.0f);
//float x = sizesingle.Width * (selectindex - 1) + ((sizesingle.Width - width) / 2.0f); ; float y = 0.0f; parentgp.FillRectangle(new SolidBrush(Color.Blue), new RectangleF(x, y, width, height)); parentgp.DrawString(text, f, new SolidBrush(Color.Black), 0.0F, 0.0F); this.pictureBox1.Image = parent;
}