Пример #1
0
        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
        }
Пример #2
0
        /// <summary>
        ///    <para>
        ///       Disposes of the resources (other than memory) used by the
        ///    <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/>.
        ///    </para>
        /// </summary>
        /// <remarks>
        ///    <para>
        ///       Call <see langword='Dispose'/> when
        ///       you are finished using the <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/>. The <see langword='Dispose'/> method leaves the <see cref='System.Web.UI.Design.WebControls.DataListDesigner'/> in an unusable state. After
        ///       calling <see langword='Dispose'/>, you must release all
        ///       references to the <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/> so the memory it was occupying
        ///       can be reclaimed by garbage collection.
        ///    </para>
        ///    <note type="note">
        ///       Always call <see langword='Dispose'/> before you release your last reference to
        ///       the <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/>. Otherwise, the resources
        ///       the <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/> is using will not be freed
        ///       until garbage collection calls the <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/> object's
        ///       destructor.
        ///    </note>
        /// </remarks>
        /// <seealso cref='System.ComponentModel.Design.IDesigner'/>
        protected override void Dispose(bool disposing) 
        {
            if (disposing && _tempBmpFile != null)
            {
                _tempBmpFile.Dispose();
                _cachedWbmpUri = null;
                _tempBmpFile = null;
            }

            base.Dispose(disposing);
        }
Пример #3
0
        private String GetConvertedImageURI(String imageUriString)
        {
            Uri baseUri = new Uri(BaseUrl);
            Uri imageUri = new Uri(baseUri, imageUriString);
            String extension = Path.GetExtension(imageUriString);

            if(extension.Equals(".wbmp"))
            {
                if(_tempBmpFile != null)
                {
                    if(_cachedWbmpUri != null
                        && _cachedWbmpUri.Equals(imageUri))
                    {
                        return _tempBmpFile.Url;
                    }
                    else
                    {
                        _tempBmpFile.Dispose();
                        _tempBmpFile = null;
                        _cachedWbmpUri = null;
                    }
                }

                Byte[] buffer = FileReader.Read(imageUri);
                if(buffer == null)
                {
                    // Could not read image from URI, return original URI to
                    // Trident and let it render as a broken image.
                    goto ConversionError;
                }
                Bitmap bitmap = WbmpConverter.Convert(buffer);
                if(bitmap == null)
                {
                    // .wbmp appears to be corrupt, return original URI to
                    // Trident and let it render as a broken image.
                    goto ConversionError;
                }
                _tempBmpFile = new TemporaryBitmapFile(bitmap);
                imageUriString = _tempBmpFile.Url;
                _cachedWbmpUri = imageUri;
            }
ConversionError:
            return imageUriString;
        }
Пример #4
0
        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
        }