关于窗口淡入淡出的问题

hylovett 2008-06-01 08:04:27
原窗口使用API函数AnimateWindow 使对窗口产生淡淡入效果

但是改变了窗口的TRANSPARENCYKEY属性后....AnimateWindow 不能使用0x00040000,和0x00080000进行 淡入淡出.


有什么办法可以解决吗?>
...全文
295 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
BIGBIRDINWOODS 2008-06-02
  • 打赏
  • 举报
回复
弄個timer,在timer_tick里面遞增或者遞減窗口的transparent
Hesperus 2008-06-02
  • 打赏
  • 举报
回复
我试试去,还没用过这个呢
yagebu1983 2008-06-02
  • 打赏
  • 举报
回复
学习了!!
谢谢!!
lxl19870315 2008-06-02
  • 打赏
  • 举报
回复
顶一下
daolang504 2008-06-02
  • 打赏
  • 举报
回复
我也想知道怎么实现这个效果!以前想做没做出来!
hylovett 2008-06-02
  • 打赏
  • 举报
回复
为什么设置了TRANSPARENCYKEY属性.AnimateWindow 函数不能正常使用...而且使窗口不能透明...?


没办法的话..下午就改用渐变Opacity 值了..
烈火焚身 2008-06-02
  • 打赏
  • 举报
回复
这里有个变暗的例子.你参考一下么
// Form1.cs
// Compile with csc /t:winexe form1.cs

using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

public partial class Form1 : Form
{
Bitmap bg;
Timer timer = new Timer();
Form form;

public Form1()
{
Rectangle workArea = Screen.PrimaryScreen.WorkingArea;
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
{
// Get HBITMAP of desktop window
IntPtr desktopDC = g.GetHdc();
const int OBJ_BITMAP = 7;
IntPtr desktopBitmap = GetCurrentObject(desktopDC, OBJ_BITMAP);
Bitmap bm = Bitmap.FromHbitmap(desktopBitmap);

// change to 256 indexed color
bg = bm.Clone(workArea, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
MemoryStream bitStream = new MemoryStream();
bg.Save(bitStream, ImageFormat.Gif);
bg = new Bitmap(bitStream);
}

this.SuspendLayout();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.TopMost = true;
this.WindowState = FormWindowState.Maximized;
this.ResumeLayout(false);

timer.Interval = 200;
timer.Enabled = true;
timer.Tick += delegate
{
ColorPalette palette = bg.Palette;
for (int i = 0; i < palette.Entries.Length; i++)
{
Color c = palette.Entries[i];
int gray = (c.R + c.G + c.B) / 3;
gray = gray - gray / 10;

int r = Math.Max(0, c.R - (c.R - gray) / 3);
int g = Math.Max(0, c.G - (c.G - gray) / 3);
int b = Math.Max(0, c.B - (c.B - gray) / 3);
palette.Entries[i] = Color.FromArgb(r, g, b);
}
bg.Palette = palette;
Invalidate();
};

// show a form
form = new Form();
form.Text = "Ctrl+F4 to close me";
form.Show(this);

form.Disposed += delegate { Close(); };
this.Activated += delegate { form.Activate(); };
}
protected override void OnPaintBackground(PaintEventArgs e)
{
}

protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImageUnscaled(bg, 0, 0);
}

static void Main()
{
Application.Run(new Form1());
}

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
internal extern static IntPtr GetCurrentObject(IntPtr hdc, ushort objectType);
}
周公 2008-06-02
  • 打赏
  • 举报
回复
下面的代码示例演示如何创建以 75% 的不透明度显示的窗体。该代码示例创建一个新窗体,该窗体位于屏幕的中央,其 Opacity 属性被设置为更改窗体的不透明度。该代码示例还设置 Size 属性来提供大于默认窗体大小的窗体。该代码示例假定该示例中定义的方法是从事件处理程序的另一个窗体或其他方法中调用。

private void CreateMyOpaqueForm()
{
// Create a new form.
Form form2 = new Form();
// Set the text displayed in the caption.
form2.Text = "My Form";
// Set the opacity to 75%.
form2.Opacity = .75;
// Size the form to be 300 pixels in height and width.
form2.Size = new Size(300,300);
// Display the form in the center of the screen.
form2.StartPosition = FormStartPosition.CenterScreen;

// Display the form as a modal dialog box.
form2.ShowDialog();
}
周公 2008-06-02
  • 打赏
  • 举报
回复
Opacity 属性使您可以指定窗体及其控件的透明度级别。将此属性设置为小于 100% (1.00) 的值时,会使整个窗体(包括边框)更透明。将此属性设置为值 0% (0.00) 时,会使窗体完全不可见。可以使用此属性提供不同级别的透明度,或者提供如窗体逐渐进入或退出视野这样的效果。例如,可以通过将 Opacity 属性设置为值 0% (0.00),并逐渐增加该值直到它达到 100% (1.00),使一个窗体逐渐进入视野。
czk598478 2008-06-02
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 DirectRay 的回复:]
有的。假设你要在五秒内完成这个效果,那你就动态设定窗体的Opacity属性。让它在指定时间内变化就是了。
[/Quote]

以上楼主的不能实现这个功能;

我测试了下;

帮你顶,我也想知道这个功能;
hylovett 2008-06-02
  • 打赏
  • 举报
回复
UP~~~~~~~~~~
hyblusea 2008-06-02
  • 打赏
  • 举报
回复
支持用Opacity

我曾经做过。在1.5秒之内完成从完全透明到完全不透明。效果不错。。
parfum 2008-06-01
  • 打赏
  • 举报
回复
先Mark了
hylovett 2008-06-01
  • 打赏
  • 举报
回复
嗯..好的..谢谢...
常熟老九 2008-06-01
  • 打赏
  • 举报
回复
明天告诉你,我看到过这个例子的,等一下
DirectRay 2008-06-01
  • 打赏
  • 举报
回复
有的。假设你要在五秒内完成这个效果,那你就动态设定窗体的Opacity属性。让它在指定时间内变化就是了。
Jade_2008 2008-06-01
  • 打赏
  • 举报
回复
关注!
eagle_2008 2008-06-01
  • 打赏
  • 举报
回复
up
hylovett 2008-06-01
  • 打赏
  • 举报
回复
窗体本身有淡入淡出属性??>?
hylovett 2008-06-01
  • 打赏
  • 举报
回复
.
加载更多回复(1)

110,568

社区成员

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

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

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