以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  在论 异形窗口透明化窗口  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=50536)

--  作者:打错潇洒
--  发布时间:2014/5/8 14:30:00
--  在论 异形窗口透明化窗口
今天逛技术论坛 看到有一个 神人(比我厉害的我都称之为神人) 贴出一个代码,用C#创建一个异形的窗口。

狐表论坛早就有了有关于异形的窗口创建的案例

案例里面的两种方案 都有缺陷
方案1: e.Form.BaseForm.TransparencyKey = Color.Black
具有清除不干净的缺陷,但是简单好用。
方案2: 
Dim frm As System.Windows.Forms.Form = e.Form.BaseForm
path.AddArc(frm .ClientRectangle, 190, 90)
path.AddLine(frm .Right, frm .Top + 50, frm .Left + 100, frm .Bottom)
path.CloseFigure()
frm.Region = new Region(path)
具有难度高的缺点,使用GDI绘制,容易造成绘制复杂图形,思维与代码混乱。但是绘制的窗体整洁

而我今天要推荐的是集合上述两点优势 简单好用

图片点击可在新窗口打开查看此主题相关图片如下:1.jpg
图片点击可在新窗口打开查看


已经简单的封装了,回复下载就可以用的


以下内容只有回复后才可以浏览









----------下面的代码是求帮忙翻译的-----------




但是这里面也有问题:
以下内容为程序代码:

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.Drawing.Drawing2D;
9
10 namespace WindowsFormsApplication1
11 {
12 public partial class Form1 : Form
13 {
14 public Form1()
15 {
16 InitializeComponent();
17 }
18
19 private void Form1_Load(object sender, EventArgs e)
20 {
21 ///<summary>
22 /// 设置不规则窗体
23 ///</summary>
24 ///<param name="sender"></param>
25 ///<param name="e"></param>
26
27 //从指定的位图中获取alpha透明度大于 10 的区域
28 Bitmap img = (Bitmap)pictureBox1.Image;
29 GraphicsPath grapth = GetNoneTransparentRegion(img, 155);
30 this.Region = new Region(grapth);
31
32 //要显示的图片设置为窗体背景
33 this.BackgroundImage = pictureBox1.Image;
34 this.BackgroundImageLayout = ImageLayout.Zoom;
35
36 //在修改窗体尺寸之前设置窗体为无边框样式
37 this.FormBorderStyle = FormBorderStyle.None;
38 this.Width = pictureBox1.Image.Width;
39 this.Height = pictureBox1.Image.Height;
40 }
41 ///<summary>
42 /// 返回指定图片中的非透明区域(方法)
43 ///</summary>
44 ///<param name="img">位图</param>
45 ///<param name="alpha">alpha 小于等于该值的为透明</param>
46 ///<returns></returns>
47 public static GraphicsPath GetNoneTransparentRegion(Bitmap img, byte alpha)
48 {
49 int height = img.Height;
50 int width = img.Width;
51 int xStart, xEnd;
52 GraphicsPath grpPath = new GraphicsPath();
53 for (int y = 0; y < height; y++)
54 {
55 //逐行扫描
56 for (int x = 0; x < width; x++)
57 {
58 //略过连续透明的部分
59 while (x < width && img.GetPixel(x, y).A <= alpha)
60 {
61 x++;
62 }
63 //不透明部分;
64 xStart = x;
65 while (x < width && img.GetPixel(x, y).A > alpha)
66 {
67 x++;
68 }
69 xEnd = x;
70 if (img.GetPixel(x - 1, y).A > alpha)
71 {
72 grpPath.AddRectangle(new Rectangle(xStart, y, xEnd - xStart, 1));
73 }
74 }
75 }
76 return grpPath;
77 }
78 }
79 }
80

GetNoneTransparentRegion 方法中狐表里翻译之后出现的情况是X参数错误,还求高手帮助

[此贴子已经被作者于2014-5-8 14:43:31编辑过]

--  作者:ybil
--  发布时间:2014/5/8 14:55:00
--  
樓主喜歡走不尋常路
--  作者:blackzhu
--  发布时间:2014/5/8 14:57:00
--  
看看
--  作者:lsy
--  发布时间:2014/5/8 15:01:00
--  
哪儿热闹哪有我。
--  作者:打错潇洒
--  发布时间:2014/5/8 15:06:00
--  
还是菜鸟 刚刚飞  学习学习,多接触一些 比较有想法的代码算法 有益身心健康图片点击可在新窗口打开查看
--  作者:hanxuntx
--  发布时间:2014/5/8 15:08:00
--  

小手一抖,积分拿走

图片点击可在新窗口打开查看


--  作者:有点甜
--  发布时间:2014/5/8 15:09:00
--  
 挺好...
--  作者:jspta
--  发布时间:2014/5/8 15:58:00
--  
学习下
--  作者:hws005
--  发布时间:2014/5/8 16:03:00
--  
支持!顶起
--  作者:zyqzyy
--  发布时间:2014/5/8 17:42:00
--  
顶!