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. ckeditor4.5.11+ckfinder_java2.6.2配置

    http://blog.csdn.net/skyman1942/article/details/52537100 1.环境说明: 日期:2016-09-14 工具:ckeditor_4.5.11+ck ...

  2. linux安装spark-2.3.0集群

    (安装spark集群的前提是服务器已经配置了jdk并且安装hadoop集群(主要是hdfs)并正常启动,hadoop集群安装可参考<hadoop集群搭建(hdfs)>) 1.配置scala ...

  3. collections 模块常用方法学习

    前情提要: 1:模块介绍 个人认为就是 python自带的骚操作模块.如果基础能力够给力的话,完全用不到 个人认为解析式才是装逼神奇,用模块的都是伪娘 2:deque   双向列表 from coll ...

  4. 获取指定订阅下所有Azure ARM虚拟机配置(CPU核数,内存大小,磁盘信息)的使用情况

    脚本内容: <# .SYNOPSIS This script grab all ARM VM VHD file in the subscription and caculate VHD size ...

  5. php实现图片base64编码解码

    1.图片的base64编码 /*首先要确定图片的类型,需要安装一个php拓展php_fileinfo 如已安装可以在extension_dir目录下找到php_fileinfo.dll(windows ...

  6. java 实用Util汇总

    1.Util介绍 Util是工具的意思,一般来说,常常用来描述和业务逻辑没有关系的数据处理. Util一般要和私有方法对比:私有方法一般来说是只是在特地场景下使用的,私有方法越多,代码结构越乱.常见的 ...

  7. java ListNode链表数据结构

    class ListNode{ int val; ListNode next; } 该节点的值 val.   下一个节点  next

  8. springboot项目:Redis缓存使用

    保存Redis 第一步:启动类中加入注解 @EnableCaching package com.payease; import org.springframework.boot.SpringAppli ...

  9. javascript全局方法与变量

    1.encodeURI(URI) a.作用:是对统一资源标识符(URI)进行编码的方法: b.参数:是一个完整的URI: c.特点:不需要对保留字以及在URI中有特殊意思的字符进行编码. (1).保留 ...

  10. hibernate3.3.2搭建log4j日志环境

    日志的框架有很多,hibernate3.3.2用的是slf4j,slf4j简单理解为一个接口,标准.具体的实现可以是不同的实现(如slf4j自己的实现,log4j等).slf就像JDBC,JPA.自己 ...