C# winform 广告机 网络多媒体发布系统桌面版之一

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Dare.Utilities;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace DareMediaTray
{
    public partial class MainFrm : Form
    {
        bool isNormal = true;
        public static bool multiSelect = false;
        public MainFrm()
        {
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            InitializeComponent();
            this.KeyPreview = true;
            this.KeyDown += new KeyEventHandler(MainFrm_KeyDown);
            this.KeyUp += new KeyEventHandler(MainFrm_KeyUp);
           
            this.Text = "网络多媒体信息发布系统";
            lblTitle.Text = "网络多媒体信息发布系统";
            this.WindowState = FormWindowState.Normal;
            this.CenterToScreen();
            MaxmizeIcon(this.WindowState == FormWindowState.Maximized);
            this.imgBtnMedia.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnMedia.MouseOverImage")));
            this.imgBtnSysconfig.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnSysconfig.ButtonImage")));
            this.imgBtnExt.ButtonImage = global::DareMediaTray.Properties.Resources.template_release;
            this.imgBtnAbout.ButtonImage = global::DareMediaTray.Properties.Resources.weather_release;
            this.imgBtnTerminal.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnTerminal.ButtonImage")));
            this.imgBtnProgram.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnProgram.ButtonImage")));
            this.lblCopyright.Text = string.Format("Copyright ? 2002 -{0} Dare-tech. All Rights Reserved",DateTime.Now.Year);
            this.lblVersion.Text = "当前版本:V " + AssemblyUtil.GetAssemblyVersion().ToString();
            this.Closing += new CancelEventHandler(MainFrm_Closing);
        }
        void MainFrm_Closing(object sender, CancelEventArgs e)
        {
            if (MessageBox.Show("确定退出系统吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
            {
                if ("1" == SysconfigFrm.GetAppSettings("CLOSE_APACHE"))
                    Program.ProcessService(Program.ApacheserviceDisplayName, true);
                Process.GetCurrentProcess().Kill();
            }
            else
            {
                e.Cancel = true;
            }
        }

        void MainFrm_KeyUp(object sender, KeyEventArgs e)
        {
            multiSelect = false;
        }

        void MainFrm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control == true || e.KeyCode == Keys.ShiftKey)
            {
                multiSelect = true;
            }
        }
        private void imgBtnMedia_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectTab("tabPage1");
            this.imgBtnMedia.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnMedia.MouseOverImage")));
            this.imgBtnSysconfig.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnSysconfig.ButtonImage")));
            this.imgBtnExt.ButtonImage = global::DareMediaTray.Properties.Resources.template_release;
            this.imgBtnAbout.ButtonImage = global::DareMediaTray.Properties.Resources.weather_release;
            this.imgBtnTerminal.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnTerminal.ButtonImage")));
            this.imgBtnProgram.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnProgram.ButtonImage")));
        }

        private void imgBtnProgram_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectTab("tabPage2");
            this.imgBtnProgram.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnProgram.MouseOverImage")));
            this.imgBtnSysconfig.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnSysconfig.ButtonImage")));
            this.imgBtnExt.ButtonImage = global::DareMediaTray.Properties.Resources.template_release;
            this.imgBtnAbout.ButtonImage = global::DareMediaTray.Properties.Resources.weather_release;
            this.imgBtnTerminal.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnTerminal.ButtonImage")));
            this.imgBtnMedia.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnMedia.ButtonImage")));
        }

        private void imgBtnTerminal_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectTab("tabPage3");
            this.imgBtnTerminal.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnTerminal.MouseOverImage")));
            this.imgBtnSysconfig.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnSysconfig.ButtonImage")));
            this.imgBtnExt.ButtonImage = global::DareMediaTray.Properties.Resources.template_release;
            this.imgBtnAbout.ButtonImage = global::DareMediaTray.Properties.Resources.weather_release;
            this.imgBtnProgram.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnProgram.ButtonImage")));
            this.imgBtnMedia.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnMedia.ButtonImage")));
        }
        private void imgBtnAbout_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectTab("tabPage4");
            this.imgBtnAbout.ButtonImage = global::DareMediaTray.Properties.Resources.weather_over;
            this.imgBtnSysconfig.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnSysconfig.ButtonImage")));
            this.imgBtnExt.ButtonImage = global::DareMediaTray.Properties.Resources.template_release;
            this.imgBtnTerminal.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnTerminal.ButtonImage")));
            this.imgBtnProgram.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnProgram.ButtonImage")));
            this.imgBtnMedia.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnMedia.ButtonImage")));

            //AboutFrm frm = new AboutFrm();
            //frm.ShowDialog();
        }

        private void imgBtnExt_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectTab("tabPage5");
            this.imgBtnExt.ButtonImage = global::DareMediaTray.Properties.Resources.template_over;
            this.imgBtnAbout.ButtonImage = global::DareMediaTray.Properties.Resources.weather_release;
            this.imgBtnSysconfig.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnSysconfig.ButtonImage")));
            this.imgBtnTerminal.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnTerminal.ButtonImage")));
            this.imgBtnProgram.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnProgram.ButtonImage")));
            this.imgBtnMedia.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnMedia.ButtonImage")));
     
        }

        private void imgBtnSysconfig_Click(object sender, EventArgs e)
        {
            this.imgBtnSysconfig.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnSysconfig.MouseOverImage")));
            this.imgBtnAbout.ButtonImage = global::DareMediaTray.Properties.Resources.weather_release;
            this.imgBtnExt.ButtonImage = global::DareMediaTray.Properties.Resources.template_release;
            this.imgBtnTerminal.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnTerminal.ButtonImage")));
            this.imgBtnProgram.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnProgram.ButtonImage")));
            this.imgBtnMedia.ButtonImage = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(MainFrm)).GetObject("imgBtnMedia.ButtonImage")));
            SysconfigFrm frm = new SysconfigFrm();
            frm.ShowDialog();
        }

        private void btnMin_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void btnMax_Click(object sender, EventArgs e)
        {
            if (isNormal)
            {
                isNormal = false;
               
                this.FormBorderStyle = FormBorderStyle.None;
                this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
                this.WindowState = FormWindowState.Maximized;
            }
            else
            {
                isNormal = true;
                this.WindowState = FormWindowState.Normal;
            }
            MaxmizeIcon(this.WindowState == FormWindowState.Maximized);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        public void MaxmizeIcon(bool maximize)
        {
            if (maximize)
            {
                this.btnMax.ButtonImage = ((System.Drawing.Image)(DareMediaTray.Properties.Resources.max_rease));
                this.btnMax.MouseClickImage = ((System.Drawing.Image)(DareMediaTray.Properties.Resources.max_rease_over));
                this.btnMax.MouseOverImage = ((System.Drawing.Image)(DareMediaTray.Properties.Resources.max_rease_over));
            }
            else
            {
                this.btnMax.ButtonImage = ((System.Drawing.Image)(DareMediaTray.Properties.Resources.max));
                this.btnMax.MouseClickImage = ((System.Drawing.Image)(DareMediaTray.Properties.Resources.max_over));
                this.btnMax.MouseOverImage = ((System.Drawing.Image)(DareMediaTray.Properties.Resources.max_over));
            }
        }
        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();

        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

        public const int WM_SYSCOMMAND = 0x0112;//点击窗口左上角那个图标时的系统信息
        public const int SC_MOVE = 0xF010;//移动信息
        public const int HTCAPTION = 0x0002;//表示鼠标在窗口标题栏时的系统信息
        public const int WM_NCHITTEST = 0x84;//鼠标在窗体客户区(除了标题栏和边框以外的部分)时发送的消息
        public const int HTCLIENT = 0x1;//表示鼠标在窗口客户区的系统消息
        public const int SC_MAXIMIZE = 0xF030;//最大化信息
        public const int SC_MINIMIZE = 0xF020;//最小化信息

        private void topPnl_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();//首先释放鼠标焦点捕获,这样就不会再发出WM_NCHITTEST消息
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//然后向当前窗体发送消息,消息是移动+表示鼠标在标题栏上

            if (e.Clicks > 1)//模拟双击
            {
                if (isNormal)
                {
                    isNormal = false;

                    this.FormBorderStyle = FormBorderStyle.None;
                    this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
                    this.WindowState = FormWindowState.Maximized;
                }
                else
                {
                    isNormal = true;
                    this.WindowState = FormWindowState.Normal;
                }
                MaxmizeIcon(this.WindowState == FormWindowState.Maximized);
                //ReleaseCapture();
                //SendMessage(this.Handle, WM_SYSCOMMAND, SC_MAXIMIZE + HTCAPTION, 0);

                //Application.OpenForms["MainFrm"].Focus();
            }
        }
    }
}

posted @ 2011-08-20 16:47  火腿骑士  阅读(1336)  评论(1编辑  收藏  举报