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. Nginx采用yum安装-Carr

    (1)使用yum安装nginx需要包括Nginx的库,安装Nginx的库 #rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx- ...

  2. 利用python 学习数据分析 (学习二)

    内容学习自: Python for Data Analysis, 2nd Edition         就是这本 纯英文学的很累,对不对取决于百度翻译了 前情提要: 各种方法贴: https://w ...

  3. BootStrap Modal 点击空白时自动关闭

    本文为大家讲解的是如何禁用 BootStrap Modal 点击空白时自动关闭的方法,感兴趣的同学参考下. 方法如下 $('#myModal').modal({backdrop: 'static', ...

  4. L02-RHEL6.5环境中安装JDK1.8

    注: 1.本文安装的是jdk1.8,采用rpm包的方式安装. 2.rpm安装方式默认会把jdk安装到/usr/java/jdk1.8xxx 路径上,若想将JDK安装到特定路径,需以源码方式安装,可参考 ...

  5. python全栈开发_day16_包

    一:包 1)包就是管理一系列模块的文件夹 2)包中有一个__init__.py文件来专门管理每一个模块(在__init__文件中不建议import导入模块,不建议as起别名) 二:导入完成的工作 1) ...

  6. 在微信移动端input file拍照或从相册选择照片后会自动刷新页面退回到一开始网站进入的页面

    <input type="file" accept="image/*"/> 调用打开摄像头后,聚焦后拍照,点击确认,这时页面会出现刷新动作,然后回退 ...

  7. [转] etcd 搭建与使用

    [From] https://blog.csdn.net/ShouTouDeXingFu/article/details/81167302 etcd 1.下载etcd二进制文件包         ht ...

  8. Mac 10.12安装SVN工具SmartSVM 7.6

    说明:SVN工具没有最好的,只有用的最顺手的. 下载: (链接: https://pan.baidu.com/s/1dFGqEsT 密码: uyjx)

  9. Mac 10.12常用软件清单

    链接: https://pan.baidu.com/s/1slds1OD 密码: 7m5t 配套教程:http://www.cnblogs.com/EasonJim/tag/mac/ 如果失效了,联系 ...

  10. LeetCode-2. Add Two Numbers(链表实现数字相加)

    1.题目描述 You are given two non-empty linked lists representing two non-negative integers. The digits a ...