using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace ExerciseUIPrj.controls
{
public partial class CustomControl1 : Control
{ Rectangle picRec = new Rectangle();
Rectangle NameRec = new Rectangle();
Rectangle DirRec = new Rectangle();
Rectangle BtnRec = new Rectangle();
Rectangle BtnRec1 = new Rectangle();
Rectangle TimeRec = new Rectangle();
Rectangle SizeRec = new Rectangle(); public CustomControl1()
{
InitializeComponent();
BackColor = Color.White;
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
Size txtSize = TextRenderer.MeasureText("abc", Font);
int pwid = txtSize.Height * + ;
int y =(int) ((Height - pwid) / 2.0);
Point p = new Point(, y);
picRec = new Rectangle(p, new Size(pwid, pwid));
int txtwid = (int)(Width / 2.0);
NameRec = new Rectangle(new Point(p.X+picRec.Width + , p.Y), new Size(txtwid, txtSize.Height));
DirRec = new Rectangle(new Point(p.X + picRec.Width +, p.Y+txtSize.Height+), new Size(txtwid, txtSize.Height));
BtnRec = new Rectangle(new Point(NameRec.Location.X + NameRec.Width + , NameRec.Y + (int)(txtSize.Height/2.0)), new Size(txtSize.Height,txtSize.Height));
BtnRec1 = new Rectangle(new Point(NameRec.Location.X + DirRec.Width + +txtSize.Width+, NameRec.Y + (int)(txtSize.Height / 2.0)), new Size(txtSize.Height, txtSize.Height));
TimeRec = new Rectangle(new Point(BtnRec1.Location.X + txtSize.Width + , NameRec.Y), new Size(Width-picRec.Width-NameRec.Width-BtnRec.Width*-*, txtSize.Height));
SizeRec = new Rectangle(new Point(BtnRec1.Location.X + txtSize.Width + , NameRec.Y+txtSize.Height+), new Size(Width - picRec.Width - NameRec.Width - BtnRec.Width * - * , txtSize.Height)); } protected override void OnPaint(PaintEventArgs pe)
{ var g = pe.Graphics;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.FillRectangle(Brushes.Red, picRec);//图标 var t1 = "这是一句测试文档";
var t2 = "这是一句测试文档这是一句测试文档这是一句测试文档这是一句测试文档这是一句测试文档这是一句测试文档这是一句测试文档这是一句测试文档";
DrawTxt(t1, g, NameRec, "这");
DrawTxt(t2, g, DirRec, "这");
g.FillRectangle(Brushes.Green, BtnRec);
g.FillRectangle(Brushes.Blue, BtnRec1);
var t3 = string.Format("修改时间:{0}",DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
var t4 = "文件大小:4555KB";
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Near;
g.DrawString(t3, Font, Brushes.Black, TimeRec,sf);
g.DrawString(t4, Font, Brushes.Black, SizeRec,sf); base.OnPaint(pe); }
void DrawTxt(string s, Graphics g, Rectangle rect,string key)
{
string[] ress = s.Split(key.ToCharArray()); List<string> res = new List<string>();
if (s.StartsWith(key))
res.Add(key);
if (ress.Length > )
{
foreach (var r in ress)
{
if (string.IsNullOrEmpty(r))
continue;
res.Add(r);
res.Add(key);
}
if (!s.EndsWith(key))
res.RemoveAt(res.Count - );
}
else
{
res.Add(s);
} StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Near;
sf.Trimming = StringTrimming.EllipsisCharacter; int cwid = ;
for (int i = ; i < res.Count; i++)
{
int wid = TextRenderer.MeasureText(g, res[i], Font,new Size(),TextFormatFlags.NoPadding|TextFormatFlags.NoPrefix).Width;
Brush b = res[i] == key ? Brushes.Red : Brushes.Black;
int x = cwid+wid;
if(x>=rect.Width)
{
wid = rect.Width - cwid;
RectangleF rec = new RectangleF(new PointF(rect.Location.X+cwid,rect.Y), new SizeF(wid, rect.Height));
g.DrawString(res[i], Font, b, rec, sf);
break;
}
else
{
g.DrawString(res[i], Font, b, new Point(rect.Location.X + cwid, rect.Y), sf);
}
cwid += wid; }
}
}
}

用自带的控件堆出来的用户控件放在flowlayotpanel里边多了滚动的时候闪的厉害·,这里就用自己画一个··顺便解决特殊字符不同颜色显示的问题··这个堆多了好像也会闪烁···在panel里边堆200个就会闪····应该还是得做分页·····好麻烦···

用windowsbase里边的库压文件夹为zip文件

        public static bool PackageFolder(string folderName, string compressedFileName, bool overrideExisting)
{
if (folderName.EndsWith(@"\"))
folderName = folderName.Remove(folderName.Length - );
bool result = false;
if (!Directory.Exists(folderName))
{
return result;
}
if (!overrideExisting && File.Exists(compressedFileName))
{
return result;
}
try
{
using (Package package = Package.Open(compressedFileName, FileMode.Create))
{
var fileList = Directory.EnumerateFiles(folderName, "*", SearchOption.AllDirectories);
foreach (string fileName in fileList)
{
//The path in the package is all of the subfolders after folderName
string pathInPackage = Path.GetDirectoryName(fileName).Replace(folderName, string.Empty) + "/" + Path.GetFileName(fileName);
Uri partUriDocument = PackUriHelper.CreatePartUri(new Uri(pathInPackage, UriKind.Relative));
PackagePart packagePartDocument = package.CreatePart(partUriDocument, "", CompressionOption.Maximum);
using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
fileStream.CopyTo(packagePartDocument.GetStream());
}
Console.WriteLine("{0} done", fileName);
}
}
result = true;
}
catch (Exception e)
{
throw new Exception("Error zipping folder " + folderName, e);
} return result;
}

C#画个控件,指定字符特殊颜色显示的更多相关文章

  1. Lodop打印控件指定打印任务某几页

    使用Lodop打印控件进行打印开发,有时候一个任务里有多页,例如各种合同之类的,客户端用户在使用过程中,可能有某一页打印后发现需要修改,这时候不必再把整个任务重新打印一遍,只需要打印需要修改的那页重新 ...

  2. DevExpress相关控件中非字符数值居左显示

    用了这么长时间的DevExpress控件,今天遇到俩问题. 一个是从头到尾看了一遍编译成功的例子,只能感慨,功能太丰富了,自己所用的不过是冰山一角.有些自己一直想实现的效果,原来早就有现成的可用,汗颜 ...

  3. VC++使用WebBrowser控件,强制给控件指定版本显示网页

    转载:http://www.cnblogs.com/1175429393wljblog/p/5398928.html 最近为了抓取淘宝的成交数据,用C#的WebBrowser控件开发了一个简单的程序. ...

  4. Jquery设置select控件指定text的值为选中项

    <select name="streetid" id="streetid"> <option value="4">北 ...

  5. Qt 设置背景图片3种方法(QPalette可以做无数的事情,一旦控件指定了调色板,就要乖乖听它的话;QPainter当场绘制当然也没有问题,还有就是QSS)

    方法1. setStylSheet{"QDialog{background-image:url()"}}  //使用styleSheet 这种方法的好处是继承它的dialog都会自 ...

  6. Shape画圆形控件

    这里涉及到shape的运用,这仅仅是一个实例 circle.xml <?xml version="1.0" encoding="utf-8"?> & ...

  7. MSCHART控件中长字符的X轴坐标标注全部显示

    X轴坐标如果超过9位的话,就不能完全显示了,就会一个隔一个的显示,解决的办法: Chart1.ChartAreas[].AxisX.Interval = ; //设置X轴坐标的间隔为1 Chart1. ...

  8. 强制IE浏览器或WebBrowser控件使用指定版本显示网页

    自从装了IE10之后,就发现好些个网站显示都不是那么的正常,网站上有些功能竟然还会出现一些意想不到的BUG——本来就是针对IE开发的,现在IE下竟然用不起来了,让用户情何以堪?但是就为少量用户使用的系 ...

  9. Delphi 7学习开发控件(继承TGraphicControl只画一条线)

    我们知道使用Delphi快速开发,很大的一方面就是其强大的VCL控件,另外丰富的第三方控件也使得Delphi程序员更加快速的开发出所需要的程序.在此不特别介绍一些概念,只记录自己学习开发控件的步骤.假 ...

随机推荐

  1. 高性能缓存服务器Varnish

    一.Varnish概述 Varnish是一款高性能的.开源的反向代理服务器和缓存服务器,计算机系统的除了有内存外,还有CPU的L1.L2,甚至L3级别的缓存,Varnish的设计架构就是利用操作系统的 ...

  2. package.json和bower的参数解释

    package.json和bower的参数解释   一.package.json解释: package.json是用来声明项目中使用的模块,这样新的环境部署时,只要在package.json文件所在的 ...

  3. UVALive-7457-Discrete Logarithm Problem(取模运算)

    原题链接 额,一直在理解题意在纠结看不懂,后来才恍然大悟 题意:定义一种新运算 a × b = a * b mod p : 已知条件给定一个p 求 x 这里用到同余与模运算乘法公式:a * b % n ...

  4. 【3】JMicro微服务-服务超时,重试,重试间隔

    如非授权,禁止用于商业用途,转载请注明出处作者:mynewworldyyl 接下来的内容都基于[2]JMicro微服务-Hello World做Demo 微服务中,超时和重试是一个最基本问题下面Dem ...

  5. 3.3.1 Validations

    摘要: 出处:黑洞中的奇点 的博客 http://www.cnblogs.com/kelvin19840813/ 您的支持是对博主最大的鼓励,感谢您的认真阅读.本文版权归作者所有,欢迎转载,但请保留该 ...

  6. Swift中的Weak Strong Dance

    亲爱的博客园的关注着博主文章的朋友们告诉你们一个很不幸的消息哦, 这篇文章将会是博主在博客园发表的最后一篇文章咯, 因为之后的文章博主只会发布到这里哦 http://daiweilai.github. ...

  7. golang在gitlab中的工作流

    在敏捷开发的时代, 快速的编码, code review, 测试, 部署, 是提升程序员效率的关键. 同时在基础工具完备的如今, 我们甚至无需过多的操作就可以轻松实现上述步骤, 本文就以gitlab为 ...

  8. 【JSP】jsp报错:Syntax error, insert "}" to complete MethodBody

    使用MyEclipse编写JSP的时候有时会报错误如下 Syntax error, insert "}" to complete MethodBody 大体意思就是说方法体缺少缺少 ...

  9. 实现Date函数属性中的format方法

    js中没有Date.format方法的,所以在date属性中加format方法 //js格式化属性 Date.prototype.format = function (format) { var o ...

  10. Redis之hiredis API (String)

    String // // Created by zhangrongxiang on 2018/3/7 13:48 // File string2 // #include <hiredis/hir ...