protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (HoverImageUrl.HasValue()) { AlternateText = AlternateText.Or(Text); } ImageUrl = Page.ResolveUrl(ImageUrl); if (HoverImageUrl.HasValue()) { Attributes.Add("onmouseover", "this.src='" + Page.ResolveUrl(HoverImageUrl) + "';"); Attributes.Add("onfocus", "this.src='" + Page.ResolveUrl(HoverImageUrl) + "';"); Attributes.Add("onmouseout", "this.src='" + Page.ResolveUrl(ImageUrl) + "';"); Attributes.Add("onblur", "this.src='" + Page.ResolveUrl(ImageUrl) + "';"); } if (HoverImageUrl.HasValue()) { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "Preload" + Page.ResolveUrl(HoverImageUrl), "preloadImages('" + Page.ResolveUrl(HoverImageUrl) + "');", addScriptTags: true); } }
public override int GetHashCode() { unchecked { var hashCode = MediaUrl?.GetHashCode() ?? 0; hashCode = (hashCode * 397) ^ (MimeType?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Caption?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (AlternateText?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (FolderPath?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (FileName?.GetHashCode() ?? 0); return(hashCode); } }
public override int GetHashCode() { unchecked { var hashCode = Align?.GetHashCode() ?? 0; hashCode = (hashCode * 397) ^ (AlternateText?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Attributes?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Float?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ Height.GetHashCode(); hashCode = (hashCode * 397) ^ (Link?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Path?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Role?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Title?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ Width.GetHashCode(); return(hashCode); } }
public string CalculateAlternateText(Graphics g, float width) { var actualText = Text; ActualWidth = g.MeasureString(Text, Font, 9999, Format).Width; foreach (var curText in AlternateText.OrderByDescending(x => x.Length)) { if (width < ActualWidth) { actualText = curText; ActualWidth = g.MeasureString(actualText, Font, 9999, Format).Width; } else { break; } } return(actualText); }
public void Draw(Graphics g) { var format = new StringFormat { Alignment = HorizontalAlignment, LineAlignment = VerticalAlignment, FormatFlags = StringFormatFlags.NoWrap, Trimming = StringTrimming.EllipsisCharacter }; if (!IsMonospaced) { var actualText = Text; ActualWidth = g.MeasureString(Text, Font, 9999, format).Width; foreach (var curText in AlternateText.OrderByDescending(x => x.Length)) { if (Width < ActualWidth) { actualText = curText; ActualWidth = g.MeasureString(actualText, Font, 9999, format).Width; } else { break; } } if (HasShadow) { using (var shadowBrush = new SolidBrush(ShadowColor)) { g.DrawString(actualText, Font, shadowBrush, new RectangleF(X + 1, Y + 1, Width, Height), format); g.DrawString(actualText, Font, shadowBrush, new RectangleF(X + 2, Y + 2, Width, Height), format); } } g.DrawString(actualText, Font, Brush, new RectangleF(X, Y, Width, Height), format); } else { var monoFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = VerticalAlignment }; var measurement = TextRenderer.MeasureText(g, "0", Font, new Size((int)(Width + 0.5f), (int)(Height + 0.5f)), TextFormatFlags.NoPadding).Width; var offset = Width; var charIndex = 0; SetActualWidth(g); var cutOffText = CutOff(g); offset = Width - MeasureActualWidth(cutOffText, g); if (HorizontalAlignment != StringAlignment.Far) { offset = 0f; } while (charIndex < cutOffText.Length) { var curOffset = 0f; var curChar = cutOffText[charIndex]; if (char.IsDigit(curChar)) { curOffset = measurement; } else { curOffset = TextRenderer.MeasureText(g, curChar.ToString(), Font, new Size((int)(Width + 0.5f), (int)(Height + 0.5f)), TextFormatFlags.NoPadding).Width; } if (HasShadow) { using (var shadowBrush = new SolidBrush(ShadowColor)) { g.DrawString(curChar.ToString(), Font, shadowBrush, new RectangleF(X + 1 + offset - curOffset * 2f, Y + 1, curOffset * 5f, Height), monoFormat); g.DrawString(curChar.ToString(), Font, shadowBrush, new RectangleF(X + 2 + offset - curOffset * 2f, Y + 2, curOffset * 5f, Height), monoFormat); } } g.DrawString(cutOffText[charIndex].ToString(), Font, Brush, new RectangleF(X + offset - curOffset / 2f, Y, curOffset * 2f, Height), monoFormat); charIndex++; offset += curOffset; } } /*if (HasGlassEffects) * { * var glassBrush = new LinearGradientBrush( * new PointF(0.0f, 0.0f), * new PointF(0.0f, Height), * Color.Transparent, * Color.Transparent); * * var cb = new ColorBlend(); * cb.Positions = new float[] { 0f, 0.5f, 0.55f, 1f }; * var c1 = Color.FromArgb(150, Color.White); * var c2 = Color.FromArgb(100, Color.White); * cb.Colors = new Color[] { c1, c2, Color.FromArgb(255, Color.Black), Color.Transparent }; * * glassBrush.InterpolationColors = cb; * * g.DrawString(cutOffText, Font, glassBrush, new RectangleF(X, Y, Width, Height), format); * }*/ }