| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4785 人关注过本帖, 1 人收藏
标题:如何实现类似photoshop图层的功能显示透明图片
取消只看楼主 加入收藏
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
结帖率:50%
收藏(1)
已结贴  问题点数:10 回复次数:5 
如何实现类似photoshop图层的功能显示透明图片
各位大侠,谁知道:如何实现类似photoshop图层的功能显示透明图片?

我这里有几张透明图片,想实现类似photoshop图层的功能,点击显示就把要显示的那层显示出来,从而实现叠加的功能!!
搜索更多相关主题的帖子: photoshop 
2010-09-27 14:04
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:0 
大侠们,帮忙看看啊!!
2010-09-27 17:24
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:0 
试了一下,把他们的backcolor设成透明的,把后面的一张做成前面一张的parent也不行。无法实现叠加的效果,也不能想让任意一张显示就让任意一张显示的功能!!
2010-09-27 21:28
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:0 
经过一天的冥思苦想,终于实现了,和大家分享一下:
首先在控件内加入多个picturebox,把它们的backcolor都设成透明的,下面的picturebox其上面picturebox的paraent,这一点很重要,否则就无法实现图像所谓“叠加”的功能了,然后通过程序加载已经是png格式的图像到各个picturebox控件内实现“叠加”。

代码写的有点笨,哈哈,仅供参考:
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Drawing.Imaging;
using
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Cutters_layout
{
   
    public partial class Form1 : Form
    {
        public PictureBox[] pict = new PictureBox[8];
        public Form1()
        {
            InitializeComponent();
            SetStyle(ControlStyles.SupportsTransparentBackColor,true);
            picBox_b1.Parent = picBox_back;
            picBox_b2.Parent = picBox_b1;
            picBox_b3.Parent = picBox_b2;
            picBox_b4.Parent = picBox_b3;
            picBox_b5.Parent = picBox_b4;
            picBox_b6.Parent = picBox_b5;
            picBox_b7.Parent = picBox_b6;
            
            picBox_b1.BackColor = Color.Transparent;
            picBox_b2.BackColor = Color.Transparent;
            picBox_b3.BackColor = Color.Transparent;
            picBox_b4.BackColor = Color.Transparent;
            picBox_b5.BackColor = Color.Transparent;
            picBox_b6.BackColor = Color.Transparent;
            picBox_b7.BackColor = Color.Transparent;
            
        }

        private void checkbox(PictureBox pictBox, CheckBox checkboxNo)
        {
            
            string picRightName = pictBox.Name.ToString().Substring(pictBox.Name.Length - 1, 1);
            int pictNo = Convert.ToInt16(picRightName);
            if (checkboxNo.Checked == true)
            {
                pictBox.Image = pict[pictNo].Image;
            }
            else
            {
                pictBox.Image = null;
            }
            

        }
        


        private void checkBox_B1_CheckedChanged(object sender, EventArgs e)
        {

            checkbox(picBox_b1, checkBox_B1);
        }

        private void checkBox_B2_CheckedChanged(object sender, EventArgs e)
        {
            checkbox(picBox_b2, checkBox_B2);
        }

        private void checkBox_B3_CheckedChanged(object sender, EventArgs e)
        {
            checkbox(picBox_b3, checkBox_B3);
        }

        private void checkBox_B4_CheckedChanged(object sender, EventArgs e)
        {
            checkbox(picBox_b4, checkBox_B4);
        }

        private void checkBox_B5_CheckedChanged(object sender, EventArgs e)
        {
            checkbox(picBox_b5, checkBox_B5);
        }

        private void checkBox_B6_CheckedChanged(object sender, EventArgs e)
        {
            checkbox(picBox_b6, checkBox_B6);
        }

        private void checkBox_B7_CheckedChanged(object sender, EventArgs e)
        {
            checkbox(picBox_b7, checkBox_B7);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            picBox_b1.Image.Save("pb1.png",ImageFormat.Png);
            Image b1 = Image.FromFile("pb1.png");
            picBox_b2.Image.Save("pb2.png", ImageFormat.Png);
            Image b2 = Image.FromFile("pb2.png");
            picBox_b3.Image.Save("pb3.png", ImageFormat.Png);
            Image b3 = Image.FromFile("pb3.png");
            picBox_b4.Image.Save("pb4.png", ImageFormat.Png);
            Image b4 = Image.FromFile("pb4.png");
            picBox_b5.Image.Save("pb5.png", ImageFormat.Png);
            Image b5 = Image.FromFile("pb5.png");
            picBox_b6.Image.Save("pb6.png", ImageFormat.Png);
            Image b6 = Image.FromFile("pb6.png");
            picBox_b7.Image.Save("pb7.png", ImageFormat.Png);
            Image b7 = Image.FromFile("pb7.png");
            
            string imageName = "pb";
            for (int i = 1; i <= 7; i++)
            {
                imageName = "pb" + i.ToString()+".png";

                pict[i] = new PictureBox();
                pict[i].Image = Image.FromFile(imageName);
               
            }
            picBox_b1.Image = null;
            picBox_b2.Image = null;
            picBox_b3.Image = null;
            picBox_b4.Image = null;
            picBox_b5.Image = null;
            picBox_b6.Image = null;
            picBox_b7.Image = null;

        }

        
    }
}
2010-09-28 13:55
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:0 
再次感谢bygg的支持!!
2010-09-28 13:57
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:0 
是有这个问题,但是我个人的需要只是简单的叠加就可以了。

你说的这个问题我想过用程序自动判断,然后确认谁是谁的“父亲”,这样可以实现那个图层在上那个在下,但是由于时间原因我没有自己动手试,估计是可行的!!
2010-09-28 22:08
快速回复:如何实现类似photoshop图层的功能显示透明图片
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016904 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved