private void DrawText(NDIAvailNetworkListboxColumnText textItem, int xPos, int yPos, int colWidth, DrawItemEventArgs e) { string text = textItem.Text; Color color = Color.Black; if (!this.Enabled) color = SystemColors.GrayText; if (text == null) return; string s = text.Trim(); using (SolidBrush solidBrush = new SolidBrush(color)) e.Graphics.DrawString(s, this.Font, (Brush) solidBrush, (float) xPos, (float) yPos); }
private void DrawText(NetworkDisplayItem ndi, NDIAvailNetworkListboxColumnText textItem, int xPos, int yPos, int colWidth, DrawItemEventArgs e) { string text = textItem.Text; Color color = Color.Black; if (!this.Enabled) color = SystemColors.GrayText; if (text == null) return; string str = text.Trim(); bool disposeFont = false; Font fontForNetwork = this.GetFontForNetwork(ndi, ref disposeFont); if (fontForNetwork == null) return; SizeF sizeF = e.Graphics.MeasureString(str, fontForNetwork); if (SizeHelper.MeasureDisplayStringWidth(e.Graphics, str, fontForNetwork) > colWidth) { int num = 0; for (int length = str.Length - 1; length >= 0; --length) { if (textItem.ValidLineBreakChars.Contains(str[length]) && (double) e.Graphics.MeasureString(str.Substring(0, length), fontForNetwork).Width < (double) colWidth) { num = length + 1; break; } } if ((double) num <= (double) str.Length * 0.3333) num = str.Length / 2; using (SolidBrush solidBrush = new SolidBrush(color)) { e.Graphics.DrawString(str.Substring(0, num), fontForNetwork, (Brush) solidBrush, (float) xPos, (float) yPos); e.Graphics.DrawString(str.Substring(num), fontForNetwork, (Brush) solidBrush, (float) xPos, (float) ((double) yPos + (double) sizeF.Height + 3.0)); } } else { using (SolidBrush solidBrush = new SolidBrush(color)) e.Graphics.DrawString(str, fontForNetwork, (Brush) solidBrush, (float) xPos, (float) yPos); } if (!disposeFont) return; fontForNetwork.Dispose(); }