Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / WinForms / Managed / System / WinForms / ButtonInternal / CheckBoxStandardAdapter.cs / 1 / CheckBoxStandardAdapter.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms.ButtonInternal {
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Windows.Forms;
using System.Windows.Forms.Layout;
internal sealed class CheckBoxStandardAdapter : CheckBoxBaseAdapter {
internal CheckBoxStandardAdapter(ButtonBase control) : base(control) {}
internal override void PaintUp(PaintEventArgs e, CheckState state)
{
if (Control.Appearance == Appearance.Button) {
ButtonAdapter.PaintUp(e, Control.CheckState);
}
else {
ColorData colors = PaintRender(e.Graphics).Calculate();
LayoutData layout = Layout(e).Layout();
PaintButtonBackground(e, Control.ClientRectangle, null);
//minor adjustment to make sure the appearance is exactly the same as Win32 app.
int focusRectFixup = layout.focus.X & 0x1; // if it's odd, subtract one pixel for fixup.
if (!Application.RenderWithVisualStyles) {
focusRectFixup = 1 - focusRectFixup;
}
if (!layout.options.everettButtonCompat) {
layout.textBounds.Offset(-1, -1);
}
layout.imageBounds.Offset(-1, -1);
layout.focus.Offset(-(focusRectFixup+1), -2);
layout.focus.Width = layout.textBounds.Width + layout.imageBounds.Width - 1;
layout.focus.Intersect(layout.textBounds);
if( layout.options.textAlign != LayoutUtils.AnyLeft && layout.options.useCompatibleTextRendering && layout.options.font.Italic) {
// fixup for GDI+ text rendering. VSW#515164
layout.focus.Width += 2;
}
PaintImage(e, layout);
DrawCheckBox(e, layout);
PaintField(e, layout, colors, colors.windowText, true);
}
}
internal override void PaintDown(PaintEventArgs e, CheckState state) {
if (Control.Appearance == Appearance.Button) {
ButtonAdapter.PaintDown(e, Control.CheckState);
}
else {
PaintUp(e, state);
}
}
internal override void PaintOver(PaintEventArgs e, CheckState state) {
if (Control.Appearance == Appearance.Button) {
ButtonAdapter.PaintOver(e, Control.CheckState);
}
else {
PaintUp(e, state);
}
}
internal override Size GetPreferredSizeCore(Size proposedSize) {
if (Control.Appearance == Appearance.Button) {
ButtonStandardAdapter adapter = new ButtonStandardAdapter(Control);
return adapter.GetPreferredSizeCore(proposedSize);
}
else {
using (Graphics measurementGraphics = WindowsFormsUtils.CreateMeasurementGraphics()) {
using (PaintEventArgs pe = new PaintEventArgs(measurementGraphics, new Rectangle())) {
LayoutOptions options = Layout(pe);
return options.GetPreferredSizeCore(proposedSize);
}
}
}
}
#region Layout
private new ButtonStandardAdapter ButtonAdapter {
get {
return ((ButtonStandardAdapter)base.ButtonAdapter);
}
}
protected override ButtonBaseAdapter CreateButtonAdapter() {
return new ButtonStandardAdapter(Control);
}
protected override LayoutOptions Layout(PaintEventArgs e) {
LayoutOptions layout = CommonLayout();
layout.checkPaddingSize = 1;
layout.everettButtonCompat = !Application.RenderWithVisualStyles;
// VSWhidbey 420870
if (Application.RenderWithVisualStyles) {
using (Graphics g = WindowsFormsUtils.CreateMeasurementGraphics()) {
layout.checkSize = CheckBoxRenderer.GetGlyphSize(g, CheckBoxRenderer.ConvertFromButtonState(GetState(), true, Control.MouseIsOver)).Width;
}
}
return layout;
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms.ButtonInternal {
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Windows.Forms;
using System.Windows.Forms.Layout;
internal sealed class CheckBoxStandardAdapter : CheckBoxBaseAdapter {
internal CheckBoxStandardAdapter(ButtonBase control) : base(control) {}
internal override void PaintUp(PaintEventArgs e, CheckState state)
{
if (Control.Appearance == Appearance.Button) {
ButtonAdapter.PaintUp(e, Control.CheckState);
}
else {
ColorData colors = PaintRender(e.Graphics).Calculate();
LayoutData layout = Layout(e).Layout();
PaintButtonBackground(e, Control.ClientRectangle, null);
//minor adjustment to make sure the appearance is exactly the same as Win32 app.
int focusRectFixup = layout.focus.X & 0x1; // if it's odd, subtract one pixel for fixup.
if (!Application.RenderWithVisualStyles) {
focusRectFixup = 1 - focusRectFixup;
}
if (!layout.options.everettButtonCompat) {
layout.textBounds.Offset(-1, -1);
}
layout.imageBounds.Offset(-1, -1);
layout.focus.Offset(-(focusRectFixup+1), -2);
layout.focus.Width = layout.textBounds.Width + layout.imageBounds.Width - 1;
layout.focus.Intersect(layout.textBounds);
if( layout.options.textAlign != LayoutUtils.AnyLeft && layout.options.useCompatibleTextRendering && layout.options.font.Italic) {
// fixup for GDI+ text rendering. VSW#515164
layout.focus.Width += 2;
}
PaintImage(e, layout);
DrawCheckBox(e, layout);
PaintField(e, layout, colors, colors.windowText, true);
}
}
internal override void PaintDown(PaintEventArgs e, CheckState state) {
if (Control.Appearance == Appearance.Button) {
ButtonAdapter.PaintDown(e, Control.CheckState);
}
else {
PaintUp(e, state);
}
}
internal override void PaintOver(PaintEventArgs e, CheckState state) {
if (Control.Appearance == Appearance.Button) {
ButtonAdapter.PaintOver(e, Control.CheckState);
}
else {
PaintUp(e, state);
}
}
internal override Size GetPreferredSizeCore(Size proposedSize) {
if (Control.Appearance == Appearance.Button) {
ButtonStandardAdapter adapter = new ButtonStandardAdapter(Control);
return adapter.GetPreferredSizeCore(proposedSize);
}
else {
using (Graphics measurementGraphics = WindowsFormsUtils.CreateMeasurementGraphics()) {
using (PaintEventArgs pe = new PaintEventArgs(measurementGraphics, new Rectangle())) {
LayoutOptions options = Layout(pe);
return options.GetPreferredSizeCore(proposedSize);
}
}
}
}
#region Layout
private new ButtonStandardAdapter ButtonAdapter {
get {
return ((ButtonStandardAdapter)base.ButtonAdapter);
}
}
protected override ButtonBaseAdapter CreateButtonAdapter() {
return new ButtonStandardAdapter(Control);
}
protected override LayoutOptions Layout(PaintEventArgs e) {
LayoutOptions layout = CommonLayout();
layout.checkPaddingSize = 1;
layout.everettButtonCompat = !Application.RenderWithVisualStyles;
// VSWhidbey 420870
if (Application.RenderWithVisualStyles) {
using (Graphics g = WindowsFormsUtils.CreateMeasurementGraphics()) {
layout.checkSize = CheckBoxRenderer.GetGlyphSize(g, CheckBoxRenderer.ConvertFromButtonState(GetState(), true, Control.MouseIsOver)).Width;
}
}
return layout;
}
#endregion
}
}
// 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
- ToolStripDropDownDesigner.cs
- HebrewNumber.cs
- TypeUtils.cs
- PrivateFontCollection.cs
- FileChangesMonitor.cs
- DocumentEventArgs.cs
- XslCompiledTransform.cs
- PasswordTextContainer.cs
- UDPClient.cs
- XmlSchemaInclude.cs
- SerializationInfo.cs
- ModelPerspective.cs
- DotAtomReader.cs
- DecoderNLS.cs
- IdentifierCreationService.cs
- IndexOutOfRangeException.cs
- HatchBrush.cs
- EntityReference.cs
- ObjectStateEntryDbDataRecord.cs
- _Semaphore.cs
- Constraint.cs
- RectAnimation.cs
- DefaultValueAttribute.cs
- SHA256Managed.cs
- WebPartEditVerb.cs
- XmlPropertyBag.cs
- Substitution.cs
- FigureParaClient.cs
- QuarticEase.cs
- Trigger.cs
- ActivationWorker.cs
- Slider.cs
- XamlStyleSerializer.cs
- StreamAsIStream.cs
- Package.cs
- SchemaImporterExtensionsSection.cs
- ParameterReplacerVisitor.cs
- RequestValidator.cs
- ImageAnimator.cs
- Pkcs9Attribute.cs
- DetailsViewAutoFormat.cs
- SizeAnimationBase.cs
- OdbcParameter.cs
- CharacterBufferReference.cs
- StringSource.cs
- PageThemeCodeDomTreeGenerator.cs
- DropDownButton.cs
- SqlReferenceCollection.cs
- FontStyle.cs
- UserPersonalizationStateInfo.cs
- TableSectionStyle.cs
- XmlMemberMapping.cs
- WebServiceClientProxyGenerator.cs
- KeyedCollection.cs
- RsaElement.cs
- ReadOnlyDictionary.cs
- MonthCalendar.cs
- SqlDependency.cs
- MessageQueueEnumerator.cs
- SqlTriggerAttribute.cs
- XmlSchemaDocumentation.cs
- InstancePersistenceCommandException.cs
- SoapAttributeOverrides.cs
- CssClassPropertyAttribute.cs
- TreeView.cs
- ViewStateException.cs
- EnumValAlphaComparer.cs
- Sentence.cs
- ViewSimplifier.cs
- TextEditorTyping.cs
- ChtmlTextWriter.cs
- CroppedBitmap.cs
- ObjRef.cs
- FacetDescription.cs
- Collection.cs
- DataGridViewTextBoxColumn.cs
- Parser.cs
- _AutoWebProxyScriptWrapper.cs
- BaseDataListComponentEditor.cs
- MsmqInputChannelListenerBase.cs
- SimpleLine.cs
- EastAsianLunisolarCalendar.cs
- CalendarTable.cs
- ParserContext.cs
- SqlNamer.cs
- SqlEnums.cs
- UnmanagedMemoryStream.cs
- DbParameterCollectionHelper.cs
- RestClientProxyHandler.cs
- ReturnValue.cs
- MultiBinding.cs
- SegmentInfo.cs
- EncodingFallbackAwareXmlTextWriter.cs
- SocketElement.cs
- CompositeScriptReference.cs
- RtType.cs
- ComponentResourceManager.cs
- Camera.cs
- ToggleProviderWrapper.cs
- StringOutput.cs