本文整理汇总了C#中System.Windows.Forms.DrawItemEventArgs.DrawBackground方法的典型用法代码示例。如果您正苦于以下问题:C# DrawItemEventArgs.DrawBackground方法的具体用法?C# DrawItemEventArgs.DrawBackground怎么用?C# DrawItemEventArgs.DrawBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DrawItemEventArgs
的用法示例。
在下文中一共展示了DrawItemEventArgs.DrawBackground方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();
if (e.Index >= 0 && e.Index < Items.Count)
{
Device dev = (Device)Items[e.Index];
Image image = ImageList.Images[dev.ImageKey];
image = ResizeImage(image, 48, 48);
Rectangle r = e.Bounds;
r.Size = image.Size;
r.X += 2;
r.Y += (e.Bounds.Height - r.Height) / 2;
e.Graphics.DrawImageUnscaled(image, r);
r = e.Bounds;
r.X += image.Width + 2;
r.Width -= image.Width + 2;
using (StringFormat sf = new StringFormat())
{
sf.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString(dev.Name, Font, new SolidBrush(ForeColor), r, sf);
}
}
base.OnDrawItem(e);
}
示例2: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Rectangle area = e.Bounds;
Rectangle iconArea = area;
iconArea.Width = 16;
if (e.Index >= 0)
{
e.DrawBackground();
Entity ent = (Entity)Items[e.Index];
int dist = (int)Vector3i.Distance(ent.Pos, PlayerPos);
// Draw entity icon
g.DrawImage(ent.Image, iconArea);
// Entity name
SizeF entName = g.MeasureString(ent.ToString(), this.Font);
Rectangle ctxt = area;
ctxt.X = iconArea.Right + 3;
ctxt.Width = (int)entName.Width + 1;
g.DrawString(ent.ToString(), this.Font, new SolidBrush(e.ForeColor), ctxt);
// Distance.
string derp = string.Format("({0}m away)", dist);
SizeF entDist = g.MeasureString(derp, this.Font);
Rectangle distArea = area;
distArea.X = ctxt.Right + 3;
distArea.Width = (int)entDist.Width;
g.DrawString(derp, this.Font, new SolidBrush(Color.FromArgb(128, e.ForeColor)), distArea);
}
}
示例3: OnDrawItem
protected override void OnDrawItem( DrawItemEventArgs e )
{
e.DrawBackground();
e.DrawFocusRectangle();
if( e.Index > -1 )
{
ComboBoxItem itm = (( ComboBoxItem ) Items[ e.Index ]);
int x = e.Bounds.Left + ( 16 - itm.Img.Width ) / 2,
y = ( 15 - itm.Img.Height ) / 2,
w = itm.Img.Width,
h = itm.Img.Height;
x = ( x > 0 ) ? x : 0;
y = (( y > 0 ) ? y : 0 ) + e.Bounds.Top;
w = ( w > 15 ) ? 15 : w;
h = ( h > 15 ) ? 15 : h;
e.Graphics.DrawImage( itm.Img,
new Rectangle( x, y, w, h ),
new Rectangle( 0, 0, itm.Img.Width, itm.Img.Height ),
GraphicsUnit.Pixel );
e.Graphics.DrawString( itm.Text,
e.Font,
new SolidBrush( e.ForeColor ),
x + w,
e.Bounds.Top + 2 );
}
base.OnDrawItem( e );
}
示例4: OnDrawItem
/// <summary>
/// Owner drawing listview item.
/// </summary>
protected void OnDrawItem( DrawItemEventArgs e, PluginListItem item )
{
e.DrawBackground();
// IsRunnning bitmap
const int imageWidth = 16+3;
if(imageList==null)
imageList = ((PluginDialog)Parent).ImageList;
if(imageList!=null)
{
int imageIndex = item.PluginInfo.IsCurrentlyLoaded ? 0 : 1;
imageList.Draw(e.Graphics, e.Bounds.Left+2, e.Bounds.Top+1, imageIndex);
}
// Name
Rectangle bounds = Rectangle.FromLTRB(e.Bounds.Left+imageWidth,
e.Bounds.Top, e.Bounds.Left+Columns[0].Width, e.Bounds.Bottom);
using(Brush brush = new SolidBrush(e.ForeColor))
e.Graphics.DrawString(item.Name, e.Font, brush, bounds);
// Check box (Load at startup)
bounds = Rectangle.FromLTRB(bounds.Right+1,
bounds.Top, bounds.Right+Columns[1].Width+1, bounds.Bottom-1);
ButtonState state = item.PluginInfo.IsLoadedAtStartup ? ButtonState.Checked : ButtonState.Normal;
ControlPaint.DrawCheckBox(e.Graphics, bounds, state);
}
示例5: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs ea)
{
ea.DrawBackground();
ea.DrawFocusRectangle();
if (ea.Index == -1)
return;
Rectangle bounds = ea.Bounds;
var foreBrush = new SolidBrush(ea.ForeColor);
int textLeftBound = (IconList == null) ? bounds.Left : bounds.Left + IconList.ImageSize.Width;
var drawObject = Items[ea.Index];
if (drawObject is ImageComboBoxItem) {
var drawItem = (ImageComboBoxItem)drawObject;
if (drawItem.ImageListIndex != -1 && IconList != null) {
//ea.Graphics.FillRectangle(Brushes.Gray, bounds.Left, bounds.Top, IconList.ImageSize.Width, IconList.ImageSize.Height);
ea.Graphics.DrawImage(IconList.Images[drawItem.ImageListIndex], bounds.Left, bounds.Top);
}
ea.Graphics.DrawString(drawItem.Text, ea.Font, foreBrush, textLeftBound, bounds.Top);
}
else {
ea.Graphics.DrawString(drawObject.ToString(), ea.Font, foreBrush, textLeftBound, bounds.Top);
}
base.OnDrawItem(ea);
}
示例6: 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;
}
示例7: 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);
}
示例8: drawItems
private void drawItems(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
int i = e.Index;
if (i != -1)
{
Font myFont;
Brush myBrush;
string dir = currentDir + "\\" + MovieBox.Items[i];
string[] content = Directory.GetFiles(dir, "*.nfo", SearchOption.TopDirectoryOnly);
if (content.Length == 0 && i != 0)
{
myFont = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold);
myBrush = Brushes.Red;
}
else
{
myFont = e.Font;
myBrush = Brushes.Black;
}
e.Graphics.DrawString(MovieBox.Items[i].ToString(), myFont, myBrush, e.Bounds, StringFormat.GenericDefault);
}
}
示例9: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();
if (e.Index < 0)
return;
FontFamily fontFamily = Items[e.Index] as FontFamily;
if ((e.State & DrawItemState.ComboBoxEdit) != 0)
{
Font font = e.Font;
if (DrawFontInEditBox)
{
if (!fontsInCache)
{
font = CreateDefaultFont(fontFamily, e.Font.Size);
if (font == null)
font = e.Font;
}
else
{
font = fonts[fontFamily.Name];
if (font == null)
font = e.Font;
}
}
e.Graphics.DrawString(fontFamily.Name, font, new SolidBrush(e.ForeColor),
e.Bounds.Left, e.Bounds.Top);
}
else
{
Font font = e.Font;
if (DrawFont)
{
if (!fontsInCache)
{
font = CreateDefaultFont(fontFamily, e.Font.Size);
if (font == null)
font = e.Font;
}
else
{
font = fonts[fontFamily.Name];
if (font == null)
font = e.Font;
}
}
e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed;
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
e.Graphics.DrawString(fontFamily.Name, font, new SolidBrush(e.ForeColor),
e.Bounds.Left, e.Bounds.Top);
}
}
示例10: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs e)
{
e.DrawBackground();
if (Items.Count <= 0)
{
base.OnDrawItem(e);
return;
}
Color color;
color = ColorGetter == null ? SystemColors.WindowText
: ColorGetter(e.Index, Items[e.Index]);
if(color == SystemColors.WindowText
&& ((e.State & DrawItemState.Selected) == DrawItemState.Selected))
color = SystemColors.HighlightText;
using (Brush b = new SolidBrush(color))
{
e.Graphics.DrawString(Convert.ToString(Items[e.Index]), e.Font, b, e.Bounds);
}
if((e.State & DrawItemState.Focus) == DrawItemState.Focus)
{
ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds);
}
}
示例11: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (e.Index >= 0 && e.Index < Items.Count)
{
this.ItemHeight = newItemHeight;
Window window = Items[e.Index] as Window;
String title = window.getTitle().Replace("&", "&&");
String processName = window.getProcessName().Replace("&", "&&");
e.DrawBackground();
// Draw icon
Icon icon = window.getIcon();
if (icon != null)
{
Image image = (Image)new Bitmap(icon.ToBitmap(), new Size(iconSize, iconSize));
e.Graphics.DrawImage(image, iconMargin, e.Bounds.Y + iconMargin);
}
// Draw window title
Rectangle titleRect = e.Bounds;
titleRect.Height /= 2;
titleRect.X += iconSize + 3 * iconMargin;
titleRect.Width -= iconSize + 3 * iconMargin;
TextRenderer.DrawText(e.Graphics, title, titleFont, titleRect, e.ForeColor, titleFlags);
// Draw process name title
Rectangle processRect = titleRect;
processRect.Y += processRect.Height;
TextRenderer.DrawText(e.Graphics, processName, processFont, processRect, processColor, processFlags);
e.DrawFocusRectangle();
}
}
示例12: settings2_3_booknamefont_DrawItem
private void settings2_3_booknamefont_DrawItem(object sender, DrawItemEventArgs e)
{
Font objFonts = new Font(settings2_3_booknamefont.Items[e.Index].ToString(), 14);
e.DrawBackground();
e.Graphics.DrawString(settings2_3_booknamefont.Items[e.Index].ToString(), objFonts, new SolidBrush(e.ForeColor), new Point(e.Bounds.Left, e.Bounds.Top));
}
示例13: comboBoxColor_DrawItem
private void comboBoxColor_DrawItem(object sender, DrawItemEventArgs e)
{
var box = (ComboBox) sender;
if ((e.State & DrawItemState.Selected) != DrawItemState.None) {
e.DrawBackground();
}
else {
e.Graphics.FillRectangle(Brushes.White, e.Bounds);
}
if ((e.State & DrawItemState.Focus) != DrawItemState.None) {
e.DrawFocusRectangle();
}
if (e.Index == 0) {
e.Graphics.DrawString(box.Items[e.Index].ToString(), box.Font, Brushes.Black, e.Bounds);
}
else if ((e.Index >= 0) && (e.Index < box.Items.Count)) {
var bounds = e.Bounds;
bounds.Inflate(-16, -2);
var boxItems = box.Items[e.Index] as string;
if (boxItems == null) {
return;
}
using (var brush = new SolidBrush(Color.FromArgb(int.Parse(boxItems.Substring(1))))) {
e.Graphics.FillRectangle(brush, bounds);
e.Graphics.DrawRectangle(Pens.Black, bounds);
}
}
}
示例14: OnDrawItem
protected override void OnDrawItem( DrawItemEventArgs e )
{
if ( Items.Count == 0 )
{
base.OnDrawItem( e );
return;
}
if ( Items[ e.Index ] is Friend )
{
Friend friendObj = ( Friend )Items[ e.Index ];
this.DrawMode = DrawMode.OwnerDrawFixed;
e.DrawBackground();
e.DrawFocusRectangle();
EPersonaState state = SteamContext.SteamFriends.GetFriendPersonaState( friendObj.SteamID );
if ( state == EPersonaState.k_EPersonaStateOffline )
e.Graphics.DrawString( friendObj.PersonaName, e.Font, new SolidBrush( Color.Red ), e.Bounds );
else
e.Graphics.DrawString( friendObj.PersonaName, e.Font, new SolidBrush( Color.Green ), e.Bounds );
}
}
示例15: OnDrawItem
// Draw list item
protected void OnDrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index >= 0)
{
// Get this color
ColorInfo color = (ColorInfo)Items[e.Index];
// Fill background
e.DrawBackground();
// Draw color box
Rectangle rect = new Rectangle();
rect.X = e.Bounds.X + 2;
rect.Y = e.Bounds.Y + 2;
rect.Width = 18;
rect.Height = e.Bounds.Height - 5;
e.Graphics.FillRectangle(new SolidBrush(color.Color), rect);
e.Graphics.DrawRectangle(SystemPens.WindowText, rect);
// Write color name
Brush brush;
if ((e.State & DrawItemState.Selected) != DrawItemState.None)
brush = SystemBrushes.HighlightText;
else
brush = SystemBrushes.WindowText;
e.Graphics.DrawString(color.Text, Font, brush,
e.Bounds.X + rect.X + rect.Width + 2,
e.Bounds.Y + ((e.Bounds.Height - Font.Height) / 2));
// Draw the focus rectangle if appropriate
if ((e.State & DrawItemState.NoFocusRect) == DrawItemState.None)
e.DrawFocusRectangle();
}
}