程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#:Win32 Hooks(二)讓MessageBox自動顯示在父窗體中心

C#:Win32 Hooks(二)讓MessageBox自動顯示在父窗體中心

編輯:C#入門知識

前言:
在WinForm裡,無論你是否指定owner,MessageBox總是顯示在屏幕中心,而不是父窗體中心。要想讓其顯示在父窗體中心,你不得不借助強大的Win32 Hooks。
源代碼:
MessageBoxPlus.cs
[csharp]
文件名稱:MessageBoxPlus.cs
 
 
開發環境:
    Visual Studio V2010
    .NET Framework 4 Client Profile
 
版本歷史:
    V1.0    2012年05月07日         
            讓MessageBox顯示在父窗體中心
------------------------------------------------------------ */ 
using System; 
using System.Windows.Forms; 
 
namespace Splash.Windows.Forms 

    public class MessageBoxPlus 
    { 
        public static DialogResult Show(IWin32Window owner, String text) 
        { 
            owner.CenterChild(); 
            return MessageBox.Show(owner, text); 
        } 
 
        public static DialogResult Show(IWin32Window owner, String text, String caption) 
        { 
            owner.CenterChild(); 
            return MessageBox.Show(owner, text, caption); 
        } 
 
        public static DialogResult Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons) 
        { 
            owner.CenterChild(); 
            return MessageBox.Show(owner, text, caption, buttons); 
        } 
 
        public static DialogResult Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon) 
        { 
            owner.CenterChild(); 
            return MessageBox.Show(owner, text, caption, buttons, icon); 
        } 
 
        public static DialogResult Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton) 
        { 
            owner.CenterChild(); 
            return MessageBox.Show(owner, text, caption, buttons, icon, defButton); 
        } 
 
        public static DialogResult Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton, MessageBoxOptions options) 
        { 
            owner.CenterChild(); 
            return MessageBox.Show(owner, text, caption, buttons, icon, defButton, options); 
        } 
 
        public static DialogResult Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, String helpFilePath) 
        { 
            owner.CenterChild(); 
            return MessageBox.Show(owner, text, caption, buttons, icon, defaultButton, options, helpFilePath); 
        } 
 
        public static DialogResult Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, String helpFilePath, String keyword) 
        { 
            owner.CenterChild(); 
            return MessageBox.Show(owner, text, caption, buttons, icon, defaultButton, options, helpFilePath, keyword); 
        } 
 
        public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator navigator) 
        { 
            owner.CenterChild(); 
            return MessageBox.Show(owner, text, caption, buttons, icon, defaultButton, options, helpFilePath, navigator); 
        } 
 
        public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator navigator, Object param) 
        { 
            owner.CenterChild(); 
            return MessageBox.Show(owner, text, caption, buttons, icon, defaultButton, options, helpFilePath, navigator, param); 
        } 
    } 

 

摘自 秦建輝的專欄

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved