/// <summary> /// 显示提示消息 /// </summary> /// <param name="content"></param> /// <param name="delay"></param> /// <param name="isFloat"></param> private void ShowMessage(string content, int delay = 1500, bool isFloat = true) { Action action = () => { UIMessageTip.Show(this, content, null, delay, isFloat); }; Invoke(action); }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Trim().Equals("") || textBox2.Text.Trim().Equals("")) { UIMessageTip.Show("信息不能为空"); } else { if (comboBox1.SelectedIndex == 0) { string no = textBox1.Text.Trim(); string name = textBox2.Text.Trim(); try { SqlConnection conn = new SqlConnection(con); string sql = "select mno,mpwd from manager where mno='" + no + "'and mpwd='" + name + "'"; conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); SqlDataReader sqlDataReader = comm.ExecuteReader(); if (sqlDataReader.HasRows) { UIMessageBox.Show("登陆成功"); string n = textBox1.Text; this.Hide(); manabook man = new manabook(n); man.Show(); } else { MessageBox.Show("登录失败"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { string no = textBox1.Text.Trim(); string name = textBox2.Text.Trim(); try { SqlConnection conn = new SqlConnection(con); string sql = "select sno,pwd from student where sno='" + no + "'and pwd='" + name + "'"; conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); SqlDataReader sqlDataReader = comm.ExecuteReader(); if (sqlDataReader.HasRows) { MessageBox.Show("登陆成功"); this.Hide(); new readbook().Show(); } else { MessageBox.Show("登录失败"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
public void InitPdone() { setting = GetUserData(); Application.ApplicationExit += (sender, e) => { SetUserData(setting); }; this.FormClosed += (sender, e) => { if (AdbProcessInfo != null) { //退出前关闭adb AdbProcessInfo.Arguments = "kill-server"; Process.Start(AdbProcessInfo); LogHelper.Info("kill adb server"); } Application.Exit(); }; #region 设置标题 Assembly asm = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location); ledTitle.Text = $"Free Control v{fvi.ProductVersion}"; ledTitle.CharCount = 19; ledTitle.MouseDown += (sender, e) => DragWindow(); this.Icon = Properties.Resources.pcm; #endregion #region 设置主题颜色 UIStyles.SetStyle(UIStyle.Gray); //设置默认导航条颜色 navTab.TabSelectedForeColor = Color.FromArgb(140, 140, 140); navTab.TabSelectedHighColor = Color.FromArgb(140, 140, 140); //设置默认导航条图标 tabHome.ImageIndex = 0; tabSetting.ImageIndex = 2; #endregion #region 设置深色模式 switchDarkMode.ValueChanged += (object sender, bool value) => { var tabBackColor = Color.Transparent; if (value) { tabBackColor = Color.FromArgb(24, 24, 24); UIStyles.SetStyle(UIStyle.Black); tabHome.BackColor = tabBackColor; tabSetting.BackColor = tabBackColor; navTab.MenuStyle = UIMenuStyle.Black; btnStart.SetStyle(UIStyle.Black); tabHome.ImageIndex = 1; tabSetting.ImageIndex = 3; } else { tabBackColor = Color.FromArgb(242, 242, 244); UIStyles.SetStyle(UIStyle.Gray); tabHome.BackColor = tabBackColor; tabSetting.BackColor = tabBackColor; navTab.MenuStyle = UIMenuStyle.White; btnStart.SetStyle(UIStyle.Gray); tabHome.ImageIndex = 0; tabSetting.ImageIndex = 2; navTab.TabSelectedForeColor = Color.FromArgb(140, 140, 140); navTab.TabSelectedHighColor = Color.FromArgb(140, 140, 140); } }; #endregion #region 切换tab事件 navTab.SelectedIndexChanged += (object sender, EventArgs e) => { }; navTab.SelectTab(0); #endregion #region 设置默认值 rbtnPx.SelectedIndex = setting.PXIndex; rbtnMbps.SelectedIndex = setting.BitRateIndex; rbtnMaxFPS.SelectedIndex = setting.MaxFPSIndex; switchDarkMode.Active = setting.DarkMode; tbxAddress.Text = setting.IPAddress; tbxPort.Text = setting.Port; tbxAddress.Enabled = !setting.UseWireless; tbxPort.Enabled = !setting.UseWireless; #region 框默认值 cbxUseWireless.Checked = setting.UseWireless; cbxUseLog.Checked = setting.UseLog; LogHelper.enable = setting.UseLog; cbxCloseScreen.Checked = setting.CloseScreen; cbxKeepAwake.Checked = setting.KeepAwake; cbxAllFPS.Checked = setting.AllFPS; cbxHideBorder.Checked = setting.HideBorder; cbxFullScreen.Checked = setting.FullScreen; cbxTopMost.Checked = setting.TopMost; #endregion #region 参数设置事件 rbtnPx.ValueChanged += RbtnPx_ValueChanged; rbtnMbps.ValueChanged += RbtnMbps_ValueChanged; rbtnMaxFPS.ValueChanged += RbtnMaxFPS_ValueChanged; cbxUseWireless.ValueChanged += CbxUseWireless_ValueChanged; cbxUseLog.ValueChanged += CbxUseLog_ValueChanged;; switchDarkMode.ValueChanged += (sender, e) => { setting.DarkMode = switchDarkMode.Active; }; tbxAddress.TextChanged += TbxAddress_TextChanged; tbxPort.TextChanged += TbxPort_TextChanged; cbxCloseScreen.ValueChanged += CommonCbx_ValueChanged; cbxKeepAwake.ValueChanged += CommonCbx_ValueChanged; cbxAllFPS.ValueChanged += CommonCbx_ValueChanged; cbxHideBorder.ValueChanged += CommonCbx_ValueChanged; cbxFullScreen.ValueChanged += CommonCbx_ValueChanged; cbxTopMost.ValueChanged += CommonCbx_ValueChanged; #endregion #endregion #region 启动前 string tempFileName = "temp.zip"; if (!Directory.Exists(scrcpyPath)) { Directory.CreateDirectory(scrcpyPath); File.WriteAllBytes(scrcpyPath + tempFileName, Properties.Resources.scrcpy_win32_v1_17); if (SharpZip.UnpackFiles(scrcpyPath + tempFileName, scrcpyPath)) { File.Delete(scrcpyPath + tempFileName); } } #endregion Process scrcpy = null; //设置端口号命令 adb tcpip 5555 #region 启动按钮 btnStart.Click += (sender, e) => { if (setting.UseWireless && (string.IsNullOrWhiteSpace(setting.IPAddress) || string.IsNullOrWhiteSpace(setting.Port))) { UIMessageTip.ShowWarning(sender as Control, "IP地址或者端口号没有填写,无法启动 -.-!", 1500); return; } LogHelper.Info("starting..."); var paramlist = $" {setting.BitRate} {setting.PX} {setting.MaxFPS} {setting.OtherParam} "; //设置屏幕高度 800 paramlist += "--window-height 800 "; //设置快捷键 左Crtl paramlist += "--shortcut-mod=lctrl "; //设置标题 paramlist += $"--window-title \"{ledTitle.Text}\" "; AdbProcessInfo = new ProcessStartInfo($@"{scrcpyPath}adb.exe", $"connect {setting.IPAddress}:{setting.Port}") { CreateNoWindow = true, //设置不在新窗口中启动新的进程 UseShellExecute = false, //不使用操作系统使用的shell启动进程 RedirectStandardOutput = true, //将输出信息重定向 }; if (setting.UseWireless) { //启动ABD Process adb = Process.Start(AdbProcessInfo); LogHelper.Info(adb.StandardOutput.ReadToEnd()); adb.WaitForExit(); paramlist = $"-s {setting.IPAddress}:{setting.Port} " + paramlist; } scrcpy = Process.Start(new ProcessStartInfo($@"{scrcpyPath}scrcpy.exe", paramlist) { CreateNoWindow = true, //设置不在新窗口中启动新的进程 UseShellExecute = false, //不使用操作系统使用的shell启动进程 RedirectStandardOutput = true, //将输出信息重定向 }); this.Hide(); LogHelper.Info("scrcpy running..."); LogHelper.Info(scrcpy.StandardOutput.ReadToEnd()); scrcpy.WaitForExit(); UIMessageTip.Show(this, "已退出", null, 1500); this.Show(); }; #endregion }
/// <summary> /// 在指定控件附近显示消息 /// </summary> /// <param name="form">窗体</param> /// <param name="controlOrItem">控件或工具栏项</param> /// <param name="text">消息文本</param> /// <param name="style">消息样式。不指定则使用默认样式</param> /// <param name="delay">消息停留时长(ms)。为负时使用全局时长</param> /// <param name="floating">是否漂浮,不指定则使用全局设置</param> /// <param name="centerInControl">是否在控件中央显示,不指定则自动判断</param> public static void ShowInfoTip(this Form form, Component controlOrItem, string text, TipStyle style = null, int delay = -1, bool?floating = null, bool?centerInControl = null) => UIMessageTip.Show(controlOrItem, text, style, delay, floating, centerInControl);
/// <summary> /// 显示消息 /// </summary> /// <param name="form">窗体</param> /// <param name="text">消息文本</param> /// <param name="style">消息样式。不指定则使用默认样式</param> /// <param name="delay">消息停留时长(ms)。为负时使用全局时长</param> /// <param name="floating">是否漂浮,不指定则使用全局设置</param> /// <param name="point">消息窗显示位置。不指定则智能判定,当由工具栏项(ToolStripItem)弹出时,请指定该参数或使用接收控件的重载</param> /// <param name="centerByPoint">是否以point参数为中心进行呈现。为false则是在其附近呈现</param> public static void ShowInfoTip(this Form form, string text, TipStyle style = null, int delay = -1, bool?floating = null, Point?point = null, bool centerByPoint = false) => UIMessageTip.Show(text, style, delay, floating, point, centerByPoint);