Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / WinForms / Managed / System / WinForms / DrawListViewSubItemEventArgs.cs / 1 / DrawListViewSubItemEventArgs.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms
{
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms.Internal;
using Microsoft.Win32;
using System.Windows.Forms.VisualStyles;
///
///
/// This class contains the information a user needs to paint ListView sub-items (Details view only).
///
public class DrawListViewSubItemEventArgs : EventArgs
{
private readonly Graphics graphics;
private readonly Rectangle bounds;
private readonly ListViewItem item;
private readonly ListViewItem.ListViewSubItem subItem;
private readonly int itemIndex;
private readonly int columnIndex;
private readonly ColumnHeader header;
private readonly ListViewItemStates itemState;
private bool drawDefault;
///
///
/// Creates a new DrawListViewSubItemEventArgs with the given parameters.
///
public DrawListViewSubItemEventArgs(Graphics graphics, Rectangle bounds, ListViewItem item,
ListViewItem.ListViewSubItem subItem, int itemIndex, int columnIndex,
ColumnHeader header, ListViewItemStates itemState)
{
this.graphics = graphics;
this.bounds = bounds;
this.item = item;
this.subItem = subItem;
this.itemIndex = itemIndex;
this.columnIndex = columnIndex;
this.header = header;
this.itemState = itemState;
}
///
///
/// Causes the item do be drawn by the system instead of owner drawn.
///
public bool DrawDefault {
get {
return drawDefault;
}
set {
drawDefault = value;
}
}
///
///
/// Graphics object with which painting should be done.
///
public Graphics Graphics
{
get
{
return graphics;
}
}
///
///
/// The rectangle outlining the area in which the painting should be done.
///
public Rectangle Bounds
{
get
{
return bounds;
}
}
///
///
/// The parent item.
///
public ListViewItem Item
{
get
{
return item;
}
}
///
///
/// The parent item.
///
public ListViewItem.ListViewSubItem SubItem
{
get
{
return subItem;
}
}
///
///
/// The index in the ListView of the parent item.
///
public int ItemIndex
{
get
{
return itemIndex;
}
}
///
///
/// The column index of this sub-item.
///
public int ColumnIndex
{
get
{
return columnIndex;
}
}
///
///
/// The header of this sub-item's column
///
public ColumnHeader Header
{
get
{
return header;
}
}
///
///
/// Miscellaneous state information pertaining to the parent item.
///
public ListViewItemStates ItemState
{
get
{
return itemState;
}
}
///
///
/// Draws the sub-item's background.
///
public void DrawBackground()
{
Color backColor = (itemIndex == -1) ? item.BackColor : subItem.BackColor;
using (Brush backBrush = new SolidBrush(backColor)) {
Graphics.FillRectangle(backBrush, bounds);
}
}
///
///
/// Draws a focus rectangle in the given bounds, if the item has focus.
///
public void DrawFocusRectangle(Rectangle bounds)
{
if((itemState & ListViewItemStates.Focused) == ListViewItemStates.Focused)
{
ControlPaint.DrawFocusRectangle(graphics, Rectangle.Inflate(bounds, -1, -1), item.ForeColor, item.BackColor);
}
}
///
///
/// Draws the sub-item's text (overloaded)
///
public void DrawText()
{
// Map the ColumnHeader::TextAlign to the TextFormatFlags.
HorizontalAlignment hAlign = header.TextAlign;
TextFormatFlags flags = (hAlign == HorizontalAlignment.Left) ? TextFormatFlags.Left :
((hAlign == HorizontalAlignment.Center) ? TextFormatFlags.HorizontalCenter :
TextFormatFlags.Right);
flags |= TextFormatFlags.WordEllipsis;
DrawText(flags);
}
///
///
/// Draws the sub-item's text (overloaded) - takes a TextFormatFlags argument.
///
[
SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters") // We want to measure the size of blank space.
// So we don't have to localize it.
]
public void DrawText(TextFormatFlags flags)
{
string text = (itemIndex == -1) ? item.Text : subItem.Text;
Font font = (itemIndex == -1) ? item.Font : subItem.Font;
Color color = (itemIndex == -1) ? item.ForeColor : subItem.ForeColor;
int padding = TextRenderer.MeasureText(" ", font).Width;
Rectangle newBounds = Rectangle.Inflate(bounds, -padding, 0);
TextRenderer.DrawText(graphics, text, font, newBounds, color, flags);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms
{
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms.Internal;
using Microsoft.Win32;
using System.Windows.Forms.VisualStyles;
///
///
/// This class contains the information a user needs to paint ListView sub-items (Details view only).
///
public class DrawListViewSubItemEventArgs : EventArgs
{
private readonly Graphics graphics;
private readonly Rectangle bounds;
private readonly ListViewItem item;
private readonly ListViewItem.ListViewSubItem subItem;
private readonly int itemIndex;
private readonly int columnIndex;
private readonly ColumnHeader header;
private readonly ListViewItemStates itemState;
private bool drawDefault;
///
///
/// Creates a new DrawListViewSubItemEventArgs with the given parameters.
///
public DrawListViewSubItemEventArgs(Graphics graphics, Rectangle bounds, ListViewItem item,
ListViewItem.ListViewSubItem subItem, int itemIndex, int columnIndex,
ColumnHeader header, ListViewItemStates itemState)
{
this.graphics = graphics;
this.bounds = bounds;
this.item = item;
this.subItem = subItem;
this.itemIndex = itemIndex;
this.columnIndex = columnIndex;
this.header = header;
this.itemState = itemState;
}
///
///
/// Causes the item do be drawn by the system instead of owner drawn.
///
public bool DrawDefault {
get {
return drawDefault;
}
set {
drawDefault = value;
}
}
///
///
/// Graphics object with which painting should be done.
///
public Graphics Graphics
{
get
{
return graphics;
}
}
///
///
/// The rectangle outlining the area in which the painting should be done.
///
public Rectangle Bounds
{
get
{
return bounds;
}
}
///
///
/// The parent item.
///
public ListViewItem Item
{
get
{
return item;
}
}
///
///
/// The parent item.
///
public ListViewItem.ListViewSubItem SubItem
{
get
{
return subItem;
}
}
///
///
/// The index in the ListView of the parent item.
///
public int ItemIndex
{
get
{
return itemIndex;
}
}
///
///
/// The column index of this sub-item.
///
public int ColumnIndex
{
get
{
return columnIndex;
}
}
///
///
/// The header of this sub-item's column
///
public ColumnHeader Header
{
get
{
return header;
}
}
///
///
/// Miscellaneous state information pertaining to the parent item.
///
public ListViewItemStates ItemState
{
get
{
return itemState;
}
}
///
///
/// Draws the sub-item's background.
///
public void DrawBackground()
{
Color backColor = (itemIndex == -1) ? item.BackColor : subItem.BackColor;
using (Brush backBrush = new SolidBrush(backColor)) {
Graphics.FillRectangle(backBrush, bounds);
}
}
///
///
/// Draws a focus rectangle in the given bounds, if the item has focus.
///
public void DrawFocusRectangle(Rectangle bounds)
{
if((itemState & ListViewItemStates.Focused) == ListViewItemStates.Focused)
{
ControlPaint.DrawFocusRectangle(graphics, Rectangle.Inflate(bounds, -1, -1), item.ForeColor, item.BackColor);
}
}
///
///
/// Draws the sub-item's text (overloaded)
///
public void DrawText()
{
// Map the ColumnHeader::TextAlign to the TextFormatFlags.
HorizontalAlignment hAlign = header.TextAlign;
TextFormatFlags flags = (hAlign == HorizontalAlignment.Left) ? TextFormatFlags.Left :
((hAlign == HorizontalAlignment.Center) ? TextFormatFlags.HorizontalCenter :
TextFormatFlags.Right);
flags |= TextFormatFlags.WordEllipsis;
DrawText(flags);
}
///
///
/// Draws the sub-item's text (overloaded) - takes a TextFormatFlags argument.
///
[
SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters") // We want to measure the size of blank space.
// So we don't have to localize it.
]
public void DrawText(TextFormatFlags flags)
{
string text = (itemIndex == -1) ? item.Text : subItem.Text;
Font font = (itemIndex == -1) ? item.Font : subItem.Font;
Color color = (itemIndex == -1) ? item.ForeColor : subItem.ForeColor;
int padding = TextRenderer.MeasureText(" ", font).Width;
Rectangle newBounds = Rectangle.Inflate(bounds, -padding, 0);
TextRenderer.DrawText(graphics, text, font, newBounds, color, flags);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- VisualCollection.cs
- ArgumentOutOfRangeException.cs
- FontConverter.cs
- MaskedTextProvider.cs
- CollectionDataContractAttribute.cs
- IsolatedStorageFilePermission.cs
- AutomationElement.cs
- HttpResponse.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- InputScope.cs
- InternalConfigConfigurationFactory.cs
- TaskFormBase.cs
- AppDomainAttributes.cs
- TextCharacters.cs
- SmiMetaData.cs
- GenericEnumerator.cs
- UnitySerializationHolder.cs
- TypeSystem.cs
- HtmlAnchor.cs
- ConfigurationCollectionAttribute.cs
- EntryWrittenEventArgs.cs
- ToolStripDropDownDesigner.cs
- StylusPlugInCollection.cs
- ResourceAttributes.cs
- RawStylusInputCustomDataList.cs
- ComplusTypeValidator.cs
- ExternalDataExchangeService.cs
- WpfWebRequestHelper.cs
- TrackBarRenderer.cs
- CodeDelegateCreateExpression.cs
- COM2Properties.cs
- TabControlCancelEvent.cs
- WebPartEditVerb.cs
- CodeDirectionExpression.cs
- StartUpEventArgs.cs
- BitmapImage.cs
- GridViewDeleteEventArgs.cs
- ClientSettings.cs
- Logging.cs
- DesignerCatalogPartChrome.cs
- DataGridSortingEventArgs.cs
- CustomAttribute.cs
- DataGridViewSortCompareEventArgs.cs
- StringTraceRecord.cs
- MenuItemCollectionEditor.cs
- ConfigurationStrings.cs
- RepeatInfo.cs
- EditorZoneAutoFormat.cs
- TemplateControl.cs
- SqlDataRecord.cs
- SignatureTargetIdManager.cs
- SqlAliaser.cs
- SqlUtils.cs
- ZipPackage.cs
- ValidationSummary.cs
- DefaultMemberAttribute.cs
- XmlSerializerFormatAttribute.cs
- SystemResourceKey.cs
- MainMenu.cs
- _NegoState.cs
- TcpTransportBindingElement.cs
- RoutingExtension.cs
- CfgParser.cs
- GetPageCompletedEventArgs.cs
- BufferModeSettings.cs
- TableCell.cs
- ObjectReaderCompiler.cs
- HtmlSelectionListAdapter.cs
- FileRegion.cs
- TokenizerHelper.cs
- CreateUserWizardStep.cs
- NavigationService.cs
- RectangleHotSpot.cs
- ActivityBuilder.cs
- Gdiplus.cs
- SessionPageStateSection.cs
- TraceContextRecord.cs
- HiddenFieldPageStatePersister.cs
- SafeNativeMethods.cs
- ClosableStream.cs
- ExpressionUtilities.cs
- columnmapkeybuilder.cs
- ErrorFormatterPage.cs
- HtmlElementEventArgs.cs
- Properties.cs
- ComplexTypeEmitter.cs
- Sentence.cs
- XmlBinaryWriterSession.cs
- TextTreeExtractElementUndoUnit.cs
- XmlNotation.cs
- UserMapPath.cs
- RootBrowserWindowAutomationPeer.cs
- MarginsConverter.cs
- DependencyPropertyConverter.cs
- CategoryAttribute.cs
- SelectedGridItemChangedEvent.cs
- TraceSource.cs
- CodeIndexerExpression.cs
- MetabaseReader.cs
- filewebrequest.cs