資源簡介
使用C#真正實現(xiàn)的透明控件,不是什么透明色或者仿背景色,直接把目標(biāo)顏色給扣掉了,使用的是UI區(qū)域裁剪自定義方法,積分可能漲

代碼片段和文件信息
using?System;
using?System.Drawing;
using?System.Runtime.InteropServices;
using?System.Text;
using?System.Windows.Forms;
using?System.Drawing.Drawing2D;
using?System.Drawing.Imaging;
namespace?UControlTran
{
????public?static?class?APub
????{
????????static?APub()
????????{?
????????}
????????///?
????????///?根據(jù)圖片計算GraphicsPath路徑(低效率)
????????///?
????????///?圖像資源
????????///?欲透明掉的顏色
????????///?路徑畫布已過濾掉了透明顏色
????????public?static?GraphicsPath?ImageToGraphicsPath(Image?imgxColor?TranColor)
????????{
????????????if?(imgx?==?null)?return?null;
????????????GraphicsPath?g?=?new?GraphicsPath(FillMode.Alternate);
????????????Bitmap?bitmap?=?null;
????????????if?(typeof(Bitmap)?==?imgx.GetType())
????????????????bitmap?=?(Bitmap)imgx;
????????????else
????????????????bitmap?=?new?Bitmap(imgx);
????????????int?ImWidth?=?bitmap.Width;
????????????int?ImHeight?=?bitmap.Height;
????????????Color?curColor;
????????????Rectangle?curRect?=?new?Rectangle();
????????????curRect.Height?=?1;
????????????bool?isTransRgn;
????????????for?(int?y?=?0;?y?????????????{
????????????????isTransRgn?=?true;
????????????????for?(int?x?=?0;?x?????????????????{
????????????????????curColor?=?bitmap.GetPixel(x?y);
????????????????????if?(curColor?==?TranColor?||?x?==?ImWidth?-?1)//如果遇到透明色或行尾
????????????????????{
????????????????????????if?(isTransRgn?==?false)//退出有效區(qū)
????????????????????????{
????????????????????????????curRect.Width?=?x?-?curRect.X;
????????????????????????????g.AddRectangle(curRect);
????????????????????????}
????????????????????}
????????????????????else//非透明色
????????????????????{
????????????????????????if?(isTransRgn?==?true)//進(jìn)入有效區(qū)
????????????????????????{
????????????????????????????curRect.X?=?x;
????????????????????????????curRect.Y?=?y;
????????????????????????}
????????????????????}//if?curColor
????????????????????isTransRgn?=?curColor?==?TranColor;?????
????????????????}
????????????}
????????????return?g;
????????}
????????///?
????????///?根據(jù)圖片計算Region路徑(低效率)
????????///?
????????///?圖像資源
????????///?欲透明掉的顏色
????????///?一個離散的路徑信息
????????public?static?Region?ImageToRegion(Image?imgx?Color?TranColor)
????????{
????????????if?(imgx?==?null)?return?null;
????????????Region?rRegion?=?new?Region();
????????????rRegion.MakeEmpty();
????????????Bitmap?bitmap?=?null;
????????????if?(typeof(Bitmap)?==?imgx.GetType())
????????????????bitmap?=?(Bitmap)imgx;
????????????else
????????????????bitmap?=?new?Bitmap(imgx);
????????????int?ImWidth?=?bitmap.Width;
????????????int?ImHeight?=?bitmap.Height;
????????????Color?curColor;
????????????Rectangle?curRect?=?new?Rectangle();
????????????curRect.Height?=?1;
????????????bool?isTransRgn;
????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????926??2017-02-07?15:41??UControlTran.sln
?????文件???????7207??2017-02-07?16:31??UControlTran\APub.cs
?????文件?????124416??2017-02-07?16:28??UControlTran\bin\Debug\UControlTran.exe
?????文件??????34304??2017-02-07?16:28??UControlTran\bin\Debug\UControlTran.pdb
?????文件??????14328??2017-02-07?16:28??UControlTran\bin\Debug\UControlTran.vshost.exe
?????文件????????362??2017-02-07?16:02??UControlTran\Form1.cs
?????文件???????3092??2017-02-07?16:02??UControlTran\Form1.Designer.cs
?????文件???????5814??2017-02-07?16:02??UControlTran\Form1.resx
?????文件???????4608??2017-02-07?15:54??UControlTran\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
?????文件????????615??2017-02-07?16:28??UControlTran\obj\Debug\UControlTran.csproj.FileListAbsolute.txt
?????文件????????883??2017-02-07?16:02??UControlTran\obj\Debug\UControlTran.csproj.GenerateResource.Cache
?????文件?????124416??2017-02-07?16:28??UControlTran\obj\Debug\UControlTran.exe
?????文件????????180??2017-02-07?16:27??UControlTran\obj\Debug\UControlTran.Form1.resources
?????文件??????34304??2017-02-07?16:28??UControlTran\obj\Debug\UControlTran.pdb
?????文件?????113412??2017-02-07?16:27??UControlTran\obj\Debug\UControlTran.Properties.Resources.resources
?????文件????????493??2017-02-07?15:41??UControlTran\Program.cs
?????文件???????1374??2017-02-07?15:41??UControlTran\Properties\AssemblyInfo.cs
?????文件???????3085??2017-02-07?15:54??UControlTran\Properties\Resources.Designer.cs
?????文件???????6192??2017-02-07?15:54??UControlTran\Properties\Resources.resx
?????文件???????1097??2017-02-07?15:41??UControlTran\Properties\Settings.Designer.cs
?????文件????????249??2017-02-07?15:41??UControlTran\Properties\Settings.settings
?????文件?????112946??2017-02-07?15:54??UControlTran\Resources\90.bmp
?????文件???????4149??2017-02-07?16:27??UControlTran\UControlTran.csproj
?????文件????????803??2017-02-07?16:28??UControlTran\UserControl1.cs
?????文件???????1123??2017-02-07?15:54??UControlTran\UserControl1.Designer.cs
?????目錄??????????0??2017-02-07?15:43??UControlTran\obj\Debug\Refactor
?????目錄??????????0??2017-02-07?15:54??UControlTran\obj\Debug\TempPE
?????目錄??????????0??2017-02-07?15:56??UControlTran\bin\Debug
?????目錄??????????0??2017-02-07?16:28??UControlTran\obj\Debug
?????目錄??????????0??2017-02-07?15:42??UControlTran\bin
............此處省略8個文件信息
評論
共有 條評論