public static Size GetTipSize(Control control, Graphics graphics, TipSection tipData) { Size tipSize = Size.Empty; SizeF tipSizeF = SizeF.Empty; if (workingArea == RectangleF.Empty) { Form ownerForm = control.FindForm(); if (ownerForm.Owner != null) { ownerForm = ownerForm.Owner; } workingArea = Screen.GetWorkingArea(ownerForm); } PointF screenLocation = control.PointToScreen(Point.Empty); SizeF maxLayoutSize = new SizeF(workingArea.Right - screenLocation.X - HorizontalBorder * 2, workingArea.Bottom - screenLocation.Y - VerticalBorder * 2); if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) { graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; tipData.SetMaximumSize(maxLayoutSize); tipSizeF = tipData.GetRequiredSize(); tipData.SetAllocatedSize(tipSizeF); tipSizeF += new SizeF(HorizontalBorder * 2, VerticalBorder * 2); tipSize = Size.Ceiling(tipSizeF); } if (control.ClientSize != tipSize) { control.ClientSize = tipSize; } return tipSize; }
public async Task <CardSectionDataTaskResult <CardSectionMessage> > Process(CardSectionMessage cardSectionData) { var cardSectionDataTaskResult = new CardSectionDataTaskResult <CardSectionMessage> { CardSectionData = cardSectionData }; var card = await _cardService.CardByName(cardSectionData.Name); if (card != null) { await _cardTipService.DeleteByCardId(card.Id); var newTipSectionList = new List <TipSection>(); foreach (var cardSection in cardSectionData.CardSections) { var newTipSection = new TipSection { CardId = card.Id, Name = cardSection.Name, Created = DateTime.UtcNow, Updated = DateTime.UtcNow }; foreach (var tip in cardSection.ContentList) { newTipSection.Tip.Add(new Tip { TipSection = newTipSection, Text = tip, Created = DateTime.UtcNow, Updated = DateTime.UtcNow }); } newTipSectionList.Add(newTipSection); } if (newTipSectionList.Any()) { await _cardTipService.Update(newTipSectionList); } } else { cardSectionDataTaskResult.Errors.Add($"Card Tips: card '{cardSectionData.Name}' not found."); } return(cardSectionDataTaskResult); }
public static Size DrawTip(Control control, Graphics graphics, TipSection tipData) { Size tipSize = Size.Empty; SizeF tipSizeF = SizeF.Empty; PointF screenLocation = control.PointToScreen(Point.Empty); if (workingArea == RectangleF.Empty) { Form ownerForm = control.FindForm(); if (ownerForm.Owner != null) { ownerForm = ownerForm.Owner; } workingArea = Screen.GetWorkingArea(ownerForm); } SizeF maxLayoutSize = new SizeF(workingArea.Right - screenLocation.X - HorizontalBorder * 2, workingArea.Bottom - screenLocation.Y - VerticalBorder * 2); if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) { graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; tipData.SetMaximumSize(maxLayoutSize); tipSizeF = tipData.GetRequiredSize(); tipData.SetAllocatedSize(tipSizeF); tipSizeF += new SizeF(HorizontalBorder * 2, VerticalBorder * 2); tipSize = Size.Ceiling(tipSizeF); } if (control.ClientSize != tipSize) { control.ClientSize = tipSize; } if (tipSize != Size.Empty) { Rectangle borderRectangle = new Rectangle(Point.Empty, tipSize - new Size(1, 1)); RectangleF displayRectangle = new RectangleF(HorizontalBorder, VerticalBorder, tipSizeF.Width - HorizontalBorder * 2, tipSizeF.Height - VerticalBorder * 2); // DrawRectangle draws from Left to Left + Width. A bug? :-/ graphics.DrawRectangle(SystemPens.WindowFrame, borderRectangle); tipData.Draw(new PointF(HorizontalBorder, VerticalBorder)); } return tipSize; }