Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / DrawItemEvent.cs / 1305376 / DrawItemEvent.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms {
using System.Diagnostics;
using System;
using System.ComponentModel;
using System.Drawing;
using Microsoft.Win32;
///
///
/// This event is fired by owner draw Controls, such as ListBoxes and
/// ComboBoxes. It contains all the information needed for the user to
/// paint the given item, including the item index, the Rectangle in which
/// the drawing should be done, and the Graphics object with which the drawing
/// should be done.
///
public class DrawItemEventArgs : EventArgs {
///
///
/// The backColor to paint each menu item with.
///
private Color backColor;
///
///
/// The foreColor to paint each menu item with.
///
private Color foreColor;
///
///
/// The font used to draw the item's string.
///
private Font font;
///
///
/// The graphics object with which the drawing should be done.
///
private readonly System.Drawing.Graphics graphics;
///
///
/// The index of the item that should be painted.
///
private readonly int index;
///
///
/// The rectangle outlining the area in which the painting should be
/// done.
///
private readonly Rectangle rect;
///
///
/// Miscellaneous state information, such as whether the item is
/// "selected", "focused", or some other such information. ComboBoxes
/// have one special piece of information which indicates if the item
/// being painted is the editable portion of the ComboBox.
///
private readonly DrawItemState state;
///
///
/// Creates a new DrawItemEventArgs with the given parameters.
///
public DrawItemEventArgs(Graphics graphics, Font font, Rectangle rect,
int index, DrawItemState state) {
this.graphics = graphics;
this.font = font;
this.rect = rect;
this.index = index;
this.state = state;
this.foreColor = SystemColors.WindowText;
this.backColor = SystemColors.Window;
}
///
///
/// Creates a new DrawItemEventArgs with the given parameters, including the foreColor and backColor of the control.
///
public DrawItemEventArgs(Graphics graphics, Font font, Rectangle rect,
int index, DrawItemState state, Color foreColor, Color backColor) {
this.graphics = graphics;
this.font = font;
this.rect = rect;
this.index = index;
this.state = state;
this.foreColor = foreColor;
this.backColor = backColor;
}
///
public Color BackColor {
get {
if ((state & DrawItemState.Selected) == DrawItemState.Selected) {
return SystemColors.Highlight;
}
return backColor;
}
}
///
///
/// The rectangle outlining the area in which the painting should be
/// done.
///
public Rectangle Bounds {
get {
return rect;
}
}
///
///
/// A suggested font, usually the parent control's Font property.
///
public Font Font {
get {
return font;
}
}
///
///
/// A suggested color drawing: either SystemColors.WindowText or SystemColors.HighlightText,
/// depending on whether this item is selected.
///
public Color ForeColor {
get {
if ((state & DrawItemState.Selected) == DrawItemState.Selected) {
return SystemColors.HighlightText;
}
return foreColor;
}
}
///
///
/// Graphics object with which painting should be done.
///
public Graphics Graphics {
get {
return graphics;
}
}
///
///
/// The index of the item that should be painted.
///
public int Index {
get {
return index;
}
}
///
///
/// Miscellaneous state information, such as whether the item is
/// "selected", "focused", or some other such information. ComboBoxes
/// have one special piece of information which indicates if the item
/// being painted is the editable portion of the ComboBox.
///
public DrawItemState State {
get {
return state;
}
}
///
///
/// Draws the background of the given rectangle with the color returned from the BackColor property.
///
public virtual void DrawBackground() {
Brush backBrush = new SolidBrush(BackColor);
Graphics.FillRectangle(backBrush, rect);
backBrush.Dispose();
}
///
///
/// Draws a handy focus rect in the given rectangle.
///
public virtual void DrawFocusRectangle() {
if ((state & DrawItemState.Focus) == DrawItemState.Focus
&& (state & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect)
ControlPaint.DrawFocusRectangle(Graphics, rect, ForeColor, BackColor);
}
}
}
// 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;
using System.ComponentModel;
using System.Drawing;
using Microsoft.Win32;
///
///
/// This event is fired by owner draw Controls, such as ListBoxes and
/// ComboBoxes. It contains all the information needed for the user to
/// paint the given item, including the item index, the Rectangle in which
/// the drawing should be done, and the Graphics object with which the drawing
/// should be done.
///
public class DrawItemEventArgs : EventArgs {
///
///
/// The backColor to paint each menu item with.
///
private Color backColor;
///
///
/// The foreColor to paint each menu item with.
///
private Color foreColor;
///
///
/// The font used to draw the item's string.
///
private Font font;
///
///
/// The graphics object with which the drawing should be done.
///
private readonly System.Drawing.Graphics graphics;
///
///
/// The index of the item that should be painted.
///
private readonly int index;
///
///
/// The rectangle outlining the area in which the painting should be
/// done.
///
private readonly Rectangle rect;
///
///
/// Miscellaneous state information, such as whether the item is
/// "selected", "focused", or some other such information. ComboBoxes
/// have one special piece of information which indicates if the item
/// being painted is the editable portion of the ComboBox.
///
private readonly DrawItemState state;
///
///
/// Creates a new DrawItemEventArgs with the given parameters.
///
public DrawItemEventArgs(Graphics graphics, Font font, Rectangle rect,
int index, DrawItemState state) {
this.graphics = graphics;
this.font = font;
this.rect = rect;
this.index = index;
this.state = state;
this.foreColor = SystemColors.WindowText;
this.backColor = SystemColors.Window;
}
///
///
/// Creates a new DrawItemEventArgs with the given parameters, including the foreColor and backColor of the control.
///
public DrawItemEventArgs(Graphics graphics, Font font, Rectangle rect,
int index, DrawItemState state, Color foreColor, Color backColor) {
this.graphics = graphics;
this.font = font;
this.rect = rect;
this.index = index;
this.state = state;
this.foreColor = foreColor;
this.backColor = backColor;
}
///
public Color BackColor {
get {
if ((state & DrawItemState.Selected) == DrawItemState.Selected) {
return SystemColors.Highlight;
}
return backColor;
}
}
///
///
/// The rectangle outlining the area in which the painting should be
/// done.
///
public Rectangle Bounds {
get {
return rect;
}
}
///
///
/// A suggested font, usually the parent control's Font property.
///
public Font Font {
get {
return font;
}
}
///
///
/// A suggested color drawing: either SystemColors.WindowText or SystemColors.HighlightText,
/// depending on whether this item is selected.
///
public Color ForeColor {
get {
if ((state & DrawItemState.Selected) == DrawItemState.Selected) {
return SystemColors.HighlightText;
}
return foreColor;
}
}
///
///
/// Graphics object with which painting should be done.
///
public Graphics Graphics {
get {
return graphics;
}
}
///
///
/// The index of the item that should be painted.
///
public int Index {
get {
return index;
}
}
///
///
/// Miscellaneous state information, such as whether the item is
/// "selected", "focused", or some other such information. ComboBoxes
/// have one special piece of information which indicates if the item
/// being painted is the editable portion of the ComboBox.
///
public DrawItemState State {
get {
return state;
}
}
///
///
/// Draws the background of the given rectangle with the color returned from the BackColor property.
///
public virtual void DrawBackground() {
Brush backBrush = new SolidBrush(BackColor);
Graphics.FillRectangle(backBrush, rect);
backBrush.Dispose();
}
///
///
/// Draws a handy focus rect in the given rectangle.
///
public virtual void DrawFocusRectangle() {
if ((state & DrawItemState.Focus) == DrawItemState.Focus
&& (state & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect)
ControlPaint.DrawFocusRectangle(Graphics, rect, ForeColor, BackColor);
}
}
}
// 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
- WebPartZoneAutoFormat.cs
- SqlRecordBuffer.cs
- EntryWrittenEventArgs.cs
- Enum.cs
- XmlWriterDelegator.cs
- AdRotatorDesigner.cs
- SimpleBitVector32.cs
- DiagnosticsConfigurationHandler.cs
- PropertyEmitterBase.cs
- RuleValidation.cs
- XPathEmptyIterator.cs
- _HelperAsyncResults.cs
- CallbackValidator.cs
- SystemWebSectionGroup.cs
- XamlPathDataSerializer.cs
- DataTableMapping.cs
- ResourcePermissionBase.cs
- SafeFindHandle.cs
- PagedDataSource.cs
- ManagementObjectCollection.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- DbParameterCollection.cs
- ComplexType.cs
- AnnotationResourceCollection.cs
- DbInsertCommandTree.cs
- PrimarySelectionAdorner.cs
- RawStylusSystemGestureInputReport.cs
- DbConnectionPool.cs
- Literal.cs
- DockPanel.cs
- ServiceNotStartedException.cs
- NameValuePermission.cs
- UriSection.cs
- RelationshipType.cs
- XmlNodeReader.cs
- SafeNativeMethodsOther.cs
- _Events.cs
- XPathPatternBuilder.cs
- LambdaCompiler.Binary.cs
- EditorPartCollection.cs
- ParserExtension.cs
- EncodingTable.cs
- SqlConnectionStringBuilder.cs
- WeakKeyDictionary.cs
- DrawingGroupDrawingContext.cs
- ExpressionEditorAttribute.cs
- AutomationPropertyInfo.cs
- PreservationFileWriter.cs
- PageBreakRecord.cs
- Convert.cs
- XmlProcessingInstruction.cs
- SoapAttributes.cs
- DataViewSetting.cs
- BaseParaClient.cs
- XmlSchemaValidationException.cs
- SkinBuilder.cs
- ReaderWriterLockWrapper.cs
- Decoder.cs
- ParameterEditorUserControl.cs
- Profiler.cs
- Attribute.cs
- Win32Native.cs
- Form.cs
- ApplicationBuildProvider.cs
- PasswordValidationException.cs
- SchemaNotation.cs
- BamlResourceDeserializer.cs
- SizeFConverter.cs
- NameValueFileSectionHandler.cs
- ScaleTransform3D.cs
- RSAOAEPKeyExchangeDeformatter.cs
- XmlReturnReader.cs
- RtfFormatStack.cs
- WebPartChrome.cs
- PartialTrustVisibleAssembly.cs
- documentsequencetextcontainer.cs
- RepeatInfo.cs
- PointKeyFrameCollection.cs
- LightweightCodeGenerator.cs
- BrowserDefinition.cs
- DesignerObjectListAdapter.cs
- SubpageParaClient.cs
- TableDesigner.cs
- ToolStripSettings.cs
- ASCIIEncoding.cs
- SelectionHighlightInfo.cs
- TextSearch.cs
- OperandQuery.cs
- StackBuilderSink.cs
- SymbolEqualComparer.cs
- WebBodyFormatMessageProperty.cs
- ClientTargetCollection.cs
- CharKeyFrameCollection.cs
- LinkedList.cs
- BuildProvider.cs
- SqlError.cs
- IPEndPoint.cs
- DrawingContextDrawingContextWalker.cs
- X509CertificateInitiatorServiceCredential.cs
- ReferenceService.cs