C#画个控件,指定字符特殊颜色显示
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#画个控件,指定字符特殊颜色显示的更多相关文章
- Lodop打印控件指定打印任务某几页
使用Lodop打印控件进行打印开发,有时候一个任务里有多页,例如各种合同之类的,客户端用户在使用过程中,可能有某一页打印后发现需要修改,这时候不必再把整个任务重新打印一遍,只需要打印需要修改的那页重新 ...
- DevExpress相关控件中非字符数值居左显示
用了这么长时间的DevExpress控件,今天遇到俩问题. 一个是从头到尾看了一遍编译成功的例子,只能感慨,功能太丰富了,自己所用的不过是冰山一角.有些自己一直想实现的效果,原来早就有现成的可用,汗颜 ...
- VC++使用WebBrowser控件,强制给控件指定版本显示网页
转载:http://www.cnblogs.com/1175429393wljblog/p/5398928.html 最近为了抓取淘宝的成交数据,用C#的WebBrowser控件开发了一个简单的程序. ...
- Jquery设置select控件指定text的值为选中项
<select name="streetid" id="streetid"> <option value="4">北 ...
- Qt 设置背景图片3种方法(QPalette可以做无数的事情,一旦控件指定了调色板,就要乖乖听它的话;QPainter当场绘制当然也没有问题,还有就是QSS)
方法1. setStylSheet{"QDialog{background-image:url()"}} //使用styleSheet 这种方法的好处是继承它的dialog都会自 ...
- Shape画圆形控件
这里涉及到shape的运用,这仅仅是一个实例 circle.xml <?xml version="1.0" encoding="utf-8"?> & ...
- MSCHART控件中长字符的X轴坐标标注全部显示
X轴坐标如果超过9位的话,就不能完全显示了,就会一个隔一个的显示,解决的办法: Chart1.ChartAreas[].AxisX.Interval = ; //设置X轴坐标的间隔为1 Chart1. ...
- 强制IE浏览器或WebBrowser控件使用指定版本显示网页
自从装了IE10之后,就发现好些个网站显示都不是那么的正常,网站上有些功能竟然还会出现一些意想不到的BUG——本来就是针对IE开发的,现在IE下竟然用不起来了,让用户情何以堪?但是就为少量用户使用的系 ...
- Delphi 7学习开发控件(继承TGraphicControl只画一条线)
我们知道使用Delphi快速开发,很大的一方面就是其强大的VCL控件,另外丰富的第三方控件也使得Delphi程序员更加快速的开发出所需要的程序.在此不特别介绍一些概念,只记录自己学习开发控件的步骤.假 ...
随机推荐
- ZooKeeper学习2---ZooKeeper安装配置
一.Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式. ■ 单机模式:Zookeeper只运行在一台服务器上,适合测试环境:■ 伪集群模式:就是在一台物 ...
- 安装openssl-devel
安装openssl-devel 0.操作系统为 RHEL6.7 1.描述:当开发人员需要调用openssl的库文件时,需要安装openssl-devel包 2.当根目录(即挂载点为 )的利用率为10 ...
- jee-oxygen版eclipse的安装与卸载 maven配置
Eclipse 是一个开放源代码的.基于Java的可扩展开发平台,是大部分JAVA编程学习者入门的编程工具.Eclipse 是开发java的一个工具,Eclipse需要JDK中的JRE支持才能启动,所 ...
- KCF+Opencv3.0+Cmake+Win10
配置 需要的文件下载 安装CMake,安装opencv3.0.0 在KCFcpp-master 目录下新建一个文件夹,命名为build 打开CMake-GUI配置如下: 点击Configure,编译器 ...
- SpringMVC 的 切面
官网路径:https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans 一:术语介绍 通知 ...
- 贪心--cf、education62-C
cf-Education 62-C 题目 C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes i ...
- spring boot快速入门 5: 事务管理
事务管理: 新增两名女生: 第一步:创建 GirlRespository package com.payease.service; import com.payease.entity.Girl; im ...
- 在JSP中常见问题,防止SpringMVC拦截器拦截js等静态资源文件的解决方案
方案一.拦截器中增加针对静态资源不进行过滤(涉及spring-mvc.xml) <mvc:resources location="/" mapping="/**/* ...
- Java源码安全审查
最近业务需要出一份Java Web应用源码安全审查报告, 对比了市面上数种工具及其分析结果, 基于结果总结了一份规则库. 本文目录结构如下: 检测工具 FindSecurityBugs 基于class ...
- CentOS和Ubuntu系统下安装 HttpFS (助推Hue部署搭建)
不多说,直接上干货! 我的集群机器情况是 bigdatamaster(192.168.80.10).bigdataslave1(192.168.80.11)和bigdataslave2(192.168 ...