vb.net中如何让msgbox保持在最前面?

cdshmin 2010-04-06 04:28:06
就像topmost一样。
...全文
776 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
KissXYL 2010-04-07
  • 打赏
  • 举报
回复
要是你懒得测试,或是不会测试呢,可以到我的下载链接来下载
MsgBox保持在最前面的功能演示
KissXYL 2010-04-07
  • 打赏
  • 举报
回复
就是一个思路演示,发帖的人需要一个msgbox能置顶,那我就想办法曲线救国,先抓图,对整个屏幕抓图,然后创建窗体,设置背景为当前图,然后弹出个对话框。就这么简单。
KissXYL 2010-04-07
  • 打赏
  • 举报
回复
新建个窗体,放个按钮在上面,然后粘贴下面代码:

Imports System.Net
Imports System.IO

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bmp As Bitmap = CaptureImage(Nothing)
Dim topWindow As New Form
msgText = "提示信息修改为这样,可以么?"
AddHandler topWindow.Load, AddressOf Form_Load
topWindow.FormBorderStyle = Windows.Forms.FormBorderStyle.None
topWindow.WindowState = FormWindowState.Maximized
topWindow.TopMost = True
topWindow.BackgroundImage = bmp
topWindow.Show()
End Sub

Private msgText As String = "这样提示可以么?"
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show(msgText)
CType(sender, Form).Close()
End Sub

'PictureBox1.Image = CaptureImage(Nothing)
'---save the video data into the Image global variable---
Public Function CaptureImage(ByRef c As Control) As Bitmap
Dim hDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
Dim sw, sh As Integer
If c Is Nothing Then
hDC = GetDC(0)
sw = Screen.PrimaryScreen.Bounds.Width
sh = Screen.PrimaryScreen.Bounds.Height
Else
hDC = GetDC(c.Handle)
sw = c.Width
sh = c.Height
End If

hMDC = CreateCompatibleDC(hDC)
hBMP = CreateCompatibleBitmap(hDC, sw, sh)
hBMPOld = SelectObject(hMDC, hBMP)
BitBlt(hMDC, 0, 0, sw, sh, hDC, 0, 0, SRCCOPY)
hBMP = SelectObject(hMDC, hBMPOld)
Dim result = Image.FromHbitmap(New IntPtr(hBMP))
DeleteDC(hDC)
DeleteDC(hMDC)
DeleteObject(hBMP)
Return result
End Function

Public Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
Public Declare Function CreateCompatibleDC Lib "gdi32" Alias "CreateCompatibleDC" (ByVal hdc As Integer) As Integer
Public Declare Function CreateCompatibleBitmap Lib "gdi32" Alias "CreateCompatibleBitmap" (ByVal hdc As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
Public Declare Function SelectObject Lib "gdi32" Alias "SelectObject" (ByVal hdc As Integer, ByVal hObject As Integer) As Integer
Public Declare Function DeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal hdc As Integer) As Integer
Public Declare Function DeleteObject Lib "gdi32" Alias "DeleteObject" (ByVal hObject As Integer) As Integer
Public Const SRCCOPY = &HCC0020

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Object) As Integer
Private Const WM_CAP_START = &H400
Private Const WM_CAP_EDIT_COPY = (WM_CAP_START + 30)
End Class
jojosu 2010-04-07
  • 打赏
  • 举报
回复
应该有相关属性支持吧
dgl_1225 2010-04-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 kissxyl 的回复:]
就是一个思路演示,发帖的人需要一个msgbox能置顶,那我就想办法曲线救国,先抓图,对整个屏幕抓图,然后创建窗体,设置背景为当前图,然后弹出个对话框。就这么简单。
[/Quote]
是很神奇,但是很奇怪
兔子-顾问 2010-04-07
  • 打赏
  • 举报
回复
另外,楼主要的最前面,应该是想阻止其他操作吧,你说自己做一个,那就真的只能放那个对话框在最上面了。
兔子-顾问 2010-04-07
  • 打赏
  • 举报
回复
MessageBox自己比较难实现的,四种图标要找,确定取消是否之类的选项,要做一个还是有点麻烦的,虽然不难,你慢慢做也做的好,还有就是效率,MessageBox的效率很高的,你自己做的未必能很好。
lgx1972 2010-04-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lovedogdog 的回复:]
那就用窗体来代替
[/Quote]
支持此解,简洁方便!何必象楼上的搞得跟高科技似地,得不偿失。
lovedogdog 2010-04-06
  • 打赏
  • 举报
回复
那就用窗体来代替

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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