本文整理汇总了C#中System.Windows.Forms.DrawItemEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# DrawItemEventArgs类的具体用法?C# DrawItemEventArgs怎么用?C# DrawItemEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DrawItemEventArgs类属于System.Windows.Forms命名空间,在下文中一共展示了DrawItemEventArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDrawItem
/// <summary>Override for the drawing of the control to include a Close Tab button</summary>
/// <param name="e"></param>
protected override void OnDrawItem(DrawItemEventArgs e)
{
RectangleF tabTextArea = RectangleF.Empty;
for(int nIndex = 0 ; nIndex < this.TabCount ; nIndex++)
{
tabTextArea = (RectangleF)this.GetTabRect(nIndex);
using(SolidBrush brush = new SolidBrush(this.TabPages[nIndex].BackColor))
{
//Clear the tab
e.Graphics.FillRectangle(brush, tabTextArea);
}
Bitmap bmp = nIndex == this.SelectedIndex ? Resources.activeClose : Resources.inactiveClose;
e.Graphics.DrawImage(bmp, tabTextArea.X + tabTextArea.Width - (CLOSE_ICON_PADDING + CLOSE_ICON_SIZE), tabTextArea.Y + CLOSE_ICON_PADDING, CLOSE_ICON_SIZE, CLOSE_ICON_SIZE);
bmp.Dispose();
string str = this.TabPages[nIndex].Text;
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
using(SolidBrush brush = new SolidBrush(this.TabPages[nIndex].ForeColor))
{
//Draw the tab header text
e.Graphics.DrawString(str, this.Font, brush, tabTextArea,stringFormat);
}
}
}
示例2: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (e.Index < 0 || e.Index >= this.Items.Count)
return;
//e.DrawBackground();
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
LinearGradientBrush brush = new LinearGradientBrush(new Point(e.Bounds.X, e.Bounds.Y), new Point(e.Bounds.X, e.Bounds.Bottom),
Color.AliceBlue, Color.LightSkyBlue);
e.Graphics.FillRectangle(brush, e.Bounds);
}
else
e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);
e.DrawFocusRectangle();
ClipboardItem ci = (ClipboardItem)this.Items[e.Index];
/*e.Graphics.DrawString(ci.Name, this.Font, Brushes.Black, new PointF(2 + e.Bounds.X, 2 + e.Bounds.Y));
e.Graphics.DrawString(ci.AddtionalInfo, this.AddtionalInfoFont, Brushes.Gray, new PointF(2 + e.Bounds.X, 15 + e.Bounds.Y));*/
TextRenderer.DrawText(e.Graphics, ci.Name, this.Font, e.Bounds, Color.Black, Color.Transparent,
TextFormatFlags.Top | TextFormatFlags.Left | TextFormatFlags.EndEllipsis | TextFormatFlags.SingleLine);
TextRenderer.DrawText(e.Graphics, ci.AddtionalInfo, this.AddtionalInfoFont, e.Bounds, Color.Gray, Color.Transparent,
TextFormatFlags.Bottom | TextFormatFlags.Left);
base.OnDrawItem(e);
}
示例3: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Color BlockColor = Color.Empty;
int left = RECTCOLOR_LEFT;
if (e.State == DrawItemState.Selected || e.State == DrawItemState.None)
e.DrawBackground();
if (e.Index == -1)
{
BlockColor = SelectedIndex < 0 ? BackColor : DesignerUtility.ColorFromHtml(this.Text, Color.Empty);
}
else
BlockColor = DesignerUtility.ColorFromHtml((string)this.Items[e.Index], Color.Empty);
// Fill rectangle
if (BlockColor.IsEmpty && this.Text.StartsWith("="))
{
g.DrawString("fx", this.Font, Brushes.Black, e.Bounds);
}
else
{
g.FillRectangle(new SolidBrush(BlockColor), left, e.Bounds.Top + RECTCOLOR_TOP, RECTCOLOR_WIDTH,
ItemHeight - 2 * RECTCOLOR_TOP);
}
base.OnDrawItem(e);
}
示例4: cmb_Connection_DrawItem
private void cmb_Connection_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index < 0)
return;
ComboBox combo = sender as ComboBox;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
e.Graphics.FillRectangle(new SolidBrush(SystemColors.Highlight),
e.Bounds);
else
e.Graphics.FillRectangle(new SolidBrush(combo.BackColor),
e.Bounds);
string text = combo.Items[e.Index].ToString();
if (!MainV2.MONO)
{
text = text + " " + SerialPort.GetNiceName(text);
}
e.Graphics.DrawString(text, e.Font,
new SolidBrush(combo.ForeColor),
new Point(e.Bounds.X, e.Bounds.Y));
e.DrawFocusRectangle();
}
示例5: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
//Draw play button
e.Graphics.DrawImage(PlayButtonImage, e.Bounds.GetPlayButtonRectangleFromItemRectangle());
}
示例6: CustomItemDrawData
/// <summary>
/// Creates a new instance of the <see>CustomItemDrawData</see> object.
/// </summary>
/// <param name="args">The <see>DrawItemEventArgs</see> on which this instance is based.</param>
/// <param name="itemToDraw">The object to render.</param>
public CustomItemDrawData(DrawItemEventArgs args, object itemToDraw)
: base(args.Graphics, args.Font, args.Bounds, args.Index, args.State, args.ForeColor, args.BackColor)
{
Debug.Assert(!object.ReferenceEquals(null, itemToDraw));
m_item = itemToDraw;
}
示例7: OnDrawItem
/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.ListBox.DrawItem"/> event.
/// </summary>
/// <param name="e">A <see cref="T:System.Windows.Forms.DrawItemEventArgs"/> that contains the event data.</param>
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (DesignMode ||
!ControlHelper.DrawListItem<KeyValuePair<GameMessage, string>>(Items, e,
x => new KeyValuePair<string, string>(x.Key.ToString(), x.Value)))
base.OnDrawItem(e);
}
示例8: QuickSearchComboBox_DrawItem
/// <summary>
/// drawns the icon and the name of the element in the dropdown list
/// </summary>
/// <param name="sender">the sender</param>
/// <param name="e">the params</param>
private void QuickSearchComboBox_DrawItem(object sender, DrawItemEventArgs e)
{
//get the selected element and its associated image
if (0 <= e.Index && e.Index < this.Items.Count)
{
UML.Extended.UMLItem selectedElement = this.Items[e.Index] as UML.Extended.UMLItem;
if (selectedElement != null)
{
Image elementImage = this.navigatorVisuals.getImage(selectedElement);
//draw standard background and focusrectangle
e.DrawBackground();
e.DrawFocusRectangle();
//draw the name of the element
e.Graphics.DrawString(this.navigatorVisuals.getNodeName(selectedElement), e.Font, new SolidBrush(e.ForeColor),
new Point(elementImage.Width + 2,e.Bounds.Y));
// draw the icon
e.Graphics.DrawImage(elementImage, new Point(e.Bounds.X, e.Bounds.Y));
// draw tooltip
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
this.itemTooltip.Show(selectedElement.fqn,
this, e.Bounds.Right, e.Bounds.Bottom);
}
else
{
this.itemTooltip.Hide(this);
}
}
}
}
示例9: comboBox2_DrawItem
private void comboBox2_DrawItem(object sender, DrawItemEventArgs e)
{
Rectangle listBound = e.Bounds;
Font listFond = null;
switch (e.Index)
{
case 0:
listFond = new Font(e.Font, FontStyle.Regular);
break;
case 2:
listFond = new Font(e.Font, FontStyle.Bold);
break;
case 1:
listFond = new Font(e.Font, FontStyle.Italic);
break;
case 3:
listFond = new Font(e.Font, FontStyle.Bold|FontStyle.Italic);
break;
}
string str = comboBox2.Items[e.Index].ToString();
Brush bru = new SolidBrush(Color.Black);
Graphics g = e.Graphics;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
g.FillRectangle(new SolidBrush(Color.FromArgb(0xFF,0x33,0x99,0xFF)), listBound);
g.DrawString(str, listFond, new SolidBrush(Color.White), listBound);
}
else
{
g.FillRectangle(new SolidBrush(Color.White), listBound);
g.DrawString(str, listFond, bru, listBound);
}
}
示例10: Drawitem
public void Drawitem(object sender, DrawItemEventArgs e)
{
if (e.Index < 0)
return;
e.DrawBackground();
e.DrawFocusRectangle();
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
//-- if selected
if (e.State.ToString().IndexOf("Selected,") >= 0)
{
//-- Base
e.Graphics.FillRectangle(new SolidBrush(_SelectedColor), new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
//-- Text
e.Graphics.DrawString(" " + ListBx.Items[e.Index].ToString(), new Font("Segoe UI", 8), Brushes.White, e.Bounds.X, e.Bounds.Y + 2);
}
else
{
//-- Base
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(51, 53, 55)), new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
//-- Text
e.Graphics.DrawString(" " + ListBx.Items[e.Index].ToString(), new Font("Segoe UI", 8), Brushes.White, e.Bounds.X, e.Bounds.Y + 2);
}
e.Graphics.Dispose();
}
示例11: SecurityCB_DrawItem
private void SecurityCB_DrawItem(object sender, DrawItemEventArgs e)
{
// If the index is invalid then simply exit.
if (e.Index == -1 || e.Index >= SecurityCB.Items.Count)
{
return;
}
// Draw the background of the item.
e.DrawBackground();
// Should we draw the focus rectangle?
if ((e.State & DrawItemState.Focus) != 0)
{
e.DrawFocusRectangle();
}
Font f = new Font(e.Font, FontStyle.Regular);
// Create a new background brush.
Brush b = new SolidBrush(e.ForeColor);
// Draw the item.
Security security = (Security)SecurityCB.Items[e.Index];
string name = security.ToString();
SizeF s = e.Graphics.MeasureString(name, f);
e.Graphics.DrawString(name, f, b, e.Bounds);
}
示例12: lstFunnel_DrawItem
private void lstFunnel_DrawItem(object sender, DrawItemEventArgs e)
{
dontRefresh = true;
e.DrawBackground();
FontStyle fs = FontStyle.Regular;
Brush b = Brushes.Black;
if (unselectableFunnelLines.Contains(e.Index))
{
b = Brushes.Gray;
fs = FontStyle.Italic;
if (e.State.HasFlag(DrawItemState.Selected))
{
//b = Brushes.White;
lstFunnel.SelectedIndex = -1;
lstFunnel.Invalidate();
}
e.Graphics.DrawString(lstFunnel.Items[e.Index].ToString(), new Font("Microsoft Sans Serif", 8, fs), b, e.Bounds);
}
else
{
if (e.State.HasFlag(DrawItemState.Selected)) b = Brushes.White;
e.Graphics.DrawString(lstFunnel.Items[e.Index].ToString(), new Font("Microsoft Sans Serif", 8, fs), b, e.Bounds);
e.DrawFocusRectangle();
}
dontRefresh = false;
}
示例13: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (e.Index < 0 || e.Index >= Items.Count) return;
var item = (Item)this.Items[e.Index];
var image = item.Title;
var drawWidth = (int)(image.Width * scalingFactor);
var drawHeight = (int)(image.Height * scalingFactor);
var destRect = new Rectangle(e.Bounds.Location,
new Size(drawWidth, drawHeight));
// we need to manually add xMargin to the offset again, as it's
// already subtracted from the actual list width in GetListWidth
destRect.Offset((GetListWidth() - drawWidth + xMargin) / 2, yMargin);
// background
e.Graphics.FillRectangle(Brushes.Black, e.Bounds);
// separator
if (e.Index > 0)
{
e.Graphics.DrawLine(Pens.DimGray,
e.Bounds.Left + 5, e.Bounds.Top + 1,
e.Bounds.Right - 5, e.Bounds.Top + 1);
destRect.Offset(0, 3);
}
// title
e.Graphics.DrawImage(image, destRect,
new Rectangle(new Point(), image.Size), GraphicsUnit.Pixel);
}
示例14: OnDrawItem
/// <summary>
/// Custom Draw Item Handler.
/// It fires when painting each item in dropdown list. We use item value (text) to create the path to picture in resource and paint it in the list.
/// </summary>
/// <param name="e">Arguments from DrawItem Event</param>
protected override void OnDrawItem(DrawItemEventArgs e)
{
// Draw background and focus rectangle, if necessary.
e.DrawBackground();
e.DrawFocusRectangle();
// If something is selected, paint it
if (e.Index > -1)
{
// Get text from current item
var text = (string)Items[e.Index];
// Get resource path to picture
var resource = string.Format("HSCardGenerator.Resources.Images.Flags.{0}.png", text.ToLower());
// Read it as stream
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
{
// And paint it
e.Graphics.DrawImage(Image.FromStream(stream), new PointF(e.Bounds.X, e.Bounds.Y));
}
// Draw text if necessary
if (showLabels)
{
// Same as for OnPaint event
var txt = Config.localesFull[(int)Methods.General.getLocaleFromString(text)];
var limits = e.Graphics.MeasureString(txt, e.Font);
var top = (24 - limits.Height) / 2;
e.Graphics.DrawString(txt, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left + 24, e.Bounds.Top + top);
}
// We need to do this, no wonder why :/
if ((e.Index == SelectedIndex) && (DroppedDown == false))
{
e.DrawFocusRectangle();
}
}
}
示例15: DrawPanel
public virtual void DrawPanel(DrawItemEventArgs e)
{
string text = base.Text;
if ((text != null) && (text.Length != 0))
{
int num = 0;
StringFormat format = new StringFormat(StringFormatFlags.NoWrap);
format.LineAlignment = StringAlignment.Center;
format.HotkeyPrefix = HotkeyPrefix.Hide;
format.Trimming = StringTrimming.EllipsisCharacter;
switch (base.Alignment)
{
case HorizontalAlignment.Right:
format.Alignment = StringAlignment.Far;
break;
case HorizontalAlignment.Center:
format.Alignment = StringAlignment.Center;
break;
default:
format.Alignment = StringAlignment.Near;
num = 3;
break;
}
Rectangle layoutRectangle = new Rectangle((e.Bounds.X + 1) + num, e.Bounds.Y, (e.Bounds.Width - 2) - num, e.Bounds.Height);
e.Graphics.DrawString(base.Text, base.Parent.Font, SystemBrushes.ControlText, layoutRectangle, format);
format.Dispose();
}
this.DrawPanelBorder(e);
}