Exemplo n.º 1
0
        /// <summary>
        /// Generates the preview.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <remarks>Documented by Dev08, 2008-12-09</remarks>
        private static void GeneratePreview(LearningModulesIndexEntry entry)
        {
            Bitmap   preview = new Bitmap(MAX_WIDTH, MAX_HEIGHT);    //Todo: get the available preview size
            Graphics g       = Graphics.FromImage(preview);

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            try
            {
                LearningModulePreviewStruct lmps = GetLearningModulePreviewData(entry.Dictionary, entry.ConnectionString);
                Font         font         = new Font("Arial", 9.0f);
                StringFormat stringFormat = new StringFormat();
                stringFormat.Alignment = StringAlignment.Center;

                //Preview Background:
                g.FillRectangle(Brushes.White, 0, 0, MAX_WIDTH, MAX_HEIGHT);
                //Border
                g.DrawLine(Pens.Black, new Point(0, 0), new Point(0, MAX_HEIGHT));
                g.DrawLine(Pens.Black, new Point(0, 0), new Point(MAX_WIDTH, 0));
                g.DrawLine(Pens.Black, new Point(0, MAX_HEIGHT - 1), new Point(MAX_WIDTH - 1, MAX_HEIGHT - 1));
                g.DrawLine(Pens.Black, new Point(MAX_WIDTH - 1, 0), new Point(MAX_WIDTH - 1, MAX_HEIGHT - 1));

                //Text String:
                lmps.Text = FitStringToArea(g, lmps.Text, font, MAX_WIDTH);
                g.DrawString(lmps.Text, font, Brushes.Black, new RectangleF(0, 0, MAX_WIDTH, 15), stringFormat); //the rectangleF is needed to cut the string if FitStringToArea does not cut enough of the string.

                //Preview Image:
                g.DrawImage(lmps.Media, MAX_WIDTH / 2 - lmps.Media.Width / 2, 15);

                LearningModulePreview lmPreview = new LearningModulePreview();
                lmPreview.Description  = lmps.Description;
                lmPreview.PreviewImage = (Image)preview.Clone();

                entry.Preview = lmPreview;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("LearningModulesIndex.GeneratePreview(" + entry.DisplayName + ")" + ex.Message);
            }
            finally
            {
                preview.Dispose();
                g.Dispose();
            }
        }
        /// <summary>
        /// Generates the preview.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <remarks>Documented by Dev08, 2008-12-09</remarks>
        private static void GeneratePreview(LearningModulesIndexEntry entry)
        {
            Bitmap preview = new Bitmap(MAX_WIDTH, MAX_HEIGHT);      //Todo: get the available preview size
            Graphics g = Graphics.FromImage(preview);
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            try
            {
                LearningModulePreviewStruct lmps = GetLearningModulePreviewData(entry.Dictionary, entry.ConnectionString);
                Font font = new Font("Arial", 9.0f);
                StringFormat stringFormat = new StringFormat();
                stringFormat.Alignment = StringAlignment.Center;

                //Preview Background:
                g.FillRectangle(Brushes.White, 0, 0, MAX_WIDTH, MAX_HEIGHT);
                //Border
                g.DrawLine(Pens.Black, new Point(0, 0), new Point(0, MAX_HEIGHT));
                g.DrawLine(Pens.Black, new Point(0, 0), new Point(MAX_WIDTH, 0));
                g.DrawLine(Pens.Black, new Point(0, MAX_HEIGHT - 1), new Point(MAX_WIDTH - 1, MAX_HEIGHT - 1));
                g.DrawLine(Pens.Black, new Point(MAX_WIDTH - 1, 0), new Point(MAX_WIDTH - 1, MAX_HEIGHT - 1));

                //Text String:
                lmps.Text = FitStringToArea(g, lmps.Text, font, MAX_WIDTH);
                g.DrawString(lmps.Text, font, Brushes.Black, new RectangleF(0, 0, MAX_WIDTH, 15), stringFormat); //the rectangleF is needed to cut the string if FitStringToArea does not cut enough of the string.

                //Preview Image:
                g.DrawImage(lmps.Media, MAX_WIDTH / 2 - lmps.Media.Width / 2, 15);

                LearningModulePreview lmPreview = new LearningModulePreview();
                lmPreview.Description = lmps.Description;
                lmPreview.PreviewImage = (Image)preview.Clone();

                entry.Preview = lmPreview;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("LearningModulesIndex.GeneratePreview(" + entry.DisplayName + ")" + ex.Message);
            }
            finally
            {
                preview.Dispose();
                g.Dispose();
            }
        }