/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Resize" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param> protected override void OnResize(EventArgs e) { if (Width > Height) { Height = Width; } else { Width = Height; } TextRect = new Rectangle(Convert.ToInt32(Width * 0.05), Convert.ToInt32(Height * 0.05), Convert.ToInt32(Width * 0.9), Convert.ToInt32(Height * 0.9)); Region = new Region(DrawHelper.CreateCircle(0, 0, Width / 2)); CalculateAvatarFont(); if (ShadowBorder != null) { ShadowBorder.Dispose(); } ShadowBorder = new GraphicsPath(); ShadowBorder = DrawHelper.CreateCircle(Location.X, Location.Y, ClientRectangle.Width / 2 - 1); if (_AvatarScaled != null) { _AvatarScaled.Dispose(); _AvatarScaled = DrawHelper.ResizeImage(_Avater, Width, Height); } }
/// <summary> /// Redraws the specified sender. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void Redraw(object sender, System.EventArgs e) { if (ShadowBorder != null) { ShadowBorder.Dispose(); } ShadowBorder = new GraphicsPath(); ShadowBorder = DrawHelper.CreateCircle(Location.X, Location.Y, ClientRectangle.Width / 2 - 1); if (Width != Height) { Width = Math.Min(Width, Height); Height = Math.Min(Width, Height); } Invalidate(); }
private Element BuildNotificationsContent() { if (_notifications.Count == 0) { return(new Border()); } var container = new StackPanel { Orientation = Orientation.Vertical, Margin = new Thickness(0, Scale(6), 0, 0) }; for (var i = 0; i < Math.Min(_notifications.Count, MaxNotifications); i++) { var notification = _notifications[i]; var image = new Border { BorderThickness = new Thickness(0, 0, Scale(1), 0), BorderBrush = SolidBrush.LightGray, Content = new Image { Bitmap = GetImage(notification.Kind), Stretch = Stretch.UniformToFill, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(6) } }; var text = new StackPanel { Orientation = Orientation.Vertical, Margin = new Thickness(Scale(6), Scale(4)), Children = { new TextBlock(notification.Title) } }; if (notification.Message != null) { text.Children.Add(new TextBlock(notification.Message)); } if (notification.Poster != null) { text.Children.Add(new TextBlock($"By {notification.Poster}") { ForeColor = Color.Gray }); } var close = new Button { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top, Cursor = GdiPresentation.Cursor.Default, Content = new Image { Margin = new Thickness(Scale(4)), Bitmap = IconClose.GetScaled(_dpi) } }; Grid.SetColumn(text, 1); Grid.SetColumn(close, 1); var content = new Grid { RowDefinitions = { new RowDefinition(GridLength.Auto) }, ColumnDefinitions = { new ColumnDefinition(GridLength.Auto), new ColumnDefinition(new GridLength(GridUnitType.Star, 1)) }, Children = { image, text, close }, }; if (notification.ParentId.HasValue) { content.Cursor = GdiPresentation.Cursor.Hand; content.Background = SolidBrush.Transparent; content.MouseUp += (s, e) => _synchronizer.OpenPost(notification.ParentId.Value); } var shadowColor = Color.LightGray; var notificationElement = new ShadowBorder { Margin = new Thickness(0, Scale(2)), BorderStartColor = new Color(0, shadowColor.R, shadowColor.G, shadowColor.B), BorderEndColor = shadowColor, BorderWidth = Scale(2), Content = new Border { Background = Brush.White, Content = content } }; long id = notification.Id.Value; close.Click += (s, e) => CloseNotification(id); container.Children.Add(notificationElement); } if (_notifications.Count > MaxNotifications) { container.Children.Add(new Image { Bitmap = IconMore.GetScaled(_dpi), HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(Scale(4), 0) }); } return(container); }