Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / MIT / System / Web / UI / MobileControls / Design / Util / ImageCreator.cs / 1305376 / ImageCreator.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Util
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal sealed class ImageCreator
{
const String _fontFamily = "Tahoma"; // default font used for the
// title and error message
private static int GetHeight(
String text,
Font font,
int width
) {
// THIS----S: I need a bitmap to get a graphics object to measure
// the string, but I can not create the bitmap I intend to return
// until I know how big it needs to be...
using(Bitmap bmp = new Bitmap(1,1))
{
using(Graphics g = Graphics.FromImage(bmp))
{
SizeF size = new SizeF(width, 0);
size = g.MeasureString(text, font, size);
return (int) (size.Height + 1);
}} // using bmp, g
}
internal static void CreateBackgroundImage(
ref TemporaryBitmapFile bmpFile,
String controlID,
String title,
String message,
bool infoMode,
int controlWidth
) {
// Really, anything this small is not practically going to
// show readable text. Truncate instead of trying to display
// the string vertically.
if(controlWidth < 75)
{
controlWidth = 75;
}
Bitmap errorIcon = infoMode? GenericUI.InfoIcon : GenericUI.ErrorIcon;
bool showMessage = message != null && message.Length != 0;
bool showTitle = (title != null && title.Length != 0)
|| (controlID != null && controlID.Length != 0);
Debug.Assert(showMessage || showTitle);
//
using(
Font normalFont = new Font(_fontFamily, 8, FontStyle.Regular),
boldFont = new Font(normalFont.FontFamily, 8, FontStyle.Bold)
) {
using(
Brush controlTextBrush = new SolidBrush(SystemColors.ControlText),
controlDarkBrush = new SolidBrush(SystemColors.ControlDark),
controlBrush = new SolidBrush(SystemColors.Control),
windowBrush = new SolidBrush(SystemColors.Window)
) {
using(
Pen controlDarkPen = new Pen(SystemColors.ControlDark),
windowPen = new Pen(SystemColors.Window)
) {
int barHeight = 0;
if(showTitle)
{
// We do not measure the height of the real title because
// we inted to truncate rather than wrap.
barHeight = GetHeight(
"'",
normalFont,
(controlWidth - 30)
) + 6;
}
int messageHeight = 0;
if(showMessage)
{
int textHeight = GetHeight(
message,
normalFont,
(controlWidth - 30)
);
messageHeight = (textHeight < (errorIcon.Height + 6)) ?
(errorIcon.Height + 6) : textHeight + 3;
}
int width = 500; // normally only 300px visible.
int height = barHeight + messageHeight;
Bitmap bitmap = new Bitmap(width, height);
using(Graphics g = Graphics.FromImage(bitmap))
{
if (showTitle)
{
// The rectangle area
g.FillRectangle(controlBrush, 0, 0, width, barHeight);
// The gray line below the controlID
g.DrawLine(controlDarkPen, 0, barHeight - 1, width, barHeight - 1);
// Draw the text "controlTypeName - controlID"
g.DrawString(controlID, boldFont, controlTextBrush, 2, 2);
if(title != null && title.Length > 0)
{
int strPelLen = (int) g.MeasureString(controlID, boldFont).Width;
g.DrawString(" - " + title, normalFont, controlTextBrush, 4 + strPelLen, 2);
}
}
if (showMessage)
{
// The transparent line between controlID and errormessage.
g.DrawLine(windowPen, 0, barHeight, width, barHeight);
// The message rectangle area
g.FillRectangle(controlDarkBrush, 0, barHeight + 1, width, messageHeight - 1);
// Draw the message text
g.DrawString(message, normalFont, windowBrush,
new RectangleF(20, barHeight + 1, controlWidth - 30, messageHeight - 1));
// Draw the icon
g.DrawImage(errorIcon, 2, barHeight + 3);
}
if(bmpFile == null)
{
bmpFile = new TemporaryBitmapFile(bitmap);
}
else
{
bmpFile.UnderlyingBitmap = bitmap;
}
} // using g
}}} // using Fonts, Brushes, and Pens
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Util
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal sealed class ImageCreator
{
const String _fontFamily = "Tahoma"; // default font used for the
// title and error message
private static int GetHeight(
String text,
Font font,
int width
) {
// THIS----S: I need a bitmap to get a graphics object to measure
// the string, but I can not create the bitmap I intend to return
// until I know how big it needs to be...
using(Bitmap bmp = new Bitmap(1,1))
{
using(Graphics g = Graphics.FromImage(bmp))
{
SizeF size = new SizeF(width, 0);
size = g.MeasureString(text, font, size);
return (int) (size.Height + 1);
}} // using bmp, g
}
internal static void CreateBackgroundImage(
ref TemporaryBitmapFile bmpFile,
String controlID,
String title,
String message,
bool infoMode,
int controlWidth
) {
// Really, anything this small is not practically going to
// show readable text. Truncate instead of trying to display
// the string vertically.
if(controlWidth < 75)
{
controlWidth = 75;
}
Bitmap errorIcon = infoMode? GenericUI.InfoIcon : GenericUI.ErrorIcon;
bool showMessage = message != null && message.Length != 0;
bool showTitle = (title != null && title.Length != 0)
|| (controlID != null && controlID.Length != 0);
Debug.Assert(showMessage || showTitle);
//
using(
Font normalFont = new Font(_fontFamily, 8, FontStyle.Regular),
boldFont = new Font(normalFont.FontFamily, 8, FontStyle.Bold)
) {
using(
Brush controlTextBrush = new SolidBrush(SystemColors.ControlText),
controlDarkBrush = new SolidBrush(SystemColors.ControlDark),
controlBrush = new SolidBrush(SystemColors.Control),
windowBrush = new SolidBrush(SystemColors.Window)
) {
using(
Pen controlDarkPen = new Pen(SystemColors.ControlDark),
windowPen = new Pen(SystemColors.Window)
) {
int barHeight = 0;
if(showTitle)
{
// We do not measure the height of the real title because
// we inted to truncate rather than wrap.
barHeight = GetHeight(
"'",
normalFont,
(controlWidth - 30)
) + 6;
}
int messageHeight = 0;
if(showMessage)
{
int textHeight = GetHeight(
message,
normalFont,
(controlWidth - 30)
);
messageHeight = (textHeight < (errorIcon.Height + 6)) ?
(errorIcon.Height + 6) : textHeight + 3;
}
int width = 500; // normally only 300px visible.
int height = barHeight + messageHeight;
Bitmap bitmap = new Bitmap(width, height);
using(Graphics g = Graphics.FromImage(bitmap))
{
if (showTitle)
{
// The rectangle area
g.FillRectangle(controlBrush, 0, 0, width, barHeight);
// The gray line below the controlID
g.DrawLine(controlDarkPen, 0, barHeight - 1, width, barHeight - 1);
// Draw the text "controlTypeName - controlID"
g.DrawString(controlID, boldFont, controlTextBrush, 2, 2);
if(title != null && title.Length > 0)
{
int strPelLen = (int) g.MeasureString(controlID, boldFont).Width;
g.DrawString(" - " + title, normalFont, controlTextBrush, 4 + strPelLen, 2);
}
}
if (showMessage)
{
// The transparent line between controlID and errormessage.
g.DrawLine(windowPen, 0, barHeight, width, barHeight);
// The message rectangle area
g.FillRectangle(controlDarkBrush, 0, barHeight + 1, width, messageHeight - 1);
// Draw the message text
g.DrawString(message, normalFont, windowBrush,
new RectangleF(20, barHeight + 1, controlWidth - 30, messageHeight - 1));
// Draw the icon
g.DrawImage(errorIcon, 2, barHeight + 3);
}
if(bmpFile == null)
{
bmpFile = new TemporaryBitmapFile(bitmap);
}
else
{
bmpFile.UnderlyingBitmap = bitmap;
}
} // using g
}}} // using Fonts, Brushes, and Pens
}
}
}
// 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
- RootAction.cs
- TimeoutConverter.cs
- EmptyControlCollection.cs
- DispatchChannelSink.cs
- Matrix.cs
- FontEmbeddingManager.cs
- CompositeCollectionView.cs
- BindingExpression.cs
- XmlLanguage.cs
- LoginUtil.cs
- SetterBase.cs
- RIPEMD160.cs
- XmlSchemaCompilationSettings.cs
- FlowPanelDesigner.cs
- storepermissionattribute.cs
- CqlLexer.cs
- BuilderInfo.cs
- BrushConverter.cs
- SerialPort.cs
- MemoryFailPoint.cs
- DocumentOrderQuery.cs
- TemplateLookupAction.cs
- RegisteredArrayDeclaration.cs
- QualifiedCellIdBoolean.cs
- TextEmbeddedObject.cs
- CharConverter.cs
- PropertyIdentifier.cs
- XmlSchemaObject.cs
- UnknownWrapper.cs
- PageAsyncTask.cs
- DataGridViewRowConverter.cs
- HostedBindingBehavior.cs
- XmlCountingReader.cs
- EnumerableCollectionView.cs
- IUnknownConstantAttribute.cs
- ServiceOperation.cs
- DataGrid.cs
- WindowsFormsSectionHandler.cs
- HttpProfileBase.cs
- CacheSection.cs
- DPTypeDescriptorContext.cs
- SchemaObjectWriter.cs
- WebPartCatalogAddVerb.cs
- SpeechDetectedEventArgs.cs
- ArraySubsetEnumerator.cs
- Models.cs
- Opcode.cs
- COAUTHIDENTITY.cs
- WmlFormAdapter.cs
- BaseProcessor.cs
- EncodingDataItem.cs
- MaterialCollection.cs
- GacUtil.cs
- WebPartActionVerb.cs
- WindowInteropHelper.cs
- FactoryGenerator.cs
- FormViewInsertEventArgs.cs
- HttpListenerElement.cs
- TraceFilter.cs
- MenuItemStyle.cs
- ValidatorCompatibilityHelper.cs
- CacheMemory.cs
- ActiveXSite.cs
- TdsRecordBufferSetter.cs
- XamlFigureLengthSerializer.cs
- PropertyMapper.cs
- ScriptMethodAttribute.cs
- WebPartEditVerb.cs
- Point3DConverter.cs
- TrueReadOnlyCollection.cs
- CompiledQuery.cs
- TreeNodeCollection.cs
- MsmqMessage.cs
- CompilerScope.Storage.cs
- HwndTarget.cs
- EntityParameter.cs
- Visual3D.cs
- JsonServiceDocumentSerializer.cs
- XmlRawWriter.cs
- InvalidFilterCriteriaException.cs
- StreamInfo.cs
- CodeDomLoader.cs
- TemplateControlBuildProvider.cs
- TemplateColumn.cs
- SchemaTypeEmitter.cs
- DynamicDataExtensions.cs
- MemoryMappedFile.cs
- DataServiceStreamResponse.cs
- FileVersion.cs
- CodeExpressionCollection.cs
- OptimalBreakSession.cs
- Utils.cs
- ArgumentsParser.cs
- StoreItemCollection.Loader.cs
- HttpContext.cs
- AutomationPatternInfo.cs
- EncodingNLS.cs
- ToolBar.cs
- DataObject.cs
- XmlNamespaceMappingCollection.cs