using Casic.Birmm.RbFreqStandMeasure.Properties; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Resources; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; namespace Casic.Birmm.RbFreqStandMeasure { public partial class RbFreqStdMeas : Form { #region 无边框拖动效果 [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; private void RbFreqStdMeas_MouseDown(object sender, MouseEventArgs e) { //拖动窗体 ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } #endregion private bool[] menuSelected = { true, false }; // 按钮图标 private PictureBox[] menuPics; // 按钮图标的资源名称(选中的资源名称在后面加上 _selected) private string[] menuIconResources; // 按钮文本 private Label[] menuLabels; // 按钮下划线 private Label[] menuUnderlines; private void ClearAllMenuSelected() { // 找到当前选中的按钮 int index = 0; for (int i = 0; i < this.menuSelected.Length; i++) { if (this.menuSelected[i] == true) { index = i; break; } } // 将当前按钮的效果设置为默认未选中 this.menuPics[index].BackgroundImage = (Bitmap)Resources.ResourceManager.GetObject(this.menuIconResources[index], null); this.menuLabels[index].ForeColor = ColorTranslator.FromHtml("#2C2C2C"); this.menuUnderlines[index].BackColor = Color.Transparent; } #region 首页按钮点击、鼠标移入/移出效果 private void HoverHome() { panHome.Back = ColorTranslator.FromHtml("#56a3f2"); } private void LeaveHome() { panHome.Back = Color.Transparent; } private void SelectHome() { // 移除所有按钮的选中样式 this.ClearAllMenuSelected(); // 鼠标移入效果去掉 LeaveHome(); // 重新设置所有按钮的状态 this.menuSelected = new bool[] { true, false }; // 将新选中的按钮设置为选中 this.picIconHome.BackgroundImage = (Bitmap)Resources.ResourceManager.GetObject("icon_home_selected", null); this.labHomeText.ForeColor = ColorTranslator.FromHtml("#1296db"); this.labHomeSelected.BackColor = ColorTranslator.FromHtml("#1296db"); } #endregion #region 基准状态按钮点击、移入/移出效果 private void HoverStatus() { panStatus.Back = ColorTranslator.FromHtml("#56a3f2"); } private void LeaveStatus() { panStatus.Back = Color.Transparent; } private void SelectStatus() { // 移除所有按钮的选中样式 this.ClearAllMenuSelected(); // 鼠标移入效果去掉 LeaveStatus(); // 重新设置所有按钮的状态 this.menuSelected = new bool[] { false, true }; // 将新选中的按钮设置为选中 this.picIconStatus.BackgroundImage = (Bitmap) Resources.ResourceManager.GetObject("icon_status_selected", null); this.labStatusText.ForeColor = ColorTranslator.FromHtml("#1296db"); this.labStatusSelected.BackColor = ColorTranslator.FromHtml("#1296db"); } #endregion public RbFreqStdMeas() { InitializeComponent(); } private void RbFreqStdMeas_Load(object sender, EventArgs e) { this.menuPics = new PictureBox[] { this.picIconHome, this.picIconStatus }; this.menuLabels = new Label[] { this.labHomeText, this.labStatusText }; this.menuUnderlines = new Label[] { this.labHomeSelected, this.labStatusSelected }; this.menuIconResources = new string[] { "icon_home", "icon_status" }; } private void btnExitSys_Click(object sender, EventArgs e) { Application.Exit(); } private void btnExitSys_MouseHover(object sender, EventArgs e) { ToolTip p = new ToolTip(); p.ShowAlways = true; p.SetToolTip(this.btnExitSys, "退出"); } private void panHome_Click(object sender, EventArgs e) { if (this.menuSelected[0] == false) { this.SelectHome(); } } private void panHome_MouseHover(object sender, EventArgs e) { // 没有选中首页时才动作 if (this.menuSelected[0] == false) { HoverHome(); } } private void panHome_MouseLeave(object sender, EventArgs e) { // 没有选中首页时才动作 if (this.menuSelected[0] == false) { LeaveHome(); } } private void panStatus_Click(object sender, EventArgs e) { if (this.menuSelected[1] == false) { SelectStatus(); } } private void panStatus_MouseHover(object sender, EventArgs e) { if (this.menuSelected[1] == false) { HoverStatus(); } } private void panStatus_MouseLeave(object sender, EventArgs e) { if (this.menuSelected[1] == false) { LeaveStatus(); } } } }