关于WinForm窗体的问题?

ZJZAYZ 2006-07-19 05:18:34
作了一张图,
如何让窗体只显示这张图片,不显示窗体的其余部分。
...全文
566 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
netmicro 2006-07-21
  • 打赏
  • 举报
回复
1)我这段代码也用在我现在在做的一个project里,虽然我只用它来找50x50的gif图的不透明区域

2)我的代码就只有两重for,绝对不会堆栈溢出,最多是内存溢出,因为如果你图象太大了会不够内存用

所以请检查一下各种可能性
ZJZAYZ 2006-07-21
  • 打赏
  • 举报
回复
netmicro(麦) :
用你的方法出现异常,下面是异常信息

未处理的“System.StackOverflowException”类型的异常出现在 system.drawing.dll 中。
netmicro 2006-07-20
  • 打赏
  • 举报
回复
注意:这个方法不能处理png图像的半透明像素

要用半透明(或者消除锯齿),就必须使用P/Invoke调用GDI+函数
netmicro 2006-07-20
  • 打赏
  • 举报
回复
这是我正在做的一个winform项目中所用的方法,对你应该有用

/// <summary>
/// Gets the opaque pixels in a bitmap as a Region object.
/// 获取一个位图中的不透明像素并作为一个 Region 对象返回。
/// </summary>
/// <param name="bitmap"></param>
/// <returns></returns>
public static Region OpaquePixels(Bitmap bitmap)
{
Region r = new Region();
r.MakeEmpty();
for (int i = 0; i < bitmap.Width; i++)
for (int j = 0; j < bitmap.Height; j++)
if (bitmap.GetPixel(i, j).A != (byte)0)
r.Union(new Rectangle(i, j, 1, 1));
return r;
}

用法就是……

Bitmap bmp = ........... // 读取窗体的背景图
FormBorder = None;
Size = bmp.Size;
Region = OpaquePixels(bmp);
slex 2006-07-20
  • 打赏
  • 举报
回复
怎么能把图片的透明区域,在窗体或(PictureBox)上显示透明?

--------------
估计需要对图片进行处理把
SaSBYa 2006-07-20
  • 打赏
  • 举报
回复
楼主查一下不规则窗体,方法很多.
ZJZAYZ 2006-07-19
  • 打赏
  • 举报
回复
多谢各位!但是怎么能把图片的透明区域,在窗体或(PictureBox)上显示透明?
zjmotion 2006-07-19
  • 打赏
  • 举报
回复
这是我自己做Splash用的一个类,已经加了注释,给你了!

using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsApplication2
{
/// <summary>
/// Splash 的摘要说明。
/// </summary>

internal class SplashForm : Form
{
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
private PictureBox m_SplashPictureBox;


public SplashForm(Bitmap bm)
{
InitializeComponent();
//图片地址
Bitmap bmp = new Bitmap(@"image\loginout.bmp");
m_SplashPictureBox.Image = bm;
//要实现你说的效果,这点很重要
ClientSize = m_SplashPictureBox.Size;
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SplashForm));
this.m_SplashPictureBox = new System.Windows.Forms.PictureBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// m_SplashPictureBox
//
this.m_SplashPictureBox.Cursor = System.Windows.Forms.Cursors.AppStarting;
this.m_SplashPictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.m_SplashPictureBox.Location = new System.Drawing.Point(0, 0);
this.m_SplashPictureBox.Name = "m_SplashPictureBox";
this.m_SplashPictureBox.Size = new System.Drawing.Size(480, 260);
this.m_SplashPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.m_SplashPictureBox.TabIndex = 0;
this.m_SplashPictureBox.TabStop = false;
//
// timer1
//
this.timer1.Enabled = true;
//3秒后自动关闭
this.timer1.Interval = 3000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// SplashForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(110, 78);
this.ControlBox = false;
this.Controls.Add(this.m_SplashPictureBox);
this.Cursor = System.Windows.Forms.Cursors.Cross;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "SplashForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.TopMost = true;
this.ResumeLayout(false);

}
#endregion

private void timer1_Tick(object sender, System.EventArgs e)
{
this.timer1.Enabled = false;
this.Close();
}
}
}
netmicro 2006-07-19
  • 打赏
  • 举报
回复
你这张图片是不是含透明区域或者mask色区域的图,然后要窗体在这些区域变透明?

这样的话,将Form.TransparentKey设成mask色,不过不一定凑效
Form.FormBorder 当然要设成 None,大小调成图片大小

不一定凑效的解决方法:自己用System.Drawing/.Imaging 里面的类将图片里面的应该透明的区域全部挖出来,手动建造一个 Region 对象,然后将 Form.Region 设成该对象,这就可以强迫窗体不显示那些像素了
icedreamboy 2006-07-19
  • 打赏
  • 举报
回复
将窗体设为无边框的,然后设置窗体背景图并讲BackgroundImageLayout设为Stretch,或者在窗体上放一个PictureBox,将其Dock设为Fill,并设置Image和SizeMode为StretchImage,就可以了。

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧