Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / Drawing / System / Drawing / Design / CursorEditor.cs / 1 / CursorEditor.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Drawing.Design {
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Collections;
using System.Reflection;
using System.Runtime.Serialization.Formatters;
using System.Windows.Forms;
using System.Windows.Forms.ComponentModel;
using System.Windows.Forms.Design;
///
///
///
/// Provides an editor that can perform default file searching for cursor (.cur)
/// files.
///
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.InheritanceDemand, Name="FullTrust")]
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name="FullTrust")]
public class CursorEditor : UITypeEditor {
private CursorUI cursorUI;
///
///
/// Returns true, indicating that this drop-down control can be resized.
///
public override bool IsDropDownResizable {
get {
return true;
}
}
///
///
/// Edits the given object value using the editor style provided by
/// GetEditorStyle. A service provider is provided so that any
/// required editing services can be obtained.
///
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
object returnValue = value;
if (provider != null) {
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null) {
if (cursorUI == null) {
cursorUI = new CursorUI(this);
}
cursorUI.Start(edSvc, value);
edSvc.DropDownControl(cursorUI);
value = cursorUI.Value;
cursorUI.End();
}
}
return value;
}
///
///
/// Retrieves the editing style of the Edit method. If the method
/// is not supported, this will return None.
///
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
return UITypeEditorEditStyle.DropDown;
}
///
///
/// The user interface for the cursor drop-down. This is just an owner-drawn
/// list box.
///
private class CursorUI : ListBox {
private object value;
private IWindowsFormsEditorService edSvc;
private TypeConverter cursorConverter;
private UITypeEditor editor;
public CursorUI(UITypeEditor editor) {
this.editor = editor;
Height = 310;
ItemHeight = (int) Math.Max(4 + Cursors.Default.Size.Height, Font.Height);
DrawMode = DrawMode.OwnerDrawFixed;
BorderStyle = BorderStyle.None;
cursorConverter = TypeDescriptor.GetConverter(typeof(Cursor));
Debug.Assert(cursorConverter.GetStandardValuesSupported(), "Converter '" + cursorConverter.ToString() + "' does not support a list of standard values. We cannot provide a drop-down");
// Fill the list with cursors.
//
if (cursorConverter.GetStandardValuesSupported()) {
foreach (object obj in cursorConverter.GetStandardValues()) {
Items.Add(obj);
}
}
}
public object Value {
get {
return value;
}
}
public void End() {
edSvc = null;
value = null;
}
protected override void OnClick(EventArgs e) {
base.OnClick(e);
value = SelectedItem;
edSvc.CloseDropDown();
}
protected override void OnDrawItem(DrawItemEventArgs die) {
base.OnDrawItem(die);
if (die.Index != -1) {
Cursor cursor = (Cursor)Items[die.Index];
string text = cursorConverter.ConvertToString(cursor);
Font font = die.Font;
Brush brushText = new SolidBrush(die.ForeColor);
die.DrawBackground();
die.Graphics.FillRectangle(SystemBrushes.Control, new Rectangle(die.Bounds.X + 2, die.Bounds.Y + 2, 32, die.Bounds.Height - 4));
die.Graphics.DrawRectangle(SystemPens.WindowText, new Rectangle(die.Bounds.X + 2, die.Bounds.Y + 2, 32 - 1, die.Bounds.Height - 4 - 1));
cursor.DrawStretched(die.Graphics, new Rectangle(die.Bounds.X + 2, die.Bounds.Y + 2, 32, die.Bounds.Height - 4));
die.Graphics.DrawString(text, font, brushText, die.Bounds.X + 36, die.Bounds.Y + (die.Bounds.Height - font.Height)/2);
brushText.Dispose();
}
}
protected override bool ProcessDialogKey(Keys keyData) {
if ((keyData & Keys.KeyCode) == Keys.Return && (keyData & (Keys.Alt | Keys.Control)) == 0) {
OnClick( EventArgs.Empty );
return true;
}
return base.ProcessDialogKey(keyData);
}
public void Start(IWindowsFormsEditorService edSvc, object value) {
this.edSvc = edSvc;
this.value = value;
// Select the current cursor
//
if (value != null) {
for (int i = 0; i < Items.Count; i++) {
if (Items[i] == value) {
SelectedIndex = i;
break;
}
}
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ValidateNames.cs
- PersistenceTypeAttribute.cs
- RawAppCommandInputReport.cs
- Opcode.cs
- PageRequestManager.cs
- DbConnectionPoolCounters.cs
- VersionedStream.cs
- COM2FontConverter.cs
- OnOperation.cs
- CodeExpressionCollection.cs
- XmlSchemaSimpleTypeUnion.cs
- StructuralCache.cs
- CollectionBase.cs
- _FtpDataStream.cs
- PersonalizationProviderHelper.cs
- PageClientProxyGenerator.cs
- DataSourceExpressionCollection.cs
- HatchBrush.cs
- ToolboxDataAttribute.cs
- RewritingValidator.cs
- messageonlyhwndwrapper.cs
- VersionedStream.cs
- StaticExtensionConverter.cs
- DeleteBookmarkScope.cs
- ServiceContractGenerator.cs
- WebScriptMetadataMessage.cs
- Stacktrace.cs
- KeyEvent.cs
- IPAddressCollection.cs
- WebResponse.cs
- documentsequencetextpointer.cs
- ScriptControlManager.cs
- SpellerInterop.cs
- ZeroOpNode.cs
- RoleGroupCollection.cs
- BasicCellRelation.cs
- ToolStripContainerDesigner.cs
- TrackingStringDictionary.cs
- ListDependantCardsRequest.cs
- SafeArrayRankMismatchException.cs
- FileDetails.cs
- PersonalizationEntry.cs
- RelationshipManager.cs
- XsdValidatingReader.cs
- MissingMemberException.cs
- SpeechEvent.cs
- ClickablePoint.cs
- UpdateInfo.cs
- TableCell.cs
- XsltCompileContext.cs
- ProfileInfo.cs
- GridViewSelectEventArgs.cs
- NameTable.cs
- SortedDictionary.cs
- TaskDesigner.cs
- ContentFileHelper.cs
- MatchingStyle.cs
- _CacheStreams.cs
- InheritedPropertyChangedEventArgs.cs
- FileLoadException.cs
- RectKeyFrameCollection.cs
- PasswordBox.cs
- EndSelectCardRequest.cs
- ContextProperty.cs
- ConfigUtil.cs
- OracleNumber.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- ZipIOBlockManager.cs
- XmlSchemaValidationException.cs
- SmiXetterAccessMap.cs
- InfoCardProofToken.cs
- TrackingSection.cs
- RNGCryptoServiceProvider.cs
- ProfileService.cs
- BamlRecordReader.cs
- OperationResponse.cs
- ExpressionBindingCollection.cs
- PreviewPageInfo.cs
- GenericsInstances.cs
- SqlClientMetaDataCollectionNames.cs
- RegisteredArrayDeclaration.cs
- ExtendLockAsyncResult.cs
- SQLChars.cs
- WeakReference.cs
- StorageMappingItemCollection.cs
- WebSysDescriptionAttribute.cs
- DocumentPageHost.cs
- DataComponentMethodGenerator.cs
- GeometryModel3D.cs
- ParameterModifier.cs
- XslException.cs
- WindowsListView.cs
- MultiDataTrigger.cs
- XmlExtensionFunction.cs
- ScriptControlDescriptor.cs
- NavigationPropertyEmitter.cs
- SessionPageStatePersister.cs
- CroppedBitmap.cs
- UIElement3DAutomationPeer.cs
- XmlTextReaderImplHelpers.cs