private void ShowPopup() { if (tip != null && tip.IsOpen) { tip.FastClose(); } tip = new BalloonTip(this); tip.Style = BalloonTipStyle; tip.Owner = Window.GetWindow(this); tip.SetBinding(Window.ContentProperty, new Binding() { Source = this, Path = new PropertyPath(QuoteProperty) }); tip.Closed += (sender, e) => { IsChecked = false; tip = null; }; tip.FastShow(); }
//################################################################################ #region Constructor public CustomApplicationContext(MainForm mainForm) { MainForm = mainForm; var customContextMenu = CustomContextMenu.Instance; customContextMenu.SetMenuOwner(mainForm); #if DEBUG Bitmap icon = Resources.Debug_Logo; #else Bitmap icon = Resources.Logo; #endif s_NotifyIcon = new NotifyIcon() { //todo: badge icon for notify icon if anything occured eg. crash, update etc. //todo: also show balloon tips if any update or crash occured Icon = Icon.FromHandle(icon.GetHicon()), ContextMenu = customContextMenu, Visible = true }; s_NotifyIcon.DoubleClick += NotifyIcon_DoubleClick; s_NotifyIcon.MouseMove += NotifyIcon_MouseMouse; m_BalloonTip = new BalloonTip(s_NotifyIcon); }
private static void OpenContactExecuted(object sender, ExecutedRoutedEventArgs e) { PeoplePeek content = sender as PeoplePeek; BalloonTip tip = Window.GetWindow(content) as BalloonTip; tip.FastClose(); }
private static void NewNoteExecuted(object sender, ExecutedRoutedEventArgs e) { NotesPeek content = sender as NotesPeek; BalloonTip tip = Window.GetWindow(content) as BalloonTip; tip.FastClose(); }
public static void HideBalloonTip(this BalloonTip balloonTip, Control control = null) { if (control != null) { balloonTip.Remove(control); } else { balloonTip.RemoveAll(); } }
static void Main(string[] args) { while (network == down) { if (!hasBalloonOpened) { hasBalloonOpened = !hasBalloonOpened; BalloonTip.Show(); } //rest of loop or method calls } }
private static void OpenAppointmentExecuted(object sender, ExecutedRoutedEventArgs e) { //if (OpenAppointmentCommand != null) //{ // OpenAppointmentCommand.Execute(e.Parameter, Application.Current.MainWindow); CalendarPeek content = sender as CalendarPeek; BalloonTip tip = Window.GetWindow(content) as BalloonTip; tip.FastClose(); //} }
public static void ShowBalloonTip(this BalloonTip balloonTip, Control controlTrigger, string msg, bool autoFous = false, string title = "提示", eBallonStyle ballonStyle = eBallonStyle.Balloon) { controlTrigger.Invoke(new Action(() => { var ballon = new Balloon(); ballon.CaptionText = title; ballon.Text = msg; balloonTip.BalloonControl = ballon; balloonTip.ShowAlways = true; balloonTip.AutoClose = false; ballon.TopLevel = true; ballon.TopMost = false; if (autoFous) { controlTrigger.Focus(); } balloonTip.Style = ballonStyle; ballon.Show(controlTrigger, autoFous); })); }
private static void ExecutedDockPeekCommand(object sender, ExecutedRoutedEventArgs e) { UndockedPeek peek = sender as UndockedPeek; BalloonTip tip = peek.Parent as BalloonTip; MainWindow mainWindow; if (tip != null) { tip.FastClose(); mainWindow = tip.Owner as MainWindow; } else { mainWindow = (MainWindow)Application.Current.MainWindow; } UIElement content = peek.PeekContent(); if (content == null) { throw new NotImplementedException(""); } foreach (DockedPeek each in mainWindow.dockedPeeks.Items) { if (each.Content.ToString() == content.ToString()) { return; } } DockedPeek docked = new DockedPeek(); docked.Content = content; mainWindow.dockedPeeks.Items.Add(docked); mainWindow.SwitchToNormalMode(); }
private void CheckOvertime() { //set mode and adjust timer values only once if (ModeFunction != FunctionMode.Overtime) { Log.Info("WorkTimer in Overtime mode"); ModeFunction = FunctionMode.Overtime; Settings.Default.ModeFunction = ModeFunction; Settings.Default.Save(); TimerOvertimeAdjustments(); } //when overtime reaches to 2 hours, stop timer if (OverTime.Hours >= 2) { Log.Info("Deadline has been reached. WorkTimer will stop."); StopTimer(); return; } //change color of TimerText if not changed if (OverTime > TimeSpan.FromMinutes(90)) { Painter <Red> .Paint(TimerText, PaintMode.Dark); //display reminder after 90 minutes of overtime for every defined time slot if (OverTime.Minutes % Constants.TimerReminderInterval == 0 && OverTime.Seconds == 0) { var lastMinutes = 60 - OverTime.Minutes; Log.Debug($"Approaching deadline: Last {lastMinutes} minutes."); var message = $"Last {lastMinutes} minutes for leaving the office."; BalloonTip.Show("Work Hour Deadline", message, ToolTipIcon.Info, 2000); } } }
private void InitializePreviewPane() { if (PreviewPane == null || !PreviewPane.IsOpen) { if (OpenPreviewPane != null && OpenPreviewPane.IsOpen) { OpenPreviewPane.FastClose(); } if (PreviewPane != null) { PreviewPane.Content = null; } PreviewPane = new BalloonTip(this); PreviewPane.Offset = PreviewPaneOffset; PreviewPane.Closed += PreviewPane_Closed; PreviewPane.PositionOrder = PreviewPanePositionOrder; PreviewPane.ContentWidth = 250; PreviewPane.ContentHeight = 330; PreviewPane.Owner = Window.GetWindow(this); if (AssociatedControl == null) { AssociatedControl = AssociatedControlType.GetConstructor(new Type[0]).Invoke(null); } PreviewPane.Content = AssociatedControl; PreviewPane.Show(); OpenPreviewPane = PreviewPane; } else { PreviewPane.ResetTimer(); } }
public ControlPanelForm() { if (Instance != null) { Instance.WindowState = FormWindowState.Normal; Instance.Activate(); return; } Instance = this; Global.BusyForms.Enqueue(busyForm); InitializeComponent(); int interfaceHeight = 260; int interfaceWidth = 750; // resize Size minimumSize = new Size(interfaceWidth + 26, (interfaceHeight + 6) * Global.NetworkInterfaces.Count + 78); Rectangle screenRectangle = RectangleToScreen(ClientRectangle); int titleBarHeight = screenRectangle.Top - Top; int borderThickness = screenRectangle.Left - Left; Rectangle workingArea = Screen.GetWorkingArea(this); Size clientSize = new Size(); if (minimumSize.Width > workingArea.Width - 2 * borderThickness) { clientSize.Width = workingArea.Width - 2 * borderThickness; } else { clientSize.Width = minimumSize.Width; } if (minimumSize.Height > workingArea.Height - titleBarHeight - borderThickness) { clientSize.Height = workingArea.Height - titleBarHeight - borderThickness; } else { clientSize.Height = minimumSize.Height; } AutoScrollMinSize = new System.Drawing.Size(minimumSize.Width, minimumSize.Height); ClientSize = new Size(clientSize.Width, clientSize.Height); // populate int i = 0; foreach (NetworkInterface nic in Global.NetworkInterfaces.Values) { GroupBox groupBox = new GroupBox(); groupBox.Name = "interface" + nic.Guid; groupBox.Tag = nic.Guid; groupBox.Width = interfaceWidth; groupBox.Height = interfaceHeight; groupBox.Location = new Point(13, 68 + interfaceHeight * i); groupBox.Anchor = (AnchorStyles)(AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right); groupBox.MinimumSize = new System.Drawing.Size(interfaceWidth, interfaceHeight); groupBox.Controls.Add(CreateLabel(nic.Name, 10, 15, 340, true, "name")); groupBox.Controls["name"].Anchor = AnchorStyles.Left; if (!Global.Config.Gadget.HiddenInterfaces.Contains(nic.Guid)) { groupBox.Controls["name"].Font = new System.Drawing.Font(DefaultFont, FontStyle.Bold); } if (Global.InternetInterface != Guid.Empty) { if (nic.Guid == Global.InternetInterface) { groupBox.Controls["name"].ForeColor = Color.Blue; toolTip1.SetToolTip(groupBox.Controls["name"], "Internet (remote network connections) goes through this interface"); } } groupBox.Controls.Add(CreateListView("ipProperties")); Button button = new Button(); button.Name = "interfaceTools"; button.Text = "Interface tools"; button.Location = new Point(360, 15); button.Anchor = AnchorStyles.Right; button.Width = 100; button.Height = 20; ContextMenuStrip contextMenuStrip = new ContextMenuStrip(); ToolStripItem toolStripItem; toolStripItem = contextMenuStrip.Items.Add("Configure"); toolStripItem.Click += new EventHandler((s, e) => { new ConfigureInterface.ConfigureInterfaceForm(nic.Guid); }); toolStripItem = contextMenuStrip.Items.Add("Make primary"); toolStripItem.Click += new EventHandler((s, e) => { DialogResult result = MessageBox.Show( "This will configure all network interfaces so that \"" + nic.Name + "\" has the smallest metrics values of all, which will cause remote connectios to go through this interface when there are multiple NICs with a default gateway.\n\nDo you want to continue ?", "Make an interface primary", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == System.Windows.Forms.DialogResult.Yes) { MakeInterfacePrimary(nic.Guid); } }); toolStripItem.MouseHover += new EventHandler((s, e) => { new BalloonTip( "Make an interface primary", "This will configure all network interfaces so that \"" + nic.Name + "\" has the smallest metrics values of all, which will cause remote connectios to go through this interface when there are multiple NICs with a default gateway." , button, BalloonTip.ICON.INFO, 100000, false, false, (short)(button.PointToScreen(Point.Empty).X + button.Width / 2), (short)(button.PointToScreen(Point.Empty).Y + button.Height * 2.5)); }); toolStripItem.MouseLeave += new EventHandler((s, e) => { BalloonTip.CloseAll(); }); // TODO: add speed, lattency test and network map //toolStripItem = contextMenuStrip.Items.Add("Test performance"); //toolStripItem.Click += new EventHandler((s,e) => new InterfacePerformance.InterfacePerformanceForm(nic)); //contextMenuStrip.Items.Add("Test lattency").Enabled = false; button.Click += new EventHandler((s, e) => { contextMenuStrip.Show((Control)s, 0, ((Control)s).Height); }); groupBox.Controls.Add(button); groupBox.Controls.Add(CreateLabel("Adapter GUID:", 360, 40, 120)); groupBox.Controls.Add(CreateLabel("Description:", 360, 55, 120)); groupBox.Controls.Add(CreateLabel("Type:", 360, 70, 120)); groupBox.Controls.Add(CreateLabel("Interface Index:", 360, 85, 120)); groupBox.Controls.Add(CreateLabel("MAC Address", 360, 100, 120)); groupBox.Controls.Add(CreateLabel("Interface Metric:", 360, 115, 120)); groupBox.Controls.Add(CreateLabel("Lowest IPv4 metrics", 360, 145, 120, false, "lowestMetrics")); groupBox.Controls["lowestMetrics"].Font = new System.Drawing.Font(DefaultFont, FontStyle.Underline); groupBox.Controls.Add(CreateLabel("Gateway Metric:", 360, 160, 120)); groupBox.Controls.Add(CreateLabel("Route Metric:", 360, 175, 120)); groupBox.Controls.Add(CreateLabel("Public IPv4:", 360, 220, 120)); groupBox.Controls.Add(CreateLabel("Public IPv6:", 360, 235, 120)); groupBox.Controls.Add(CreateLabel(nic.Guid.ToString().ToUpper(), 480, 40, 265, true)); groupBox.Controls.Add(CreateLabel(nic.Description, 480, 55, 265, true)); groupBox.Controls.Add(CreateLabel(nic.Type.GetDescription(), 480, 70, 265, true)); groupBox.Controls.Add(CreateLabel(nic.Index.ToString(), 480, 85, 120, true)); groupBox.Controls.Add(CreateLabel(nic.Mac, 480, 100, 120, true)); groupBox.Controls.Add(CreateLabel(nic.InterfaceMetric.ToString(), 480, 115, 120, true)); groupBox.Controls.Add(CreateLabel(nic.IPv4Gateway.Count != 0 ? nic.IPv4Gateway.Min(x => x.GatewayMetric).ToString() : "", 480, 160, 120, true)); groupBox.Controls.Add(CreateLabel(nic.IPv4Gateway.Count != 0 ? nic.IPv4Gateway.Min(x => x.GatewayMetric + nic.InterfaceMetric).ToString() : "", 480, 175, 120, true)); groupBox.Controls.Add(CreateLabel(nic.PublicIPv4, 480, 220, 265, true, "publicIPv4")); groupBox.Controls.Add(CreateLabel(nic.PublicIPv6, 480, 235, 265, true, "publicIPv6")); groupBox.Controls.Add(CreateLabel("Download:", 600, 85, 65, false, "", Color.FromArgb(0x9b, 0x87, 0x0c))); groupBox.Controls.Add(CreateLabel("0 B/s", 600, 100, 65, false, "downByte", Color.FromArgb(0x9b, 0x87, 0x0c))); groupBox.Controls.Add(CreateLabel("0 b/s", 600, 115, 65, false, "downBit", Color.FromArgb(0x9b, 0x87, 0x0c))); groupBox.Controls.Add(CreateLabel(Unit.AutoScale(nic.IPv4BytesReceived, "B"), 600, 205, 65, false, "totalDown", Color.FromArgb(0x9b, 0x87, 0x0c))); groupBox.Controls.Add(CreateLabel("Upload:", 665, 85, 65, false, "", Color.Green, ContentAlignment.MiddleRight)); groupBox.Controls.Add(CreateLabel("0 B/s", 665, 100, 65, false, "upByte", Color.Green, ContentAlignment.MiddleRight)); groupBox.Controls.Add(CreateLabel("0 b/s", 665, 115, 65, false, "upBit", Color.Green, ContentAlignment.MiddleRight)); groupBox.Controls.Add(CreateLabel(Unit.AutoScale(nic.IPv4BytesSent, "B"), 665, 205, 65, false, "totalUp", Color.Green, ContentAlignment.MiddleRight)); groupBox.Controls.Add(CreateLabel("Total:", 650, 190, 65)); groupBox.Controls.Add(CreateGraph("graph", 600, 145)); // interface event subscriptions EventHandler <TextEventArgs> handler = new EventHandler <TextEventArgs>((s, e) => { try { Invoke(new Action(() => { if (nic.Guid == ((WinLib.Network.NetworkInterface)s).Guid) { groupBox.Controls["publicIPv4"].Text = e.Text; } })); } catch { } }); nic.PublicIPv4Changed += handler; publicIPv4Subscriptions.Add(nic, handler); handler = new EventHandler <TextEventArgs>((s, e) => { try { Invoke(new Action(() => { if (nic.Guid == ((WinLib.Network.NetworkInterface)s).Guid) { groupBox.Controls["publicIPv6"].Text = e.Text; } })); } catch { } }); nic.PublicIPv6Changed += handler; publicIPv6Subscriptions.Add(nic, handler); handler = new EventHandler <TextEventArgs>((s, e) => { try { Invoke(new Action(() => { if (nic.IPv4Address.Any(a => a.Address == e.Text)) { groupBox.Controls["name"].ForeColor = Color.Aqua; toolTip1.SetToolTip(groupBox.Controls["name"], "Internet (remote network connections) goes through this interface"); Global.InternetInterface = nic.Guid; } else { groupBox.Controls["name"].ForeColor = Color.Black; toolTip1.SetToolTip(groupBox.Controls["name"], ""); } })); } catch { } }); WinLib.Network.NetworkInterface.InternetInterfaceChanged += handler; internetInterfaceSubscriptions.Add(handler); Controls.Add(groupBox); i++; } ClientSize = new Size(ClientSize.Width + 70, ClientSize.Height); Location = new Point(workingArea.Left + workingArea.Width / 2 - Width / 2, workingArea.Top + workingArea.Height / 2 - Height / 2); Show(); }
private void UpdatePACFile() { string gfwlist; try { gfwlist = File.ReadAllText(Path.Combine(directory, gfwlist_file), Encoding.UTF8); } catch { gfwlist = Resources.gfwlist; File.WriteAllText(Path.Combine(directory, gfwlist_file), gfwlist, Encoding.UTF8); } string userRule; string userPath = Path.Combine(directory, user_rule_file); if (!File.Exists(userPath)) { userRule = Resources.user_rule; File.WriteAllText(Path.Combine(directory, user_rule_file), userRule, Encoding.UTF8); } else { //以只读共享方式打开文件 using (FileStream fs = new FileStream(userPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { int length = (int)fs.Length; byte[] content = new byte[length]; fs.Read(content, 0, content.Length); userRule = Encoding.UTF8.GetString(content); } } string abpContent; try { abpContent = File.ReadAllText(Path.Combine(directory, abp_js_file), Encoding.UTF8); } catch { FileUtil.UnGzip(Path.Combine(directory, abp_js_file), Resources.abp_js); abpContent = File.ReadAllText(Path.Combine(directory, abp_js_file), Encoding.UTF8); } try { List <string> lines = FileUtil.ParseResult(gfwlist); using (var sr = new StringReader(userRule)) { foreach (var rule in sr.NonWhiteSpaceLines()) { if (rule.BeginWithAny(FileUtil.IgnoredLineBegins)) { continue; } lines.Add(rule); } } abpContent = abpContent.Replace("__PROXY__", $"PROXY 127.0.0.1:{remotePort}"); abpContent = abpContent.Replace("__RULES__", JsonUtil.SerializeObject(lines)); if (File.Exists(Path.Combine(directory, pac_file))) { string original = File.ReadAllText(Path.Combine(directory, pac_file), Encoding.UTF8); if (original == abpContent) { return; } } File.WriteAllText(Path.Combine(directory, pac_file), abpContent, Encoding.UTF8); BalloonTip tip = new BalloonTip() { IconIndex = 1, Message = "Update PAC file success", timeout = 3000 }; ShowBalloonTip?.Invoke(this, tip); } catch (Exception) { BalloonTip tip = new BalloonTip() { IconIndex = 1, Message = "Update PAC file fail", timeout = 3000 }; ShowBalloonTip?.Invoke(this, tip); } }
private void btnTest_Click(object sender, EventArgs e) { var hint = new BalloonTip(); hint.Show("hi", "its work?", comboBoxUserActive, ToolTipIcon.Info, 2000); }