急救 小球脱离主窗体,单独在桌面上显示,困了我很久的,各位弟兄多多帮忙,兄弟先行谢过!
就是去行的时候,只看到一个小球在桌面上就可以了,我用以下代码只能实现小球在一个正方形的方框内,没不是单独的,请各位高手多多帮忙,兄弟感激不尽.谢谢!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace yixingtu
{
     public partial class MainForm : Form
     {
         public MainForm()
         {
             InitializeComponent();
         }
         private Region BmpRgn(Bitmap Picture, Color TransparentColor)
         {
             int nWidth = Picture.Width;
             int nHeight = Picture.Height;
             Region rgn = new Region();
             rgn.MakeEmpty();
             bool isTransRgn;//前一个点是否在透明区
             Color curColor;//当前点的颜色
             Rectangle curRect = new Rectangle();
             curRect.Height = 1;
             int x = 0, y = 0;
             //逐像素扫描这个图片,找出非透明色部分区域并合并起来。
             for (y = 0; y < nHeight; ++y)
             {
                 isTransRgn = true;
                 for (x = 0; x < nWidth; ++x)
                 {
                     curColor = Picture.GetPixel(x, y);
                     if (curColor == TransparentColor || x == nWidth - 1)//如果遇到透明色或行尾
                     {
                         if (isTransRgn == false)//退出有效
                         {
                             curRect.Width = x - curRect.X;
                             rgn.Union(curRect);
                         }
                     }
                     else//非透明色
                     {
                         if (isTransRgn == true)//进入有效区
                         {
                             curRect.X = x;
                             curRect.Y = y;
                         }
                     }//if curColor
                     isTransRgn = curColor == TransparentColor;
                 }//for x
             }//for y
             return rgn;
         }
         private void Form1_Load(object sender, EventArgs e)
         {             
         }
         private void button1_Click(object sender, EventArgs e)
         {
             this.Region = BmpRgn(new Bitmap("d:\\a.gif"), Color.FromArgb(0, 0, 0));
         }
     }
}
------解决方案--------------------需要这么深奥么……
如果只是满足你开始说的要求的话,是不是可以考虑:
1. 做一个没有边框的Form
2. Form的TransparencyKey属性设置为你指定的颜色(可以在设计器里设,也可以用编码动态设)。
3. 放一个PictureBox。把小球的图片加载上。
4. 调整合适的大小。
然后不就OK了?
------解决方案--------------------http://www.cnblogs.com/pcant/articles/1132905.html
------解决方案--------------------C#根据图片创建不规则窗体
http://so.blogchinese.com/06042/202595/archives/2006/200642518142.html
------解决方案--------------------看看以前的一个古老帖子
http://topic.csdn.net/t/20060322/17/4632557.html
------解决方案--------------------我试了很正常啊,关键是透明色,你用画笔存绿色画一个原,其他地方都是白的,然后透明色取bmp.getpixel(0,0)就出来个原了