新鲜事,来看看

visualC120 2010-08-31 03:46:30
其实我想在一个winform程序中弹出一个对话框(MessageBox),在弹出对话框的同时不能操作其他东西,只能允许鼠标操作对话框。该怎么实现呢。不能操作其他东西也就是说除了对话框是可以清晰看得到的,整个桌面是像被蒙上了一层雾状。
...全文
101 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huxuan3226335 2010-08-31
  • 打赏
  • 举报
回复
可以使用AJAX控件之ModalPopup 这个控件 你在网上学一下 应该很简单的
不过要装ajax工具包
teerhu 2010-08-31
  • 打赏
  • 举报
回复
webform 遮罩效果做過
winform 沒做過
ovenj 2010-08-31
  • 打赏
  • 举报
回复
给你个小窍门,当弹出对话框时候,系统默认弹出一个全屏的的窗体,窗体设成白色透明的模糊效果,然后放在最上层,这样你有智能操作这个透明窗体以上的的东西了。

如果想禁用键盘可以用下起点10工作助理这个小软件,里面有通过钩子禁用键盘方法,也有窗体全屏模糊效果,(这是软件一个功能:休息提醒)

你可以试试,希望能帮到你
地址: http://download.csdn.net/source/1738160
指尖魔术师 2010-08-31
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace AphaStyle
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.BackColor = Color.Silver;

this.TopMost = true;

this.FormBorderStyle = FormBorderStyle.None;

this.WindowState = FormWindowState.Maximized;

this.SetWindowTransparent(128);
}

private void SetWindowTransparent(byte bAlpha)
{
try
{
WinAPI.SetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE, WinAPI.GetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE) | (uint)WinAPI.ExWindowStyle.WS_EX_LAYERED);//如果第二个参数中加入 "| WinAPI.WS_EX_TRANSPARENT" 就可以穿过这个窗体,如果不加,像现在这样,就不能穿过窗体,可以实现你说的只能操作对话框了,至于对话框你在第一个窗体弹出对话框之前弹出行,是在这个透明窗体加载时候弹出也行,看你个人需要

WinAPI.SetLayeredWindowAttributes(this.Handle, 0, bAlpha, WinAPI.LWA_COLORKEY | WinAPI.LWA_ALPHA);
}
catch
{
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;

cp.Parent = WinAPI.GetDesktopWindow();
cp.ExStyle = 0x00000080 | 0x00000008;//WS_EX_TOOLWINDOW | WS_EX_TOPMOST

return cp;
}
}
}

class WinAPI
{
[DllImport("user32.dll")]
public extern static IntPtr GetDesktopWindow();

[DllImport("user32.dll")]
public extern static bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
public static uint LWA_COLORKEY = 0x00000001;
public static uint LWA_ALPHA = 2;
public static uint WS_EX_TRANSPARENT = 0x20;//加入这个以后鼠标可以穿过透明窗体

[DllImport("user32.dll")]
public extern static uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
[DllImport("user32.dll")]
public extern static uint GetWindowLong(IntPtr hwnd, int nIndex);

public enum WindowStyle : int
{
GWL_EXSTYLE = -20
}

public enum ExWindowStyle : uint
{
WS_EX_LAYERED = 0x80000
}

}
}

bdmh 2010-08-31
  • 打赏
  • 举报
回复
不知道你要控制哪些东西,如果是本程序的话,已经可以了
yanele 2010-08-31
  • 打赏
  • 举报
回复
是不是连桌面都无法操作,还要考虑禁止调用Ctrl+Alt+Del键的调用,不然可以注销或结束任务!

110,545

社区成员

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

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

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