本文整理汇总了C#中System.Windows.Forms.DrawListViewSubItemEventArgs.DrawFocusRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# DrawListViewSubItemEventArgs.DrawFocusRectangle方法的具体用法?C# DrawListViewSubItemEventArgs.DrawFocusRectangle怎么用?C# DrawListViewSubItemEventArgs.DrawFocusRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DrawListViewSubItemEventArgs
的用法示例。
在下文中一共展示了DrawListViewSubItemEventArgs.DrawFocusRectangle方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDrawSubItem
protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
{
base.OnDrawSubItem(e);
if (e.ItemState == 0)
{
return;
}
if ((e.ItemState & ListViewItemStates.Selected) == ListViewItemStates.Selected)
e.SubItem.BackColor = System.Drawing.Color.LightSkyBlue;
else
{
ConfigData data = e.Item.Tag as ConfigData;
if (data != null && (data.HasTaskitem || data.IsAutRun))
{
e.SubItem.BackColor = System.Drawing.Color.Pink;
}
else if (e.ItemIndex % 2 != 0)
e.SubItem.BackColor = HVH_Ken_Modules.GlobalVar.Instanse.StyleColor;
else
e.SubItem.BackColor = this.BackColor;
}
e.DrawBackground();
using (StringFormat sf = new StringFormat())
{
HorizontalAlignment align = Columns[e.ColumnIndex].TextAlign;
if (align == HorizontalAlignment.Center)
sf.Alignment = StringAlignment.Center;
else if (align == HorizontalAlignment.Right)
sf.Alignment = StringAlignment.Far;
e.Graphics.DrawString(e.SubItem.Text, Font, new SolidBrush(ForeColor), e.Bounds, sf);
}
e.DrawFocusRectangle(e.Bounds);
if ((e.ItemState & ListViewItemStates.Focused) == ListViewItemStates.Focused)
{
if (this.FullRowSelect == false)
{
if (e.ColumnIndex == 0)
{
e.DrawFocusRectangle(e.Bounds);
}
}
else
e.DrawFocusRectangle(e.Bounds);
}
}
示例2: listView_DrawSubItem
private void listView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
Brush brush;
Color backColor;
Color foreColor;
if (e.Item.Selected)
{
if (listView.Focused)
{
brush = SystemBrushes.Highlight;
backColor = SystemColors.Highlight;
foreColor = SystemColors.HighlightText;
}
else
{
// We use the same colors here as TreeViewMS does for
// drawing unfocused selected rows.
brush = Brushes.LightGray;
backColor = Color.LightGray;
foreColor = SystemColors.WindowText;
}
}
else
{
brush = SystemBrushes.Window;
backColor = SystemColors.Window;
foreColor = SystemColors.WindowText;
}
if (e.ColumnIndex == 0)
{
// Erase the entire background when drawing the first sub-item
e.Graphics.FillRectangle(brush, e.Item.Bounds);
}
if (e.ColumnIndex == colHdrDisplayText.Index)
{
var findResult = (FindResult) e.Item.Tag;
var textRendererHelper = new TextRendererHelper
{
ForeColor = foreColor,
BackColor = backColor,
Font = e.Item.Font,
HighlightFont = new Font(e.Item.Font, FontStyle.Bold),
};
textRendererHelper.DrawHighlightedText(e.Graphics, e.SubItem.Bounds, findResult.FindMatch);
}
else
{
e.SubItem.ForeColor = foreColor;
e.DrawText();
}
if (e.ColumnIndex == 0)
{
e.DrawFocusRectangle(e.Bounds);
}
}
示例3: _tailListView_DrawSubItem
private void _tailListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
if (e.ColumnIndex != 1)
return;
Color? textColor = null;;
Color? backColor = null;
// Bookmark coloring has higher priority, than keyword highlight
if (MatchesBookmark(e.ItemIndex))
{
backColor = _bookmarkBackColor;
textColor = _bookmarkTextColor;
}
else
{
TailKeywordConfig keyword = MatchesKeyword(e.Item.Text, false, true);
if (keyword != null)
{
if (keyword.FormBackColor.HasValue && keyword.FormTextColor.HasValue)
{
backColor = keyword.FormBackColor.Value;
textColor = keyword.FormTextColor.Value;
}
}
}
//toggle colors if the item is highlighted
if (e.Item.Selected)
{
if (backColor.HasValue || textColor.HasValue)
{
e.SubItem.BackColor = SystemColors.Highlight;
e.SubItem.ForeColor = Color.FromArgb(SystemColors.Highlight.A, (SystemColors.Highlight.R + 128) % 256, (SystemColors.Highlight.G + 128) % 256, (SystemColors.Highlight.B + 128) % 256);
}
else
{
e.SubItem.BackColor = SystemColors.Highlight;
e.SubItem.ForeColor = SystemColors.HighlightText;
}
}
else
{
if (backColor.HasValue)
e.SubItem.BackColor = backColor.Value;
else
e.SubItem.BackColor = e.Item.ListView.BackColor;
if (textColor.HasValue)
e.SubItem.ForeColor = textColor.Value;
else
e.SubItem.ForeColor = e.Item.ListView.ForeColor;
}
// Draw the standard header background.
e.DrawBackground();
e.DrawFocusRectangle(e.Bounds);
TextFormatFlags flags = TextFormatFlags.Left | TextFormatFlags.ExpandTabs | TextFormatFlags.SingleLine | TextFormatFlags.NoPrefix;
if (e.Item.Text.Length > 1000)
TextRenderer.DrawText(e.Graphics, e.Item.Text.Substring(0, 1000), e.Item.ListView.Font, e.Bounds, e.SubItem.ForeColor, flags);
else
TextRenderer.DrawText(e.Graphics, e.Item.Text, e.Item.ListView.Font, e.Bounds, e.SubItem.ForeColor, flags);
}
示例4: ActionListView_DrawSubItem
private void ActionListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
e.DrawDefault = true; //采用系统默认方式绘制子项
e.DrawFocusRectangle(e.Bounds);
}
示例5: lstFunctions_DrawSubItem
void lstFunctions_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
if (_argsBrush == null) _argsBrush = new SolidBrush(Util.MixColor(SystemColors.Window, SystemColors.WindowText, .5f));
if (_argsBrushHighlight == null) _argsBrushHighlight = new SolidBrush(Util.MixColor(SystemColors.Highlight, SystemColors.HighlightText, .5f));
if (e.ColumnIndex != 0 || e.Item == null || e.Item.Tag == null || e.Item.Tag.GetType() != typeof(Function))
{
e.DrawDefault = true;
}
else
{
e.DrawDefault = false;
var func = e.Item.Tag as Function;
var selected = e.Item.Selected;
const int k_iconSize = 16;
const int k_spacer = 2;
var iconRect = new Rectangle(e.Bounds.Left + k_spacer, e.Bounds.Top + (e.Bounds.Height - k_iconSize) / 2, k_iconSize, k_iconSize);
var textRect = new Rectangle(iconRect.Right + k_spacer, e.Bounds.Top, e.Bounds.Right - (iconRect.Right + k_spacer), e.Bounds.Height);
using (var sf = new StringFormat())
{
sf.FormatFlags = StringFormatFlags.NoWrap;
sf.LineAlignment = StringAlignment.Center;
e.Graphics.FillRectangle(selected ? SystemBrushes.Highlight : SystemBrushes.Window, textRect);
e.Graphics.DrawIcon(Res.FunctionIcon, iconRect);
if (e.Item.Text.StartsWith(func.Name))
{
e.Graphics.DrawString(func.Name, lstFunctions.Font,
selected ? SystemBrushes.HighlightText : SystemBrushes.WindowText, textRect, sf);
if (e.Item.Text.Length > func.Name.Length)
{
var size = Util.MeasureString(e.Graphics, func.Name, lstFunctions.Font, textRect, sf);
var argsRect = new RectangleF(textRect.Left + size.Width, textRect.Top, textRect.Width - size.Width, textRect.Height);
if (!argsRect.IsEmpty)
{
e.Graphics.DrawString(e.Item.Text.Substring(func.Name.Length), lstFunctions.Font,
selected ? _argsBrushHighlight : _argsBrush, argsRect, sf);
}
}
}
else
{
e.Graphics.DrawString(e.Item.Text, lstFunctions.Font,
selected ? SystemBrushes.HighlightText : SystemBrushes.WindowText,
textRect, sf);
}
e.DrawFocusRectangle(e.Bounds);
}
}
}
示例6: logListView_DrawSubItem
private void logListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
var item = e.Item.SubItems[e.ColumnIndex];
e.DrawBackground();
var text = item.Text;
Color forecolor;
if (text.StartsWith(@"ERROR") || text.StartsWith(@"FATAL"))
{
forecolor = Color.DarkRed;
}
else if (text.StartsWith(@"WARN"))
{
forecolor = Color.FromArgb(181, 166, 16);
}
else if (text.StartsWith(@"DEBUG"))
{
forecolor = Color.Black;
}
else
{
forecolor = Color.DarkBlue;
}
TextRenderer.DrawText(e.Graphics, item.Text, this.logListView.Font, e.Bounds, forecolor, TextFormatFlags.Left);
e.DrawFocusRectangle(e.Bounds);
}
示例7: tsvMessages_DrawSubItem
/// <summary>
/// Draw the row.
/// </summary>
private void tsvMessages_DrawSubItem(object sender, DrawListViewSubItemEventArgs args)
{
CIXMessage message = args.Item.Tag as CIXMessage;
if (message != null)
{
DrawRectElements elements = ComputeDrawRectElements(args.Graphics, message, args.Bounds);
bool canThread = CanGroupByConversation();
Color textColor = UI.Forums.HeaderFooterColour;
if (args.Item.Selected)
{
args.DrawFocusRectangle(elements.BoundaryRect);
textColor = UI.Forums.SelectionTextColour;
}
// Draw the selection around the control.
using (Pen edgePen = new Pen(args.Item.Selected ? UI.Forums.SelectionColour : BackColor))
{
Color fillColour = args.Item.Selected ? UI.Forums.SelectionColour : (message.IsRoot ? UI.Forums.RootColour : UI.Forums.CommentColour);
using (Brush backBrush = new SolidBrush(fillColour))
{
args.Graphics.FillRoundedRectangle(edgePen, backBrush, elements.BoundaryRect);
}
}
Font headerFont = FontForItem(message);
using (Brush textBrush = new SolidBrush(message.Ignored ? UI.Forums.IgnoredColour : textColor))
{
using (Brush priorityBrush = new SolidBrush(message.Ignored ? UI.Forums.IgnoredColour : UI.Forums.PriorityColour))
{
// Draw arrows if message can be expanded or collapsed
if (message.IsRoot && message.HasChildren && canThread)
{
Image arrowImage = IsExpanded(message) ? Resources.CollapseArrow : Resources.ExpandArrow;
args.Graphics.DrawImage(arrowImage, elements.ExpanderRect);
}
// Draw read image
Image readImage = ReadImageForMessage(message);
args.Graphics.DrawImage(readImage, elements.ReadRect);
// Draw author name
args.Graphics.DrawString(message.Author, headerFont, message.Priority ? priorityBrush : textBrush, elements.AuthorRect);
// Draw separator
const string separatorChar = "•";
args.Graphics.DrawString(separatorChar, headerFont, textBrush, elements.Separator1Rect);
// Draw date
string dateString = (_showFullDate)
? message.Date.ToString("d MMM yyyy") + " " + message.Date.ToShortTimeString()
: message.Date.FriendlyString(true);
args.Graphics.DrawString(dateString, headerFont, textBrush, elements.DateRect);
// Draw star icon
Image starIcon = message.Starred ? Resources.ActiveStar : Resources.InactiveStar;
args.Graphics.DrawImage(starIcon, elements.StarRect);
// Draw ID field
string idString = message.IsPseudo
? "Draft"
: message.RemoteID.ToString(CultureInfo.InvariantCulture);
args.Graphics.DrawString(idString, headerFont, textBrush, elements.IDRect);
// Another separator
args.Graphics.DrawString(separatorChar, headerFont, textBrush, elements.Separator2Rect);
// Draw subject line
string subjectLine = message.Subject;
args.Graphics.DrawString(subjectLine, headerFont, textBrush, elements.SubjectRect, new StringFormat(StringFormatFlags.NoWrap));
}
}
}
}
示例8: lvServerBrowser_DrawSubItem
private void lvServerBrowser_DrawSubItem(Object sender, DrawListViewSubItemEventArgs e)
{
if (e.ColumnIndex == 0)
{
Image imgLock = Properties.Resources.theLock;
Image imgUnlock = Properties.Resources.theUnlock;
if (lvServerBrowser.Items[e.ItemIndex].SubItems[e.ColumnIndex].Text.Equals("true"))
{
e.Graphics.DrawImage(imgLock, lvServerBrowser.Items[e.ItemIndex].SubItems[e.ColumnIndex].Bounds.Location);
}
else
{
e.Graphics.DrawImage(imgUnlock, lvServerBrowser.Items[e.ItemIndex].SubItems[e.ColumnIndex].Bounds.Location);
}
e.DrawFocusRectangle(lvServerBrowser.Items[e.ItemIndex].SubItems[e.ColumnIndex].Bounds);
}
else
{
e.DrawText();
}
}
示例9: DrawSubItem
/// <summary>
/// Draw the row.
/// </summary>
private void DrawSubItem(object sender, DrawListViewSubItemEventArgs args)
{
InboxConversation message = args.Item.Tag as InboxConversation;
if (message != null)
{
DrawRectElements elements = ComputeDrawRectElements(args.Graphics, message, args.Bounds);
Color textColor = UI.Forums.HeaderFooterColour;
if (args.Item.Selected)
{
args.DrawFocusRectangle(elements.BoundaryRect);
textColor = UI.Forums.SelectionTextColour;
}
// Draw the selection around the control.
using (Pen edgePen = new Pen(args.Item.Selected ? UI.Forums.SelectionColour : BackColor))
{
Color fillColour = args.Item.Selected ? UI.Forums.SelectionColour : UI.Forums.RootColour;
using (Brush backBrush = new SolidBrush(fillColour))
{
args.Graphics.FillRoundedRectangle(edgePen, backBrush, elements.BoundaryRect);
}
}
using (Brush textBrush = new SolidBrush(textColor))
{
// Draw read image
Image readImage = ReadImageForMessage(message);
args.Graphics.DrawImage(readImage, elements.ReadRect);
// Draw author name
args.Graphics.DrawString(message.Author, _font, textBrush, elements.AuthorRect);
// Draw separator
const string separatorChar = "•";
args.Graphics.DrawString(separatorChar, _font, textBrush, elements.Separator1Rect);
// Draw date
string dateString = (_showFullDate)
? message.Date.ToString("d MMM yyyy") + " " + message.Date.ToShortTimeString()
: message.Date.FriendlyString(true);
args.Graphics.DrawString(dateString, _font, textBrush, elements.DateRect);
// Draw ID field
string idString = (message.IsDraft)
? "Draft"
: message.RemoteID.ToString(CultureInfo.InvariantCulture);
args.Graphics.DrawString(idString, _font, textBrush, elements.IDRect);
// Another separator
args.Graphics.DrawString(separatorChar, _font, textBrush, elements.Separator2Rect);
// Draw subject line
string subjectLine = message.Subject;
args.Graphics.DrawString(subjectLine, _font, textBrush, elements.SubjectRect, new StringFormat(StringFormatFlags.NoWrap));
}
}
}
示例10: listViewLog_DrawSubItem
private void listViewLog_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
var item = e.Item.SubItems[e.ColumnIndex];
e.DrawBackground();
var text = item.Text;
Color forecolor;
if (text.StartsWith(@"ERROR", StringComparison.CurrentCultureIgnoreCase) ||
text.StartsWith(@"FATAL", StringComparison.CurrentCultureIgnoreCase))
{
forecolor = _darkRedColor;
}
else if (text.StartsWith(@"WARN", StringComparison.CurrentCultureIgnoreCase))
{
forecolor = Color.FromArgb(181, 166, 16);
}
else if (text.StartsWith(@"DEBUG"))
{
forecolor = Color.Black;
}
else
{
forecolor = Color.DarkBlue;
}
TextRenderer.DrawText(e.Graphics, item.Text, listViewLog.Font, e.Bounds, forecolor, TextFormatFlags.Left);
e.DrawFocusRectangle(e.Bounds);
}