Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / DataGridToolTip.cs / 1305376 / DataGridToolTip.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms {
using System.Runtime.Remoting;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;
using System.ComponentModel;
// this class is basically a NativeWindow that does toolTipping
// should be one for the entire grid
internal class DataGridToolTip : MarshalByRefObject {
// the toolTip control
private NativeWindow tipWindow = null;
// the dataGrid which contains this toolTip
private DataGrid dataGrid = null;
// CONSTRUCTOR
public DataGridToolTip(DataGrid dataGrid)
{
Debug.Assert(dataGrid!= null, "can't attach a tool tip to a null grid");
this.dataGrid = dataGrid;
}
// will ensure that the toolTip window was created
public void CreateToolTipHandle()
{
if (tipWindow == null || tipWindow.Handle == IntPtr.Zero)
{
NativeMethods.INITCOMMONCONTROLSEX icc = new NativeMethods.INITCOMMONCONTROLSEX();
icc.dwICC = NativeMethods.ICC_TAB_CLASSES;
icc.dwSize = Marshal.SizeOf(icc);
SafeNativeMethods.InitCommonControlsEx(icc);
CreateParams cparams = new CreateParams();
cparams.Parent = dataGrid.Handle;
cparams.ClassName = NativeMethods.TOOLTIPS_CLASS;
cparams.Style = NativeMethods.TTS_ALWAYSTIP;
tipWindow = new NativeWindow();
tipWindow.CreateHandle(cparams);
UnsafeNativeMethods.SendMessage(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.TTM_SETMAXTIPWIDTH, 0, SystemInformation.MaxWindowTrackSize.Width);
SafeNativeMethods.SetWindowPos(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.HWND_NOTOPMOST, 0, 0, 0, 0, NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOMOVE | NativeMethods.SWP_NOACTIVATE);
UnsafeNativeMethods.SendMessage(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.TTM_SETDELAYTIME, NativeMethods.TTDT_INITIAL, 0);
}
}
// this function will add a toolTip to the
// windows system
public void AddToolTip(String toolTipString, IntPtr toolTipId, Rectangle iconBounds)
{
Debug.Assert(tipWindow != null && tipWindow.Handle != IntPtr.Zero, "the tipWindow was not initialized, bailing out");
if (toolTipString == null)
throw new ArgumentNullException("toolTipString");
if (iconBounds.IsEmpty)
throw new ArgumentNullException("iconBounds", SR.GetString(SR.DataGridToolTipEmptyIcon));
NativeMethods.TOOLINFO_T toolInfo = new NativeMethods.TOOLINFO_T();
toolInfo.cbSize = Marshal.SizeOf(toolInfo);
toolInfo.hwnd = dataGrid.Handle;
toolInfo.uId = toolTipId;
toolInfo.lpszText = toolTipString;
toolInfo.rect = NativeMethods.RECT.FromXYWH(iconBounds.X, iconBounds.Y, iconBounds.Width, iconBounds.Height);
toolInfo.uFlags = NativeMethods.TTF_SUBCLASS;
UnsafeNativeMethods.SendMessage(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.TTM_ADDTOOL, 0, toolInfo);
}
public void RemoveToolTip(IntPtr toolTipId)
{
NativeMethods.TOOLINFO_T toolInfo = new NativeMethods.TOOLINFO_T();
toolInfo.cbSize = Marshal.SizeOf(toolInfo);
toolInfo.hwnd = dataGrid.Handle;
toolInfo.uId = toolTipId;
UnsafeNativeMethods.SendMessage(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.TTM_DELTOOL, 0, toolInfo);
}
// will destroy the tipWindow
public void Destroy()
{
Debug.Assert(tipWindow != null, "how can one destroy a null window");
tipWindow.DestroyHandle();
tipWindow = null;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms {
using System.Runtime.Remoting;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;
using System.ComponentModel;
// this class is basically a NativeWindow that does toolTipping
// should be one for the entire grid
internal class DataGridToolTip : MarshalByRefObject {
// the toolTip control
private NativeWindow tipWindow = null;
// the dataGrid which contains this toolTip
private DataGrid dataGrid = null;
// CONSTRUCTOR
public DataGridToolTip(DataGrid dataGrid)
{
Debug.Assert(dataGrid!= null, "can't attach a tool tip to a null grid");
this.dataGrid = dataGrid;
}
// will ensure that the toolTip window was created
public void CreateToolTipHandle()
{
if (tipWindow == null || tipWindow.Handle == IntPtr.Zero)
{
NativeMethods.INITCOMMONCONTROLSEX icc = new NativeMethods.INITCOMMONCONTROLSEX();
icc.dwICC = NativeMethods.ICC_TAB_CLASSES;
icc.dwSize = Marshal.SizeOf(icc);
SafeNativeMethods.InitCommonControlsEx(icc);
CreateParams cparams = new CreateParams();
cparams.Parent = dataGrid.Handle;
cparams.ClassName = NativeMethods.TOOLTIPS_CLASS;
cparams.Style = NativeMethods.TTS_ALWAYSTIP;
tipWindow = new NativeWindow();
tipWindow.CreateHandle(cparams);
UnsafeNativeMethods.SendMessage(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.TTM_SETMAXTIPWIDTH, 0, SystemInformation.MaxWindowTrackSize.Width);
SafeNativeMethods.SetWindowPos(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.HWND_NOTOPMOST, 0, 0, 0, 0, NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOMOVE | NativeMethods.SWP_NOACTIVATE);
UnsafeNativeMethods.SendMessage(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.TTM_SETDELAYTIME, NativeMethods.TTDT_INITIAL, 0);
}
}
// this function will add a toolTip to the
// windows system
public void AddToolTip(String toolTipString, IntPtr toolTipId, Rectangle iconBounds)
{
Debug.Assert(tipWindow != null && tipWindow.Handle != IntPtr.Zero, "the tipWindow was not initialized, bailing out");
if (toolTipString == null)
throw new ArgumentNullException("toolTipString");
if (iconBounds.IsEmpty)
throw new ArgumentNullException("iconBounds", SR.GetString(SR.DataGridToolTipEmptyIcon));
NativeMethods.TOOLINFO_T toolInfo = new NativeMethods.TOOLINFO_T();
toolInfo.cbSize = Marshal.SizeOf(toolInfo);
toolInfo.hwnd = dataGrid.Handle;
toolInfo.uId = toolTipId;
toolInfo.lpszText = toolTipString;
toolInfo.rect = NativeMethods.RECT.FromXYWH(iconBounds.X, iconBounds.Y, iconBounds.Width, iconBounds.Height);
toolInfo.uFlags = NativeMethods.TTF_SUBCLASS;
UnsafeNativeMethods.SendMessage(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.TTM_ADDTOOL, 0, toolInfo);
}
public void RemoveToolTip(IntPtr toolTipId)
{
NativeMethods.TOOLINFO_T toolInfo = new NativeMethods.TOOLINFO_T();
toolInfo.cbSize = Marshal.SizeOf(toolInfo);
toolInfo.hwnd = dataGrid.Handle;
toolInfo.uId = toolTipId;
UnsafeNativeMethods.SendMessage(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.TTM_DELTOOL, 0, toolInfo);
}
// will destroy the tipWindow
public void Destroy()
{
Debug.Assert(tipWindow != null, "how can one destroy a null window");
tipWindow.DestroyHandle();
tipWindow = null;
}
}
}
// 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
- CodeLabeledStatement.cs
- TableLayoutPanel.cs
- CodeCompileUnit.cs
- CategoriesDocument.cs
- File.cs
- InheritanceContextHelper.cs
- ControlParser.cs
- ProtocolReflector.cs
- KeyboardInputProviderAcquireFocusEventArgs.cs
- ServiceNotStartedException.cs
- PopupControlService.cs
- LinqDataSource.cs
- SelectionProcessor.cs
- HttpClientProtocol.cs
- TextReturnReader.cs
- ModifierKeysConverter.cs
- ContextProperty.cs
- DataPagerCommandEventArgs.cs
- PointF.cs
- AnnotationMap.cs
- TrackPoint.cs
- SqlUtils.cs
- XmlSchemaSet.cs
- RegexCapture.cs
- ByeMessageCD1.cs
- ArrayTypeMismatchException.cs
- _SslStream.cs
- Contracts.cs
- DataGridViewColumnStateChangedEventArgs.cs
- ValuePatternIdentifiers.cs
- LocalFileSettingsProvider.cs
- SqlCacheDependencyDatabase.cs
- BitmapEffect.cs
- RtfFormatStack.cs
- SqlUnionizer.cs
- ListViewDataItem.cs
- ListViewCancelEventArgs.cs
- Processor.cs
- SqlSupersetValidator.cs
- ProfileParameter.cs
- CurrencyManager.cs
- _CommandStream.cs
- ButtonPopupAdapter.cs
- MdiWindowListItemConverter.cs
- XsdValidatingReader.cs
- MarkupExtensionParser.cs
- Selector.cs
- Clock.cs
- XmlNamespaceMapping.cs
- PageAdapter.cs
- Bold.cs
- OdbcError.cs
- EnumBuilder.cs
- SymbolPair.cs
- HtmlForm.cs
- QueryOperatorEnumerator.cs
- MonthChangedEventArgs.cs
- ScriptResourceAttribute.cs
- CompositionCommandSet.cs
- BitConverter.cs
- MenuItemAutomationPeer.cs
- PolyQuadraticBezierSegment.cs
- StdValidatorsAndConverters.cs
- OleDbInfoMessageEvent.cs
- DelimitedListTraceListener.cs
- TypeElementCollection.cs
- TreeViewBindingsEditorForm.cs
- ISFTagAndGuidCache.cs
- DesignerActionListCollection.cs
- PropertiesTab.cs
- ScriptManagerProxy.cs
- dbenumerator.cs
- TransformedBitmap.cs
- FrugalMap.cs
- ReflectionServiceProvider.cs
- ZipIOLocalFileDataDescriptor.cs
- EntityDataSourceSelectingEventArgs.cs
- SHA512CryptoServiceProvider.cs
- DetailsViewRowCollection.cs
- MessageSecurityOverTcpElement.cs
- UpdatePanelControlTrigger.cs
- NamespaceMapping.cs
- PartialList.cs
- Html32TextWriter.cs
- LoginDesigner.cs
- WindowsTooltip.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- XamlToRtfWriter.cs
- ThreadSafeList.cs
- WorkItem.cs
- DispatcherSynchronizationContext.cs
- DataRecordInfo.cs
- TextOptions.cs
- Int64AnimationBase.cs
- MouseEventArgs.cs
- SymDocumentType.cs
- NullableDoubleSumAggregationOperator.cs
- SqlBulkCopyColumnMapping.cs
- WindowProviderWrapper.cs
- HostSecurityManager.cs