程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> WinForm特效:同時讓兩個窗體有激活效果

WinForm特效:同時讓兩個窗體有激活效果

編輯:關於.NET

windows api,一個窗體激活的時候給另外一個發消息

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication43
{
  public partial class Form1 : Form
  {
    Form frm =null;
    public Form1()
    {
      InitializeComponent();
      this.Activated += Form_Activated;
    }
    const int WM_NCACTIVATE = 0x86;
    const int WA_ACTIVE = 0x1;
    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
    private void button1_Click(object sender, EventArgs e)
    {
      frm = new Form();
      frm.Text = "jinjazz";
      frm.Activated += Form_Activated;
      frm.Show();
      frm.Location = new System.Drawing.Point(this.Left + this.Width, this.Top);
      SendMessage(this.Handle, WM_NCACTIVATE, WA_ACTIVE, 0);
    }
    void Form_Activated(object sender, EventArgs e)
    {
      SendMessage(this.Handle, WM_NCACTIVATE, WA_ACTIVE, 0);
      if (frm != null)
        SendMessage(frm.Handle, WM_NCACTIVATE, WA_ACTIVE, 0);
    }
  }
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved