Exemplo n.º 1
0
        void m_printDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            SelectedMealCollection colData = (SelectedMealCollection)this.FindResource("SelectedMealCollectionData");
            float leftMargin = e.MarginBounds.Left;
            float rightMargin = e.MarginBounds.Right;
            float topMargin = e.MarginBounds.Top;
          
            float yPos = leftMargin;
            float xPos = 0;
            float centrePos = 2 * (rightMargin - leftMargin) / 5;
            float rightPos =  4 * (rightMargin - leftMargin) / 5;
            int count = 0;

            System.Drawing.Font printFont = new System.Drawing.Font("Arial", 10);
            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);

            // Work out the number of lines per page, using the MarginBounds.
            float linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
            float lineCount = 0;
            foreach (var selectedMeal in colData)
            {
                // calculate the next line position based on the height of the font according to the printing device
                yPos = topMargin + (count++ * printFont.GetHeight(e.Graphics));
                e.Graphics.DrawString(selectedMeal.Date, printFont, myBrush, xPos, yPos);
                lineCount++;
   
                yPos = topMargin + (count++ * printFont.GetHeight(e.Graphics));
                e.Graphics.DrawString(selectedMeal.Meal, printFont, myBrush, xPos + 20, yPos);

                lineCount++;

                if (lineCount > linesPerPage) { break; }
            }

            lineCount = 0;
            count = 0;

            SelectedIngredientsCollection ingredientData = (SelectedIngredientsCollection)this.FindResource("SelectedIngredientsCollectionData");

            foreach (SelectedIngredient ingredient in ingredientData)
            {               
                // calculate the next line position based on the height of the font according to the printing device
                yPos = topMargin + (count++ * printFont.GetHeight(e.Graphics));
                xPos = centrePos;
                if (lineCount > linesPerPage) xPos = rightPos;
                e.Graphics.DrawString(ingredient.Ingredient, printFont, myBrush, xPos, yPos);
                lineCount++;
            }

            // If there are more lines, print another page.
            if (lineCount > linesPerPage)
            {
           //     e.HasMorePages = true;
            }
            else
            {
                e.HasMorePages = false;
                myBrush.Dispose();
            }
        }
 public CustomListViewItem()
 {
     // Customize the ListViewItem control by setting various properties.
     BackColor = System.Drawing.Color.White;
     Font = new System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Bold);
     ForeColor = System.Drawing.Color.Gray;
 }
        //BinaryWrite方法将一个二进制字符串写入HTTP输出流
        //public void BinaryWrite(byte[] buffer)
        public void DrawBinaryImage()
        {
            //要绘制的字符串
            string word = "5142";

            //设定画布大小,Math.Ceiling向上取整
            int width = int.Parse(Math.Ceiling(word.Length * 20.5).ToString());
            int height = 22;

            //创建一个指定大小的画布
            System.Drawing.Bitmap image = new System.Drawing.Bitmap(width, height);
            //创建一个指定的GDI+绘图图面
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
            try
            {
                //用白色填充图面
                g.Clear(System.Drawing.Color.White);

                //绘制背景噪音线
                Random r = new Random();
                int x1, x2, y1, y2;
                for (int i = 0; i < 2; i++)
                {
                    x1 = r.Next(image.Width);
                    x2 = r.Next(image.Width);
                    y1 = r.Next(image.Height);
                    y2 = r.Next(image.Height);
                    g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Black), x1, y1, x2, y2);
                }

                //绘制文字
                System.Drawing.Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold));
                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush
                                                        (new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
                                                        System.Drawing.Color.Blue, System.Drawing.Color.DarkRed, 5.2f, true);
                g.DrawString(word, font, brush, 2, 2);

                //绘制前景噪点
                int x, y;
                for (int i = 0; i < 100; i++)
                {
                    x = r.Next(image.Width);
                    y = r.Next(image.Height);
                    image.SetPixel(x, y, System.Drawing.Color.FromArgb(r.Next()));
                }

                //绘制边框
                g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
                System.IO.MemoryStream ms = new MemoryStream();
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                Response.ClearContent();
                Response.ContentType = "image/Gif";
                Response.BinaryWrite(ms.ToArray());
            }
            catch (Exception)
            {
                g.Dispose();
                image.Dispose();
            }
        }
Exemplo n.º 4
0
        private int GetFontId(FontDescriptor fd)
        {
            var fontId = String.Intern(fd.Id);

            var index = m_registeredFonts.FindIndex(fm => Object.ReferenceEquals(fm.m_id, fontId));
            if (index == -1)
            {
                var fontObject = new Font(fd.FamilyName, fd.Size, fd.Style);
                m_registeredFonts.Add(new FontMetrics
                {
                    m_id = fontId,
                    m_fontObject = fontObject,
                    m_outlineThickness = fd.OutlineThickness,
                    m_spaceWidth = MeasureSpace(fontObject).Width,
                    m_fullWidthSpaceWidth = MeasureFullwidthSpace(fontObject).Width,
                    m_ascentInPixels = CalculateAscentInPixel(fontObject)
                });
                index = m_registeredFonts.Count - 1;
            }

            if (index > 0xffff)
            {
                throw new OverflowException("Number of registered font has grown ridiculously too large.");
            }

            return index;
        }
Exemplo n.º 5
0
        public bool InsertExcel(string titleName, string unit, GridControl gridControl, TONLI.BZH.UI.DSOFramerWordControl wordcontrol)
        {
            try
            {
                System.Drawing.Font font = new System.Drawing.Font("���ו", 16);
                wordcontrol.DoInsert("\n\n"+titleName+"\n"  , font, TONLI.BZH.UI.WdParagraphAlignment.Center);
                //wordcontrol.DoPaste();

                font = new System.Drawing.Font("���ו", 12);
                wordcontrol.DoInsert(unit + "\n", font, TONLI.BZH.UI.WdParagraphAlignment.Right);
                //wordcontrol.DoPaste();

                wordcontrol.DoInsert("", font, TONLI.BZH.UI.WdParagraphAlignment.Center);
                string filename =System.Windows.Forms.Application.StartupPath + "\\BlogData\\Blog.xls";
                gridControl.DefaultView.ExportToExcelOld(filename);

                wordcontrol.DoInsertOleObject(filename);
                //System.Drawing.Font font = new System.Drawing.Font("���ו", 16);
                wordcontrol.DoInsert("", font, TONLI.BZH.UI.WdParagraphAlignment.Center);
                //Microsoft.Office.Interop.Excel.Application ep = new Microsoft.Office.Interop.Excel.Application();

                //Microsoft.Office.Interop.Excel._Workbook wb = ep.Workbooks.Add(filename);

                //Microsoft.Office.Interop.Excel.Sheets sheets = wb.Worksheets;

                //Microsoft.Office.Interop.Excel._Worksheet ws = (Microsoft.Office.Interop.Excel._Worksheet)sheets.get_Item(1);// [System.Type.Missing];//.get.get_Item("xx");
                //ws.UsedRange.Select();
                //ws.UsedRange.Copy(System.Type.Missing);

                //wordcontrol.DoPaste();

                return true;
            }
            catch { return false; }
        }
Exemplo n.º 6
0
	public DrawingFont(IToolkit toolkit, System.Drawing.Font properties, float dpi)
	{
		this.toolkit = toolkit;
		this.properties = properties;
		this.dpi = dpi;
		CreateFont();
	}
 public BaseNavMin(
     System.Windows.Forms.Control parentpal,
     System.Drawing.Size size,
     System.Drawing.Point point,
     float fontSize,
     System.Drawing.Color backcolor,
     System.Drawing.Color backlight,
     System.Drawing.Color forecolor,
     System.Drawing.Color forelight,
     System.Windows.Forms.AnchorStyles anchorstyle
     )
 {
     Backlight = backlight;
     Forelight = forelight;
     BackColor = Backcolor = backcolor;
     ForeColor = Forecolor = forecolor;
     Size = size;
     Location = point;
     Text = @"-";
     TextAlign = Helper.Align;
     Cursor = Helper.HCursors;
     Font = new System.Drawing.Font(Helper.FontSymbol, fontSize);
     Anchor = anchorstyle;
     parentpal.Controls.Add(this);
     MouseClick += BaseNavMin_MouseClick;
     MouseLeave += BaseNavMin_MouseLeave;
     MouseUp += BaseNavMin_MouseUp;
     MouseDown += BaseNavMin_MouseDown;
     MouseHover += BaseNavMin_MouseHover;
 }
Exemplo n.º 8
0
        private void LoadingProcess(object param)
        {
            LoadingResourcesDlg dlg = (LoadingResourcesDlg)param;
            try
            {
                // load symbols for elements
                ElementPTFactory elements = ElementPTFactory.Instance;
                System.Drawing.Font font = new System.Drawing.Font("Tahoma", 20);
                float onePer = 100.0f / elements.Size;
                float prog = 0;
                foreach (PeriodicTableElement element in elements)
                {
                    Texture tex = TextTexture.DrawTextToTexture(element.Symbol,
                                                font, device, 64, 64).Texture;

                    symbolTextures[element.Symbol] = tex;

                    prog += onePer;
                    dlg.Progress = (int)prog;
                }

                dlg.TryClose();
            }
            catch { }
        }
Exemplo n.º 9
0
        // prekresli sa vrchol
        private void repaintNodes(KDNode n)
        {
            System.Drawing.Font font = new System.Drawing.Font("Verdana", 10);
            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
            System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Black);

            if (n.highlight)
            {
                myBrush.Color = System.Drawing.Color.Green;
                myPen.Color = System.Drawing.Color.Green;
            }

            if (n.highlightRed)
            {
                myBrush.Color = System.Drawing.Color.Red;
                myPen.Color = System.Drawing.Color.Red;
            }
            if (n.highligthIn)
            {
                myBrush.Color = System.Drawing.Color.Red;
                myPen.Color = System.Drawing.Color.Red;
                g.DrawEllipse(myPen, n.getPoint().X - (RADIUS + 2), n.getPoint().Y - (RADIUS + 2), 2 * (RADIUS + 2), 2 * (RADIUS + 2));
                myPen.Color = System.Drawing.Color.Black;
            }

            g.FillEllipse(myBrush, n.getPoint().X - RADIUS, n.getPoint().Y - RADIUS, 2*RADIUS, 2*RADIUS);

            string s = "(" + n.getPoint().X.ToString() + "," + n.getPoint().Y.ToString() + ")";
            g.DrawString(s, font, myBrush, n.getPoint().X - 35, n.getPoint().Y);
        }
Exemplo n.º 10
0
 // Change the font size
 //
 protected override void OnMouseWheel(MouseEventArgs e)
 {
     base.OnMouseWheel(e);
     if (e.Delta > 0)
         Font = new System.Drawing.Font(Font.FontFamily, Font.Size + 0.2f);
     else
         Font = new System.Drawing.Font(Font.FontFamily, Font.Size - 0.2f);
 }
Exemplo n.º 11
0
 public TextCord(string st, float x, float y, System.Drawing.Font f, System.Drawing.Brush b)
 {
     X = x;
     Y = y;
     font = f;
     brush = b;
     str = st;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new TextEntity class.
 /// </summary>
 /// <param name="text">The Text.</param>
 /// <param name="font">The Font.</param>
 /// <param name="color">The Color.</param>
 /// <param name="wrapWidth">The Wordwrap Width.</param>
 public TextEntity(string text, OpenGLFont font, Color color, int wrapWidth = 0)
 {
     if (wrapWidth > 0) text = text.WordWrap(wrapWidth);
     var gdiFont = OpenGLHelper.ConvertFont(font);
     Id = text.GetHashCode() + gdiFont.GetHashCode() + color.GetHashCode();
     _text = text;
     _font = gdiFont;
     _color = color;
 }
Exemplo n.º 13
0
 public LibrarySpinEdit()
 {
     Properties.EditMask = "F0";
     Properties.MinValue = 0;
     Value = 0;
     Properties.MaxValue = 2000000000;
     Font = new System.Drawing.Font("Tahoma", 9, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
     Properties.IsFloatValue = false;
 }
Exemplo n.º 14
0
 public System.Drawing.Font GetFont(Styles.Font font)
 {
     System.Drawing.Font gdiFont;
     if (!fonts.TryGetValue(font, out gdiFont))
     {
         gdiFont = new System.Drawing.Font(font.FontFamily, (float)font.Size);
     }
     return gdiFont;
 }
Exemplo n.º 15
0
        //-----------------------------------------------------------------------------------
        #endregion
        //-----------------------------------------------------------------------------------
        #region Constructors
        //-----------------------------------------------------------------------------------
        /// <summary>
        /// Конструктор
        /// </summary>
        public TextDocumentPrinter()
        {
            _PrintDocument = new System.Drawing.Printing.PrintDocument();
            _PrintDocument.PrintPage += 
                new System.Drawing.Printing.PrintPageEventHandler(_PrintDocument_PrintPage);

            // Шрифт по умолчанию
            _PrintFont = new System.Drawing.Font("Courier New", 10);
        }
Exemplo n.º 16
0
 public static void SetFont()
 {
     FontDialog fd = new FontDialog();
     if(sysfont!=null)fd.Font = sysfont;
     if (fd.ShowDialog() == DialogResult.OK)
     {
         sysfont = fd.Font;
     }
 }
Exemplo n.º 17
0
        public CustomRichTextBox() {

            BackColor = System.Drawing.Color.WhiteSmoke;
            Font = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Regular);
            Size = new System.Drawing.Size(460, 457);
            Location = new System.Drawing.Point(0, 0);
            WordWrap = true;
            ReadOnly = true;
        }
Exemplo n.º 18
0
        private void fontButton_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FontDialog fd = new System.Windows.Forms.FontDialog();

               if (fd.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
               {
               font = fd.Font;
               lableFontname.Content = font.Name;
               }
        }
Exemplo n.º 19
0
 public Button()
     : base()
 {
     BackColor = System.Drawing.Color.Silver;
     FlatAppearance.BorderSize = 0;
     FlatStyle = System.Windows.Forms.FlatStyle.Flat;
     Font = new System.Drawing.Font(Font.FontFamily, 16, Font.Style);
     TabStop = false;
     UseVisualStyleBackColor = false;
 }
 private static double CalculateTextWidth(string font, int fontSize, string text)
 {
     // The algorithm is from below link
     // https://social.msdn.microsoft.com/Forums/office/en-US/28aae308-55cb-479f-9b58-d1797ed46a73/solution-how-to-autofit-excel-content?forum=oxmlsdk
     var stringFont = new System.Drawing.Font(font, fontSize);
     var textSize = TextRenderer.MeasureText(text, stringFont);
     var width = (textSize.Width / (double) 7 * 256 - 18) / 256;
     width = (double) decimal.Round((decimal) width + 0.2M, 2);
     return width;
 }
Exemplo n.º 21
0
 public TopicItem(string key,bool light)
 {
     Text = key;
     Cursor = System.Windows.Forms.Cursors.Hand;
     Font = new System.Drawing.Font(Helper.FontFang, 23F);
     Size = new System.Drawing.Size(85, 35);
     ForeColor = light?System.Drawing.Color.FromArgb(250, 250, 250):System.Drawing.Color.FromArgb(150, 150, 150);
     BackColor = System.Drawing.Color.Transparent;
     MouseDown += RankItem_MouseDown;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Initializes a new LabelStyle
 /// </summary>
 public LabelStyle()
 {
     _Font = new System.Drawing.Font("Times New Roman", 12f);
     _Offset = new System.Drawing.PointF(0, 0);
     _CollisionDetection = false;
     _CollisionBuffer = new System.Drawing.Size(0, 0);
     _ForeColor = System.Drawing.Color.Black;
     _HorisontalAlignment = HorizontalAlignmentEnum.Center;
     _VerticalAlignment = VerticalAlignmentEnum.Middle;
 }
Exemplo n.º 23
0
		public TreeDialog()
		{
            InitializeComponent();
            var font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
            treOperations.StateNormal.Node.Content.ShortText.Font = font;
            treOperations.StateCommon.Node.Content.ShortText.Font = font;
            treOperations.StateDisabled.Node.Content.ShortText.Font = font;
            treOperations.StatePressed.Node.Content.ShortText.Font = font;
            treOperations.StatePressed.Node.Content.ShortText.Font = font;
			treOperations.ImageList = Icons.IconList;
		}
Exemplo n.º 24
0
 public ShareItemBarBase(string key)
 {
     Text = key;
     Cursor = Helper.HCursors;
     ForeColor = Helper.All["ListNavBar"][0];
     BackColor = Helper.All["ListNavBar"][1];
     Font = new System.Drawing.Font(Helper.FontFang, 18F);
     TextAlign = Helper.Align;
     Dock = System.Windows.Forms.DockStyle.Fill;
     MouseDown += ListNavBarBase_MouseDown;
 }
Exemplo n.º 25
0
 public ILDXSimpleTextRenderer(object device,System.Drawing.Font font) {
     m_isPrepared = false; 
     m_device = (Device)device; 
     if (font != null) {
         m_SysFont = font; 
     } else {
         m_SysFont = new System.Drawing.Font(
             System.Drawing.FontFamily.GenericSansSerif,10.0f);
     }
     m_orientation = TextOrientation.Horizontal; 
 }
Exemplo n.º 26
0
 public static void DrawAdaptiveString(this System.Drawing.Graphics g, string Text, System.Drawing.Font Font, System.Drawing.Brush Brush, System.Drawing.RectangleF Where, System.Drawing.StringFormat Format)
 {
     System.Drawing.Font curFont = (System.Drawing.Font)Font.Clone();
     System.Drawing.SizeF curSize;
     do
     {
         curSize = g.MeasureString(Text, curFont);
         if (curSize.Width > Where.Width || curSize.Height > Where.Height)
             curFont = new System.Drawing.Font(curFont.FontFamily, curFont.Size - 1);
     } while ((curSize.Width > Where.Width || curSize.Height > Where.Height));
     g.DrawString(Text, curFont, Brush, Where, Format);
 }
Exemplo n.º 27
0
 protected override void ProcessRecord()
 {
     using (var g = System.Drawing.Graphics.FromImage(this.Bitmap))
     {
         var color = System.Drawing.Color.FromArgb(this.Color);
         using (var brush = new System.Drawing.SolidBrush(color))
         using (var font = new System.Drawing.Font(this.Font,this.Size))
         {
             g.DrawString(this.Text, font, brush, this.X, this.Y);                    
         }
     }
 }
Exemplo n.º 28
0
 protected Generator()
 {
     InitializeComponent();
     var font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
     tvTemplate.StateNormal.Node.Content.ShortText.Font = font;
     tvTemplate.StateCommon.Node.Content.ShortText.Font = font;
     tvTemplate.StateDisabled.Node.Content.ShortText.Font = font;
     tvTemplate.StatePressed.Node.Content.ShortText.Font = font;
     tvTemplate.StatePressed.Node.Content.ShortText.Font = font;
     lsbTemplate.ListBox.DoubleClick += new EventHandler(ListBox_DoubleClick);
     tvTemplate.Nodes.Add(templateNode);
     UpdateTexts();
 }
Exemplo n.º 29
0
 /// 在图片上增加文字水印
 /// </summary>
 /// <param name="Path">原服务器图片路径</param>
 /// <param name="Path_sy">生成的带文字水印的图片路径</param>
 public void AddWater(string Path, string Path_sy)
 {
     string addText = "ROYcms!NT";
     System.Drawing.Image image = System.Drawing.Image.FromFile(Path);
     System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
     g.DrawImage(image, 0, 0, image.Width, image.Height);
     System.Drawing.Font f = new System.Drawing.Font("Verdana", 60);
     System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
     g.DrawString(addText, f, b, 35, 35);
     g.Dispose();
     image.Save(Path_sy);
     image.Dispose();
 }
        public CustomSearchTextBox() {

            Size = new System.Drawing.Size(150, 25);
            BackColor = System.Drawing.Color.WhiteSmoke;
            BorderStyle = System.Windows.Forms.BorderStyle.None;
            Location = new System.Drawing.Point(5, 10);
            Text = "Keywords";
            Font = new System.Drawing.Font("Arial", 10F);
            Multiline = true;
            ForeColor = System.Drawing.Color.Gray;
            TextAlign = HorizontalAlignment.Left;

        }
        public ActionResult CreatePdf(IFormCollection collection)
        {
            // create a PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // create a page in document
            PdfPage page1 = document.AddPage();

            // set a background color for the page
            PdfRectangle backgroundRectangle = new PdfRectangle(page1.DrawableRectangle);

            backgroundRectangle.BackColor = System.Drawing.Color.WhiteSmoke;
            page1.Layout(backgroundRectangle);

            // create the true type fonts that can be used in document text
            System.Drawing.Font sysFont      = new System.Drawing.Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
            PdfFont             pdfFont      = document.CreateFont(sysFont);
            PdfFont             pdfFontEmbed = document.CreateFont(sysFont, true);

            float crtYPos = 20;
            float crtXPos = 5;

            #region Layout transparent image

            PdfText titleTextTransImage = new PdfText(crtXPos, crtYPos,
                                                      "PNG image with alpha transparency:", pdfFontEmbed);
            titleTextTransImage.ForeColor = System.Drawing.Color.Navy;
            PdfLayoutInfo textLayoutInfo = page1.Layout(titleTextTransImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a PNG image with alpha transparency
            PdfImage      transparentPdfImage = new PdfImage(crtXPos, crtYPos, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            PdfLayoutInfo imageLayoutInfo     = page1.Layout(transparentPdfImage);

            // advance the Y position in the PDF page
            crtYPos += imageLayoutInfo.LastPageRectangle.Height + 10;

            #endregion

            #region Layout resized transparent image

            PdfText titleTextTransImageResized = new PdfText(crtXPos, crtYPos,
                                                             "The transparent PNG image below is resized:", pdfFontEmbed);
            titleTextTransImageResized.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextTransImageResized);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a PNG image with alpha transparency
            PdfImage transparentResizedPdfImage = new PdfImage(crtXPos, crtYPos, 50, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            imageLayoutInfo = page1.Layout(transparentResizedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += imageLayoutInfo.LastPageRectangle.Height + 10;

            #endregion

            #region Layout rotated transparent image

            PdfText titleTextTransImageRotated = new PdfText(crtXPos, crtYPos,
                                                             "The transparent PNG image below is rotated 180 degrees counter clockwise:", pdfFontEmbed);
            titleTextTransImageRotated.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextTransImageRotated);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // rotate the PNG image with alpha transparency 180 degrees counter clockwise
            PdfImage transparentRotatedPdfImage = new PdfImage(0, 0, 50, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            // translate the coordinates system to image location
            transparentRotatedPdfImage.SetTranslation(crtXPos, crtYPos);
            // rotate the coordinates system counter clockwise
            transparentRotatedPdfImage.SetRotationAngle(180);
            // translate back the coordinates system
            transparentRotatedPdfImage.SetTranslation(-50, -50);

            imageLayoutInfo = page1.Layout(transparentRotatedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += 50 + 10;

            #endregion

            #region Layout clipped transparent image

            PdfText titleTextTransClippedImage = new PdfText(crtXPos, crtYPos,
                                                             "The transparent PNG image below is clipped:", pdfFontEmbed);
            titleTextTransClippedImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextTransClippedImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a clipped PNG image with alpha transparency
            PdfImage transparentClippedPdfImage = new PdfImage(crtXPos, crtYPos, 50, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            transparentClippedPdfImage.ClipRectangle = new System.Drawing.RectangleF(crtXPos, crtYPos, 50, 25);

            imageLayoutInfo = page1.Layout(transparentClippedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += transparentClippedPdfImage.ClipRectangle.Height + 10;

            #endregion

            #region Layout JPEG image

            PdfText titleTextOpaqueImage = new PdfText(crtXPos, crtYPos, "The JPG image below is opaque:", pdfFontEmbed);
            titleTextOpaqueImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextOpaqueImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout an opaque JPG image
            PdfImage opaquePdfImage = new PdfImage(crtXPos, crtYPos, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.jpg");

            imageLayoutInfo = page1.Layout(opaquePdfImage);

            // advance the Y position in the PDF page
            crtYPos += imageLayoutInfo.LastPageRectangle.Height + 10;

            #endregion

            #region Layout clipped JPEG image

            PdfText titleTextClippedImage = new PdfText(crtXPos, crtYPos, "The JPG image below is clipped:", pdfFontEmbed);
            titleTextClippedImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextClippedImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a clipped image
            PdfImage clippedPdfImage = new PdfImage(crtXPos, crtYPos, 50, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.jpg");
            clippedPdfImage.ClipRectangle = new System.Drawing.RectangleF(crtXPos, crtYPos, 50, 25);

            imageLayoutInfo = page1.Layout(clippedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += clippedPdfImage.ClipRectangle.Height + 10;

            #endregion

            #region Layout a vectorial SVG image

            PdfText titleTextSvgImage = new PdfText(crtXPos, crtYPos, "Vectorial SVG image:", pdfFontEmbed);
            titleTextSvgImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextSvgImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            string svgImageCode = System.IO.File.ReadAllText(m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Svg\SvgImage.svg");

            PdfHtml       svgImage      = new PdfHtml(crtXPos, crtYPos, svgImageCode, null);
            PdfLayoutInfo svgLayoutInfo = page1.Layout(svgImage);

            // advance the Y position in the PDF page
            crtYPos += svgImage.ConversionInfo.PdfRegions[0].Rectangle.Height + 10;

            #endregion

            #region Layout JPEG image on multiple pages

            PdfText titleTexMultiPageImage = new PdfText(crtXPos, crtYPos, "The JPG image below is laid out on 2 pages:", pdfFontEmbed);
            titleTexMultiPageImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTexMultiPageImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout an opaque JPG image on 2 pages
            PdfImage paginatedPdfImage = new PdfImage(crtXPos, crtYPos, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_big.jpg");

            imageLayoutInfo = page1.Layout(paginatedPdfImage);

            #endregion

            // get the last page
            PdfPage crtPage = document.Pages[imageLayoutInfo.LastPageIndex];
            crtYPos = imageLayoutInfo.LastPageRectangle.Bottom + 10;

            #region Layout the screenshot of a HTML document

            PdfText titleTextHtmlImage = new PdfText(crtXPos, crtYPos, "HTML document screenshot:", pdfFontEmbed);
            titleTextHtmlImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = crtPage.Layout(titleTextHtmlImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            string htmlFile = m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Html\Logo.Html";

            PdfHtmlImage htmlRasterImage = new PdfHtmlImage(crtXPos, crtYPos, htmlFile);
            htmlRasterImage.BrowserWidth = 400;
            PdfLayoutInfo htmlLayoutInfo = crtPage.Layout(htmlRasterImage);

            // advance the Y position in the PDF page
            crtYPos += htmlRasterImage.ConversionInfo.PdfRegions[0].Rectangle.Height + 10;

            #endregion

            try
            {
                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "PdfImages.pdf";

                return(fileResult);
            }
            finally
            {
                document.Close();
            }
        }
Exemplo n.º 32
0
        /// <summary>
        /// 生成校验码图片。
        /// </summary>
        /// <param name="code">验证码文本。</param>
        /// <returns></returns>
        public static System.Drawing.Bitmap GenerateVerifyCodeImage(string code)
        {
            int fSize    = VerifyCode.FontSize;
            int iPadding = VerifyCode.Padding;

            int fWidth      = fSize + iPadding;
            int imageWidth  = code.Length * fWidth + iPadding * 2 + fWidth;
            int imageHeight = fSize * 2 + iPadding;

            System.Drawing.Bitmap image = new System.Drawing.Bitmap(imageWidth, imageHeight);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);

            g.Clear(VerifyCode.BackColor);

            System.Random rand = new System.Random();

            int left, top, top1, top2;

            int n1 = (imageHeight - fSize - iPadding * 2);
            int n2 = n1 / 4;

            top1 = n2;
            top2 = n2 * 2;

            System.Drawing.Font  f;
            System.Drawing.Brush b;

            int cindex, findex;

            #region 随机字体和颜色的验证码字符
            cindex = rand.Next(ForeColors.Length);
            for (int i = 0; i < code.Length; i++)
            {
                findex = rand.Next(Fonts.Length);

                f = new System.Drawing.Font(Fonts[findex], fSize, System.Drawing.FontStyle.Bold);
                b = new System.Drawing.SolidBrush(ForeColors[cindex]);

                if (i % 2 == 1)
                {
                    top = top2;
                }
                else
                {
                    top = top1;
                }

                left = i * fWidth;

                g.DrawString(code.Substring(i, 1), f, b, left, top);
            }
            #endregion

            //#region 给背景添加随机生成的燥点
            //if (VerifyCode.HasPinto && VerifyCode.Pinto > 0)
            //{

            //    //System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.LightGray, 0);
            //    System.Drawing.Pen pen = new System.Drawing.Pen(VerifyCode.BackColor, 0);
            //    int c = System.Convert.ToInt32(image.Width * image.Height * VerifyCode.Pinto);

            //    for (int i = 0; i < c; i++)
            //    {
            //        int x = rand.Next(image.Width);
            //        int y = rand.Next(image.Height);

            //        g.DrawRectangle(pen, x, y, 1, 1);
            //    }
            //}
            //#endregion

            //画一个边框 边框颜色为Color.Gainsboro
            //g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Gainsboro, 0), 0, 0, image.Width - 1, image.Height - 1);
            g.Dispose();

            //产生波形
            if (VerifyCode.BendingAngle != 0)
            {
                image = VerifyCode.TwistImage(image, VerifyCode.BackColor, true, VerifyCode.BendingAngle, 4);
            }
            DrawCurve(image, VerifyCode.ForeColors[rand.Next(0, VerifyCode.ForeColors.Length)]);
            return(image);
        }
Exemplo n.º 33
0
        private static Size TextSize(int num, System.Drawing.Font font)
        {
            var sampleText = Enumerable.Repeat("9", num).Aggregate((total, next) => total + next);

            return(TextSize(sampleText, font));
        }
Exemplo n.º 34
0
        private void InitializeComponent()
        {
            var resources = new System.ComponentModel.ComponentResourceManager(typeof(WinFormConfigurationDialog));

            this.picLogo          = new System.Windows.Forms.PictureBox();
            this.grpVideoOptions  = new System.Windows.Forms.GroupBox();
            this.lblOption        = new System.Windows.Forms.Label();
            this.cboOptionValues  = new System.Windows.Forms.ComboBox();
            this.lstOptions       = new System.Windows.Forms.ListBox();
            this.lblRenderer      = new System.Windows.Forms.Label();
            this.cboRenderSystems = new System.Windows.Forms.ComboBox();
            this.cmdCancel        = new System.Windows.Forms.Button();
            this.cmdOk            = new System.Windows.Forms.Button();
            this.pnlBackground    = new System.Windows.Forms.Panel();
            ((System.ComponentModel.ISupportInitialize)(this.picLogo)).BeginInit();
            this.grpVideoOptions.SuspendLayout();
            SuspendLayout();
            //
            // picLogo
            //
            this.picLogo.BackColor = System.Drawing.Color.White;
            this.picLogo.Image     = global::Axiom.Framework.Properties.Resources.AxiomLogo;
            this.picLogo.Location  = new System.Drawing.Point(12, 3);
            this.picLogo.Name      = "picLogo";
            this.picLogo.Size      = new System.Drawing.Size(420, 174);
            this.picLogo.SizeMode  = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.picLogo.TabIndex  = 3;
            this.picLogo.TabStop   = false;
            //
            // grpVideoOptions
            //
            this.grpVideoOptions.Controls.Add(this.lblOption);
            this.grpVideoOptions.Controls.Add(this.cboOptionValues);
            this.grpVideoOptions.Controls.Add(this.lstOptions);
            this.grpVideoOptions.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.grpVideoOptions.Font      = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular,
                                                                     System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.grpVideoOptions.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(25)))),
                                                                           ((int)(((byte)(35)))),
                                                                           ((int)(((byte)(75)))));
            this.grpVideoOptions.Location = new System.Drawing.Point(12, 215);
            this.grpVideoOptions.Name     = "grpVideoOptions";
            this.grpVideoOptions.Size     = new System.Drawing.Size(420, 187);
            this.grpVideoOptions.TabIndex = 6;
            this.grpVideoOptions.TabStop  = false;
            this.grpVideoOptions.Text     = "Rendering System Options";
            //
            // lblOption
            //
            this.lblOption.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.lblOption.Font      = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular,
                                                               System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblOption.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(25)))),
                                                                     ((int)(((byte)(35)))),
                                                                     ((int)(((byte)(75)))));
            this.lblOption.Location  = new System.Drawing.Point(32, 153);
            this.lblOption.Name      = "lblOption";
            this.lblOption.Size      = new System.Drawing.Size(200, 22);
            this.lblOption.TabIndex  = 9;
            this.lblOption.Text      = "Option Name:";
            this.lblOption.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.lblOption.Visible   = false;
            //
            // cboOptionValues
            //
            this.cboOptionValues.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboOptionValues.Font          = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular,
                                                                         System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cboOptionValues.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(25)))),
                                                                           ((int)(((byte)(35)))),
                                                                           ((int)(((byte)(75)))));
            this.cboOptionValues.Location              = new System.Drawing.Point(238, 158);
            this.cboOptionValues.Name                  = "cboOptionValues";
            this.cboOptionValues.Size                  = new System.Drawing.Size(176, 22);
            this.cboOptionValues.TabIndex              = 8;
            this.cboOptionValues.Visible               = false;
            this.cboOptionValues.SelectedIndexChanged += new System.EventHandler(cboOptionValues_SelectedIndexChanged);
            //
            // lstOptions
            //
            this.lstOptions.ItemHeight            = 14;
            this.lstOptions.Location              = new System.Drawing.Point(7, 22);
            this.lstOptions.Name                  = "lstOptions";
            this.lstOptions.Size                  = new System.Drawing.Size(407, 130);
            this.lstOptions.TabIndex              = 0;
            this.lstOptions.SelectedIndexChanged += new System.EventHandler(lstOptions_SelectedIndexChanged);
            //
            // lblRenderer
            //
            this.lblRenderer.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.lblRenderer.Font      = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular,
                                                                 System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblRenderer.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(25)))),
                                                                       ((int)(((byte)(35)))),
                                                                       ((int)(((byte)(75)))));
            this.lblRenderer.Location  = new System.Drawing.Point(10, 185);
            this.lblRenderer.Name      = "lblRenderer";
            this.lblRenderer.Size      = new System.Drawing.Size(128, 24);
            this.lblRenderer.TabIndex  = 9;
            this.lblRenderer.Text      = "Rendering Subsystem:";
            this.lblRenderer.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            //
            // cboRenderSystems
            //
            this.cboRenderSystems.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboRenderSystems.Font          = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular,
                                                                          System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cboRenderSystems.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(25)))),
                                                                            ((int)(((byte)(35)))),
                                                                            ((int)(((byte)(75)))));
            this.cboRenderSystems.Location              = new System.Drawing.Point(145, 185);
            this.cboRenderSystems.Name                  = "cboRenderSystems";
            this.cboRenderSystems.Size                  = new System.Drawing.Size(285, 22);
            this.cboRenderSystems.TabIndex              = 8;
            this.cboRenderSystems.SelectedIndexChanged += new System.EventHandler(RenderSystems_SelectedIndexChanged);
            //
            // cmdCancel
            //
            this.cmdCancel.Anchor       = System.Windows.Forms.AnchorStyles.Bottom;
            this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.cmdCancel.Location     = new System.Drawing.Point(355, 408);
            this.cmdCancel.Name         = "cmdCancel";
            this.cmdCancel.Size         = new System.Drawing.Size(75, 23);
            this.cmdCancel.TabIndex     = 10;
            this.cmdCancel.Text         = "Cancel";
            this.cmdCancel.Click       += new System.EventHandler(cmdCancel_Click);
            //
            // cmdOk
            //
            this.cmdOk.Anchor       = System.Windows.Forms.AnchorStyles.Bottom;
            this.cmdOk.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.cmdOk.Location     = new System.Drawing.Point(261, 408);
            this.cmdOk.Name         = "cmdOk";
            this.cmdOk.Size         = new System.Drawing.Size(75, 23);
            this.cmdOk.TabIndex     = 11;
            this.cmdOk.Text         = "Ok";
            this.cmdOk.Click       += new System.EventHandler(cmdOk_Click);
            //
            // pnlBackground
            //
            this.pnlBackground.BackColor = System.Drawing.Color.White;
            this.pnlBackground.Location  = new System.Drawing.Point(-2, 3);
            this.pnlBackground.Name      = "pnlBackground";
            this.pnlBackground.Size      = new System.Drawing.Size(446, 174);
            this.pnlBackground.TabIndex  = 12;
            //
            // WinFormConfigurationDialog
            //
            //SWF.Application.AddMessageFilter( this );
            ClientSize = new System.Drawing.Size(442, 436);
            ControlBox = false;
            Controls.Add(this.cmdOk);
            Controls.Add(this.cmdCancel);
            Controls.Add(this.lblRenderer);
            Controls.Add(this.grpVideoOptions);
            Controls.Add(this.cboRenderSystems);
            Controls.Add(this.picLogo);
            Controls.Add(this.pnlBackground);
            Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
                                           ((byte)(0)));
            FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            MaximizeBox     = false;
            MinimizeBox     = false;
            Name            = "WinFormConfigurationDialog";
            StartPosition   = System.Windows.Forms.FormStartPosition.CenterScreen;
            Text            = "Axiom Rendering Engine Setup";
            Load           += new System.EventHandler(WinFormConfigurationDialog_Load);
            ((System.ComponentModel.ISupportInitialize)(this.picLogo)).EndInit();
            this.grpVideoOptions.ResumeLayout(false);
            ResumeLayout(false);
        }
Exemplo n.º 35
0
        private static double GetWidth(System.Drawing.Font stringFont, string text)
        {
            var textSize = TextRenderer.MeasureText(text, stringFont);

            return((double)decimal.Round(textSize.Width / 7m + 1, 2));
        }
Exemplo n.º 36
0
 internal TextHandle(string text, System.Drawing.Font font)
 {
     Text     = text;
     GdiPFont = font;
 }
 private void InitializeComponent()
 {
     panelbody     = new System.Windows.Forms.Panel();
     tlpBody       = new System.Windows.Forms.TableLayoutPanel();
     messageLabel  = new System.Windows.Forms.Label();
     titleLabel    = new System.Windows.Forms.Label();
     pnlBottom     = new System.Windows.Forms.Panel();
     poisonButton2 = new ReaLTaiizor.Controls.PoisonButton();
     poisonButton1 = new ReaLTaiizor.Controls.PoisonButton();
     poisonButton3 = new ReaLTaiizor.Controls.PoisonButton();
     panelbody.SuspendLayout();
     tlpBody.SuspendLayout();
     pnlBottom.SuspendLayout();
     SuspendLayout();
     //
     // panelbody
     //
     panelbody.BackColor = System.Drawing.Color.DarkGray;
     panelbody.Controls.Add(tlpBody);
     panelbody.Dock     = System.Windows.Forms.DockStyle.Fill;
     panelbody.Location = new System.Drawing.Point(0, 0);
     panelbody.Margin   = new System.Windows.Forms.Padding(0);
     panelbody.Name     = "panelbody";
     panelbody.Size     = new System.Drawing.Size(804, 211);
     panelbody.TabIndex = 2;
     //
     // tlpBody
     //
     tlpBody.ColumnCount = 3;
     tlpBody.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
     tlpBody.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 80F));
     tlpBody.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
     tlpBody.Controls.Add(messageLabel, 1, 2);
     tlpBody.Controls.Add(titleLabel, 1, 1);
     tlpBody.Controls.Add(pnlBottom, 1, 3);
     tlpBody.Dock     = System.Windows.Forms.DockStyle.Fill;
     tlpBody.Location = new System.Drawing.Point(0, 0);
     tlpBody.Name     = "tlpBody";
     tlpBody.RowCount = 4;
     tlpBody.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 5F));
     tlpBody.RowStyles.Add(new System.Windows.Forms.RowStyle());
     tlpBody.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
     tlpBody.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F));
     tlpBody.Size     = new System.Drawing.Size(804, 211);
     tlpBody.TabIndex = 6;
     //
     // messageLabel
     //
     messageLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                  | System.Windows.Forms.AnchorStyles.Left)
                                                                 | System.Windows.Forms.AnchorStyles.Right)));
     messageLabel.BackColor = System.Drawing.Color.Transparent;
     messageLabel.ForeColor = System.Drawing.Color.White;
     messageLabel.Location  = new System.Drawing.Point(83, 37);
     messageLabel.Margin    = new System.Windows.Forms.Padding(3, 0, 0, 0);
     messageLabel.Name      = "messageLabel";
     messageLabel.Size      = new System.Drawing.Size(640, 134);
     messageLabel.TabIndex  = 0;
     messageLabel.Text      = "message here";
     //
     // titleLabel
     //
     titleLabel.AutoSize  = true;
     titleLabel.BackColor = System.Drawing.Color.Transparent;
     titleLabel.Font      = new System.Drawing.Font("Segoe UI Semibold", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     titleLabel.ForeColor = System.Drawing.Color.WhiteSmoke;
     titleLabel.Location  = new System.Drawing.Point(80, 5);
     titleLabel.Margin    = new System.Windows.Forms.Padding(0);
     titleLabel.Name      = "titleLabel";
     titleLabel.Size      = new System.Drawing.Size(159, 32);
     titleLabel.TabIndex  = 1;
     titleLabel.Text      = "message title";
     //
     // pnlBottom
     //
     pnlBottom.BackColor = System.Drawing.Color.Transparent;
     pnlBottom.Controls.Add(poisonButton2);
     pnlBottom.Controls.Add(poisonButton1);
     pnlBottom.Controls.Add(poisonButton3);
     pnlBottom.Dock     = System.Windows.Forms.DockStyle.Fill;
     pnlBottom.Location = new System.Drawing.Point(80, 171);
     pnlBottom.Margin   = new System.Windows.Forms.Padding(0);
     pnlBottom.Name     = "pnlBottom";
     pnlBottom.Size     = new System.Drawing.Size(643, 40);
     pnlBottom.TabIndex = 2;
     //
     // poisonButton2
     //
     poisonButton2.Anchor        = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     poisonButton2.FontWeight    = Extension.Poison.PoisonButtonWeight.Regular;
     poisonButton2.Location      = new System.Drawing.Point(455, 1);
     poisonButton2.Name          = "poisonButton2";
     poisonButton2.Size          = new System.Drawing.Size(90, 26);
     poisonButton2.TabIndex      = 4;
     poisonButton2.Text          = "button 2";
     poisonButton2.UseSelectable = true;
     //
     // poisonButton1
     //
     poisonButton1.Anchor                  = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     poisonButton1.BackColor               = System.Drawing.Color.ForestGreen;
     poisonButton1.FontWeight              = Extension.Poison.PoisonButtonWeight.Regular;
     poisonButton1.Location                = new System.Drawing.Point(357, 1);
     poisonButton1.Name                    = "poisonButton1";
     poisonButton1.Size                    = new System.Drawing.Size(90, 26);
     poisonButton1.TabIndex                = 3;
     poisonButton1.Text                    = "button 1";
     poisonButton1.UseSelectable           = true;
     poisonButton1.UseVisualStyleBackColor = false;
     //
     // poisonButton3
     //
     poisonButton3.Anchor        = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     poisonButton3.FontWeight    = Extension.Poison.PoisonButtonWeight.Regular;
     poisonButton3.Location      = new System.Drawing.Point(553, 1);
     poisonButton3.Name          = "poisonButton3";
     poisonButton3.Size          = new System.Drawing.Size(90, 26);
     poisonButton3.TabIndex      = 5;
     poisonButton3.Text          = "button 3";
     poisonButton3.UseSelectable = true;
     //
     // PoisonMessageBoxControl
     //
     AutoScaleDimensions = new System.Drawing.SizeF(10F, 28F);
     AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
     ClientSize          = new System.Drawing.Size(804, 211);
     ControlBox          = false;
     Controls.Add(panelbody);
     Font            = new System.Drawing.Font("Segoe UI Light", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
     Margin          = new System.Windows.Forms.Padding(4, 5, 4, 5);
     Name            = "PoisonMessageBoxControl";
     StartPosition   = System.Windows.Forms.FormStartPosition.Manual;
     panelbody.ResumeLayout(false);
     tlpBody.ResumeLayout(false);
     tlpBody.PerformLayout();
     pnlBottom.ResumeLayout(false);
     ResumeLayout(false);
 }
Exemplo n.º 38
0
        /// <summary>
        /// Create the font image using GDI+ functionality.
        /// </summary>
        void CreateGdiFontImage(XFont font, XPdfFontOptions options /*, XPrivateFontCollection privateFontCollection*/)
        {
            System.Drawing.Font   gdiFont = font.RealizeGdiFont();
            NativeMethods.LOGFONT logFont;
#if DEBUG_
            logFont = new NativeMethods.LOGFONT();
            gdiFont.ToLogFont(logFont);
            Debug.WriteLine("FontData: " + logFont.lfFaceName);
#endif
            this.data = null;

            // PFC
            //if (privateFontCollection != null)
            //{
            //  //XPrivateFont privateFont = privateFontCollection.FindFont(logFont.lfFaceName, logFont.lfWeight >= 700, logFont.lfItalic > 0);
            //  XGlyphTypeface privateFont = privateFontCollection.FindFont(font.Name, font.Bold, font.Italic);
            //  if (privateFont != null)
            //  {
            //    //////int size = privateFont.GetData(ref this.data);
            //    //////if (size > 0)
            //    //////{
            //    //////  this.data = new byte[size];
            //    //////  privateFont.GetData(ref this.data, size);
            //    //////}
            //  }
            //}
            if (this.data == null)
            {
                int    error;
                IntPtr hfont = gdiFont.ToHfont();
                IntPtr hdc   = NativeMethods.GetDC(IntPtr.Zero);
                error = Marshal.GetLastWin32Error();
                IntPtr oldFont = NativeMethods.SelectObject(hdc, hfont);
                error = Marshal.GetLastWin32Error();
                // size is exactly the size of the font file.
                int size = NativeMethods.GetFontData(hdc, 0, 0, null, 0);
                error = Marshal.GetLastWin32Error();
                if (size > 0)
                {
                    this.data = new byte[size];
                    int effectiveSize = NativeMethods.GetFontData(hdc, 0, 0, this.data, this.data.Length);
                    Debug.Assert(size == effectiveSize);
                    NativeMethods.SelectObject(hdc, oldFont);
                    NativeMethods.ReleaseDC(IntPtr.Zero, hdc);
                    error.GetType();
                }
                else
                {
                    // Sometimes size is -1 (GDI_ERROR), but I cannot determine why. It happens only with the font 'Symbol'.
                    // The issue occurs the first time in early 2005, when I start writing PDFsharp. I could not fix it and after
                    // some code refactoring the problem disappears.
                    // There was never a report from anyone about this issue.
                    // Now I get it again (while debugging QBX 2006). Maybe it is a problem with my PC at my home office.
                    // As a work-around I create a new font handle with a different height value. This works. Maybe the
                    // font file gets locked somewhere. Very very strange.

                    // IF SOMEONE ELSE COMES HERE PLEASE LET ME KNOW!

                    // Clean up old handles
                    NativeMethods.SelectObject(hdc, oldFont);
                    NativeMethods.ReleaseDC(IntPtr.Zero, hdc);

                    // Try again with new font handle
                    logFont = new NativeMethods.LOGFONT();
                    gdiFont.ToLogFont(logFont);
                    logFont.lfHeight += 1; // force new handle
                    IntPtr hfont2 = NativeMethods.CreateFontIndirect(logFont);
                    hdc     = NativeMethods.GetDC(IntPtr.Zero);
                    error   = Marshal.GetLastWin32Error();
                    oldFont = NativeMethods.SelectObject(hdc, hfont2);
                    error   = Marshal.GetLastWin32Error();
                    // size is exactly the size of the font file.
                    size  = NativeMethods.GetFontData(hdc, 0, 0, null, 0);
                    error = Marshal.GetLastWin32Error();
                    if (size > 0)
                    {
                        this.data = new byte[size];
                        int effectiveSize = NativeMethods.GetFontData(hdc, 0, 0, this.data, this.data.Length);
                        Debug.Assert(size == effectiveSize);
                    }
                    NativeMethods.SelectObject(hdc, oldFont);
                    NativeMethods.ReleaseDC(IntPtr.Zero, hdc);
                    NativeMethods.DeleteObject(hfont2);
                    error.GetType();
                }
            }
            if (this.data == null)
            {
                throw new InvalidOperationException("Internal error. Font data could not retrieved.");
            }
        }
        internal ExcelPackage GenerateExcelFieldplan(ProtocolTransfer trans, ExcelPackage pack)
        {
            ExcelWorksheet ws         = pack.Workbook.Worksheets.Add(title);
            int            cols       = 0;
            int            rowcounter = 1;

            ws.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
            for (int i = 0; i < trans.dominoes.Length; i++) // foreach row
            {
                if (trans.dominoes[i] == null)
                {
                    throw new InvalidOperationException("Object not valid!");
                }
                int        cellcounter = 1;
                ExcelRange cell1       = ws.Cells[++rowcounter, cellcounter++];
                cell1.Value = ((trans.orientation == Orientation.Horizontal) ? "Row" : "Column") + " " + (i + 1);
                cell1.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                cell1.Style.Border.Bottom.Color.SetColor(System.Drawing.Color.Black);
                for (int j = 0; j < trans.dominoes[i].Count; j++) // foreach block
                {
                    if (trans.dominoes[i][j] == null)
                    {
                        throw new InvalidOperationException("Field not valid!");
                    }
                    for (int k = 0; k < trans.dominoes[i][j].Count; k++)
                    {
                        if (trans.dominoes[i][j][k] != null && trans.dominoes[i][j][k].Item1 >= 0) // for all non-empty dominoes
                        {
                            using (ExcelRange cell = ws.Cells[rowcounter, cellcounter++])
                            {
                                cell.Style.Border.BorderAround(ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                                Color b = Colors.Black;
                                switch (backColorMode)
                                {
                                case ColorMode.Normal: b = trans.colors[trans.dominoes[i][j][k].Item1].mediaColor; break;            // normal color

                                case ColorMode.Inverted: b = trans.colors[trans.dominoes[i][j][k].Item1].mediaColor.Invert(); break; // inverted color

                                case ColorMode.Fixed: b = fixedBackColor; break;                                                     // fixed
                                }
                                if ((trans.colors[trans.dominoes[i][j][k].Item1] is EmptyDomino))
                                {
                                    cell.Style.Fill.PatternType = ExcelFillStyle.DarkUp;
                                    cell.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.White);
                                    cell.Style.Fill.PatternColor.SetColor(System.Drawing.Color.Black);
                                }
                                else
                                {
                                    cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
                                }
                                var background = b.ToSD(true);
                                cell.Style.Fill.BackgroundColor.SetColor(background);

                                if (k == trans.dominoes[i][j].Count - 1) // if end of block, draw right border in intelligent black/white
                                {
                                    System.Drawing.Color border = trans.colors[trans.dominoes[i][j][k].Item1].mediaColor.IntelligentBW().ToSD();
                                    cell.Style.Border.Right.Style = ExcelBorderStyle.Thick;
                                    cell.Style.Border.Right.Color.SetColor(border);
                                }
                                Color f = Colors.Black;
                                switch (foreColorMode)
                                {
                                case ColorMode.Normal: f = trans.colors[trans.dominoes[i][j][k].Item1].mediaColor; break;            // normal color

                                case ColorMode.Inverted: f = trans.colors[trans.dominoes[i][j][k].Item1].mediaColor.Invert(); break; // inverted color

                                case ColorMode.Intelligent: f = b.IntelligentBW(); break;                                            // intelligent BW
                                }
                                cell.Style.Font.Color.SetColor(f.ToSD());


                                string parsed = ParseFormatString(trans.colors[trans.dominoes[i][j][k].Item1].name, trans.dominoes[i][j][k].Item2);
                                // Bugfix für Warnung "Zahl als Text" in Excel
                                if (parsed.Trim().All(char.IsDigit))
                                {
                                    cell.Value = Int32.Parse(parsed);
                                }
                                else
                                {
                                    cell.Value = parsed;
                                }
                            }
                        }
                    }
                }
                if (cellcounter > cols)
                {
                    cols = cellcounter;
                }
            }
            // those two assignments are needed for whatever reason (see http://stackoverflow.com/questions/38860557/strange-behavior-in-autofitcolumns-using-epplus)
            ws.Cells[1, 1].Value = "a";
            ws.Cells[1, 2].Value = "b";
            // apply font scheme to all cells
            System.Drawing.Font textFont = StringToFont(textFormat);
            if (textFont != null)
            {
                ws.Cells[1, 1, rowcounter, cols].Style.Font.SetFromFont(StringToFont(textFormat));
            }
            // resize cell
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                ws.Cells.AutoFitColumns(0);
            }
            // add title
            ws.Cells[1, 2].Clear();
            ws.Cells[1, 1].Value                   = title;
            ws.Cells[1, 1].Style.Font.Size         = 15;
            ws.Cells[1, 1].Style.VerticalAlignment = ExcelVerticalAlignment.Top;
            ws.Row(1).Height = 27;
            // add small summary
            if (summaryMode != SummaryMode.None)
            {
                ExcelRange cell1 = ws.Cells[rowcounter + 2, 1];
                cell1.Value = "Rows: " + trans.rows + ", Columns: " + trans.columns;
                ws.Cells[rowcounter + 3, 1].Value = "Total Number of dominoes: " + trans.counts.Sum();
                if (textFont != null)
                {
                    ws.Cells[rowcounter + 2, 1, rowcounter + 3, 1].Style.Font.SetFromFont(textFont);
                }
            }
            rowcounter += 4;
            // set footer
            ws.HeaderFooter.FirstFooter.CenteredText     = string.Format("Page {0} of {1}", ExcelHeaderFooter.PageNumber, ExcelHeaderFooter.NumberOfPages);
            ws.HeaderFooter.EvenFooter.CenteredText      = string.Format("Page {0} of {1}", ExcelHeaderFooter.PageNumber, ExcelHeaderFooter.NumberOfPages);
            ws.HeaderFooter.OddFooter.CenteredText       = string.Format("Page {0} of {1}", ExcelHeaderFooter.PageNumber, ExcelHeaderFooter.NumberOfPages);
            ws.HeaderFooter.OddHeader.RightAlignedText   = DateTime.Today.ToShortDateString();
            ws.HeaderFooter.EvenHeader.RightAlignedText  = DateTime.Today.ToShortDateString();
            ws.HeaderFooter.FirstHeader.LeftAlignedText  = "Project: " + project;
            ws.HeaderFooter.OddHeader.LeftAlignedText    = title;
            ws.HeaderFooter.EvenHeader.LeftAlignedText   = title;
            ws.HeaderFooter.FirstHeader.RightAlignedText = "Go to View -> Page Break Preview for page overview";
            ws.HeaderFooter.OddHeader.CenteredText       = "Project: " + project;
            ws.HeaderFooter.EvenHeader.CenteredText      = "Project: " + project;
            ws.PrinterSettings.TopMargin    = (decimal)0.5;
            ws.PrinterSettings.LeftMargin   = (decimal)0.4;
            ws.PrinterSettings.RightMargin  = (decimal)0.4;
            ws.PrinterSettings.BottomMargin = (decimal)0.5;
            ws.PrinterSettings.HeaderMargin = (decimal)0.2;
            ws.PrinterSettings.FooterMargin = (decimal)0.2;
            if (summaryMode == SummaryMode.Large)
            {
                var orderedList = OrderedColorBalance(trans);
                // The list is first stored to a new workbook to get the minimum size of each column.
                ExcelWorksheet summary = pack.Workbook.Worksheets.Add("Summary");
                summary.Cells[1, 1].Value = " ";
                summary.Cells[1, 2].Value = "Color";
                summary.Cells[1, 3].Value = "Total";
                summary.Cells[1, 4].Value = "Used";
                int non_empty_cols = 0;
                for (int i = 0; i < orderedList.Count; i++)
                {
                    if (orderedList[i].count != 0)
                    {
                        summary.Cells[i + 2, 2].Value = orderedList[i].color.name;
                        if (orderedList[i].color is DominoColor)
                        {
                            summary.Cells[i + 2, 3].Value = orderedList[i].color.count;
                        }
                        summary.Cells[i + 2, 4].Value = orderedList[i].count;
                        non_empty_cols++;
                    }
                }
                if (textFont != null)
                {
                    summary.Cells[1, 1, trans.counts.Length, 4].Style.Font.SetFromFont(textFont);
                }
                if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    summary.Cells.AutoFitColumns(0);
                }

                double[] widths = new double[] { summary.Column(1).Width, summary.Column(2).Width, summary.Column(3).Width, summary.Column(4).Width };
                // the sheet is not needed anymore
                pack.Workbook.Worksheets.Delete(summary);

                ws.Cells[rowcounter + 1, 1].Value = "Overview of used dominoes:";
                int[] indices = new int[3]; // fist item: end index of name column,...
                for (int i = 0; i < 3; i++)
                {
                    int    endindex = (i == 0) ? 2 : indices[i - 1] + 1;
                    double width    = ws.Column(endindex).Width;
                    while (width < widths[i + 1])
                    {
                        endindex++;
                        width += ws.Column(endindex).Width;
                    }
                    indices[i] = endindex;
                }
                if (textFont != null)
                {
                    ws.Cells[rowcounter + 1, 1].Style.Font.SetFromFont(textFont);
                }
                rowcounter += 2;
                using (ExcelRange Color_Header = ws.Cells[rowcounter, 2, rowcounter, indices[0]])
                {
                    Color_Header.Merge = true;
                    Color_Header.Value = "Color";
                    if (textFont != null)
                    {
                        Color_Header.Style.Font.SetFromFont(textFont);
                    }
                    SetAllBorders(Color_Header, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                    Color_Header.Style.Border.Bottom.Style = ExcelBorderStyle.Thick;
                }
                using (ExcelRange Count_Header = ws.Cells[rowcounter, indices[0] + 1, rowcounter, indices[1]])
                {
                    Count_Header.Merge = true;
                    Count_Header.Value = "Count";
                    if (textFont != null)
                    {
                        Count_Header.Style.Font.SetFromFont(textFont);
                    }
                    SetAllBorders(Count_Header, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                    Count_Header.Style.Border.Bottom.Style = ExcelBorderStyle.Thick;
                }
                using (ExcelRange Used_Header = ws.Cells[rowcounter, indices[1] + 1, rowcounter, indices[2]])
                {
                    Used_Header.Merge = true;
                    Used_Header.Value = "Used";
                    if (textFont != null)
                    {
                        Used_Header.Style.Font.SetFromFont(textFont);
                    }
                    SetAllBorders(Used_Header, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                    Used_Header.Style.Border.Bottom.Style = ExcelBorderStyle.Thick;
                }
                for (int i = 0; i < orderedList.Count; i++)
                {
                    if (orderedList[i].count != 0)
                    {
                        rowcounter++;
                        using (ExcelRange color_cell = ws.Cells[rowcounter, 1])
                        {
                            color_cell.Value = " ";
                            color_cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
                            color_cell.Style.Fill.BackgroundColor.SetColor(orderedList[i].color.mediaColor.ToSD());
                            SetAllBorders(color_cell, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                        }
                        using (ExcelRange name_cell = ws.Cells[rowcounter, 2, rowcounter, indices[0]])
                        {
                            name_cell.Merge = true;
                            name_cell.Value = orderedList[i].color.name;
                            SetAllBorders(name_cell, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                            if (textFont != null)
                            {
                                name_cell.Style.Font.SetFromFont(textFont);
                            }
                        }
                        using (ExcelRange count_cell = ws.Cells[rowcounter, indices[0] + 1, rowcounter, indices[1]])
                        {
                            count_cell.Merge = true;
                            if (orderedList[i].color is DominoColor)
                            {
                                count_cell.Value = orderedList[i].color.count;
                            }
                            SetAllBorders(count_cell, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                            if (textFont != null)
                            {
                                count_cell.Style.Font.SetFromFont(textFont);
                            }
                        }
                        using (ExcelRange used_cell = ws.Cells[rowcounter, indices[1] + 1, rowcounter, indices[2]])
                        {
                            used_cell.Merge = true;
                            used_cell.Value = orderedList[i].count;
                            SetAllBorders(used_cell, ExcelBorderStyle.Thin, System.Drawing.Color.Black);
                            if (textFont != null)
                            {
                                used_cell.Style.Font.SetFromFont(textFont);
                            }
                        }
                    }
                }
                ws.Cells[rowcounter + 1, 1, rowcounter + non_empty_cols + 1, indices[2]].Style.Font.SetFromFont(StringToFont(textFormat));
            }

            return(pack);
        }
Exemplo n.º 40
0
 public override void SetMarkeeFont(System.Drawing.Font font)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 41
0
        /// <summary>
        /// Adds sheet to workbook
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="spreadsheetDocument"></param>
        /// <param name="sheetName"></param>
        /// <param name="headerCellFormatIndex"></param>
        /// <param name="cellCellFormatIndex"></param>
        private static void AddSheet(DataTable dt, SpreadsheetDocument spreadsheetDocument, string sheetName, uint headerCellFormatIndex, uint cellCellFormatIndex)
        {
            if (dt.Rows.Count < 500)
            {
                ////TODO: If records exists less than 500, then add blank rows upto 500th position and format
                for (var intRowPos = dt.Rows.Count; intRowPos < 500; intRowPos++)
                {
                    var blankDataRow = dt.NewRow();
                    dt.Rows.InsertAt(blankDataRow, intRowPos);
                }
            }

            // Add a blank WorksheetPart.
            var worksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart <WorksheetPart>();
            var worksheet     = new Worksheet();
            var sheetData     = new SheetData();

            const uint headerRowIndex = 1;
            var        headerRow      = new Row {
                RowIndex = headerRowIndex
            };

            sheetData.AppendChild(headerRow);

            var columns = new List <ExcelColumn>();

            using (var headerFont = new System.Drawing.Font(PrintFormatting.ExcelHeaderFont, Convert.ToInt32(PrintFormatting.ExcelCellFontSize), System.Drawing.FontStyle.Bold))
            {
                for (var i = 0; i < dt.Columns.Count; i++)
                {
                    var excelColumnName = GetExcelColumnName(i);
                    var columnName      = dt.Columns[i].ColumnName;
                    AppendCell(excelColumnName, columnName, headerRow, headerRowIndex, headerCellFormatIndex);
                    columns.Add(new ExcelColumn
                    {
                        ColumnName      = columnName,
                        ExcelColumnName = excelColumnName,
                        Index           = (uint)i + 1,
                        Width           = GetWidth(headerFont, columnName)
                    });
                }
            }

            using (var cellFont = new System.Drawing.Font(PrintFormatting.ExcelCellFont, Convert.ToInt32(PrintFormatting.ExcelCellFontSize)))
            {
                uint rowIndex = 2;
                foreach (DataRow dr in dt.Rows)
                {
                    var row = new Row {
                        RowIndex = rowIndex
                    };
                    sheetData.AppendChild(row);
                    foreach (var col in columns)
                    {
                        var value = Convert.ToString(dr[col.ColumnName]);
                        AppendCell(col.ExcelColumnName, value, row, rowIndex, cellCellFormatIndex);

                        if (String.IsNullOrWhiteSpace(value))
                        {
                            continue;
                        }

                        var width = GetWidth(cellFont, value);
                        if (width > col.Width)
                        {
                            col.Width = width;
                        }
                    }

                    rowIndex += 1;
                }
            }

            var excelColumns = new Columns();

            foreach (var col in columns)
            {
                var c = new Column();
                c.Min         = col.Index;
                c.Max         = col.Index;
                c.Width       = col.Width;
                c.CustomWidth = true;
                c.BestFit     = true;
                excelColumns.Append(c);
            }

            worksheet.Append(excelColumns);

            worksheet.Append(sheetData);
            worksheetPart.Worksheet = worksheet;
            worksheetPart.Worksheet.Save();

            var sheets         = spreadsheetDocument.WorkbookPart.Workbook.GetFirstChild <Sheets>();
            var relationshipId = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart);
            // Get a unique ID for the new worksheet.
            uint sheetId = 1;

            if (sheets.Elements <Sheet>().Any())
            {
                sheetId = sheets.Elements <Sheet>().Select(s => s.SheetId.Value).Max() + 1;
            }

            // Append the new worksheet and associate it with the workbook.

            var sheet = new Sheet
            {
                Id      = relationshipId,
                SheetId = sheetId,
                Name    = sheetName
            };

            sheets.AppendChild(sheet);
        }
Exemplo n.º 42
0
        public override void Render(RdlRender.Container box)
        {
            if (box != null)
            {
                string text;
                try
                {
                    text = _vaue.ExecAsString((Style == null)?"":Style.Format);
                }
                catch (Exception err)
                {
                    throw new Exception("Error evaluating expression in TextBox " + _name, err);
                }
                bool hidden = false;

                if (_hideDuplicates != null)
                {
                    int gi = Context.FindContextByGroupName(_hideDuplicates).GroupIndex;
                    if (text == _lastValue)
                    {
                        if (gi == _lastGroupIndex)
                        {
                            hidden = true;
                        }
                    }
                    _lastGroupIndex = gi;
                }

                if (!hidden)
                {
                    decimal width  = (IsInCell || _width == null) ? box.Width : _width.points;
                    decimal height = (IsInCell) ? box.Height : _height.points;

                    TextElement te = box.AddTextElement(this, _name, text, Style);
                    te.Name = "TextBox";
                    if (_canGrow || _canShrink)
                    {
                        // If the textbox can shrink or grow based on the contained text
                        // then we need to measure the text and set the box size appropriately.
                        Style style = this.Style;

                        System.Drawing.Bitmap   bm = new System.Drawing.Bitmap((int)width, (int)height);
                        System.Drawing.Graphics g  = System.Drawing.Graphics.FromImage(bm);
                        g.PageUnit = System.Drawing.GraphicsUnit.Point;
                        System.Drawing.FontStyle fs = (Style.FontStyle == Style.FontStyleEnum.Italic) ? System.Drawing.FontStyle.Italic : System.Drawing.FontStyle.Regular;
                        if (Style.FontWeight >= RdlEngine.Style.FontWeightEnum.Bold)
                        {
                            fs |= System.Drawing.FontStyle.Bold;
                        }
                        System.Drawing.Font font = new System.Drawing.Font(
                            style.FontFamily, (float)style.FontSize.points, fs);
                        System.Drawing.SizeF textSize = g.MeasureString(
                            text, font, (int)width);
//                        System.Drawing.Size textSize =
//                            System.Windows.Forms.TextRenderer.MeasureText(
//                                text, font,
//                                new System.Drawing.Size((int)width, int.MaxValue));

                        if (_canGrow && (decimal)textSize.Height > height)
                        {
                            height = (decimal)textSize.Height;
                        }
                        if (_canShrink && (decimal)textSize.Height < height)
                        {
                            height = (decimal)textSize.Height;
                        }
                    }
                    if (IsInCell)
                    {
                        te.MatchParentHeight = true;
                    }
                    else
                    {
                        te.Left = _left.points;
                        te.Top  = _top.points;
                    }
                    te.Width  = width;
                    te.Height = height;

                    _lastValue = text;
                }
            }
        }
Exemplo n.º 43
0
        public void DrawEan13Barcode(System.Drawing.Graphics g, System.Drawing.Point pt)
        {
            float width  = this.Width * this.Scale;
            float height = this.Height * this.Scale;

            //	EAN13 Barcode should be a total of 113 modules wide.
            float lineWidth = width / 113f;

            // Save the GraphicsState.
            System.Drawing.Drawing2D.GraphicsState gs = g.Save();

            // Set the PageUnit to Inch because all of our measurements are in inches.
            //g.PageUnit = System.Drawing.GraphicsUnit.Millimeter;
            //g.PageUnit = System.Drawing.GraphicsUnit.Pixel;

            // Set the PageScale to 1, so a millimeter will represent a true millimeter.
            g.PageScale = 1;

            System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);

            float xPosition = 0;

            System.Text.StringBuilder strbEAN13 = new System.Text.StringBuilder();
            System.Text.StringBuilder sbTemp    = new System.Text.StringBuilder();

            float xStart = pt.X;
            float yStart = pt.Y;
            float xEnd   = 0;

            System.Drawing.Font font = new System.Drawing.Font("Arial", this._fFontSize * this.Scale);

            // Calculate the Check Digit.
            this.CalculateChecksumDigit();

            //sbTemp.AppendFormat( "{0}{1}{2}{3}",
            //    this.CountryCode,
            //    this.ManufacturerCode,
            //    this.ProductCode,
            //    this.ChecksumDigit );

            //string sTemp = sbTemp.ToString( );
            string sTemp        = this.Barcode + this.ChecksumDigit;
            string sLeftPattern = "";

            // Convert the left hand numbers.
            sLeftPattern = ConvertLeftPattern(sTemp.Substring(0, 7));

            // Build the UPC Code.
            strbEAN13.AppendFormat("{0}{1}{2}{3}{4}{1}{0}",
                                   this._sQuiteZone, this._sLeadTail,
                                   sLeftPattern,
                                   this._sSeparator,
                                   ConvertToDigitPatterns(sTemp.Substring(7), this._aRight));

            string sTempUPC = strbEAN13.ToString();

            float fTextHeight = g.MeasureString(sTempUPC, font).Height;

            // Draw the barcode lines.
            for (int i = 0; i < strbEAN13.Length; i++)
            {
                if (sTempUPC.Substring(i, 1) == "1")
                {
                    if (xStart == pt.X)
                    {
                        xStart = xPosition;
                    }

                    // Save room for the UPC number below the bar code.
                    if ((i > 12 && i < 55) || (i > 57 && i < 101))
                    {
                        // Draw space for the number
                        g.FillRectangle(brush, xPosition, yStart, lineWidth, height - fTextHeight);
                    }
                    else
                    {
                        // Draw a full line.
                        g.FillRectangle(brush, xPosition, yStart, lineWidth, height);
                    }
                }

                xPosition += lineWidth;
                xEnd       = xPosition;
            }

            // Draw the upc numbers below the line.
            xPosition = xStart - g.MeasureString(this.CountryCode.Substring(0, 1), font).Width;
            float yPosition = yStart + (height - fTextHeight);

            // Draw 1st digit of the country code.
            g.DrawString(sTemp.Substring(0, 1), font, brush, new System.Drawing.PointF(xPosition, yPosition));

            xPosition += (g.MeasureString(sTemp.Substring(0, 1), font).Width + 43 * lineWidth) -
                         (g.MeasureString(sTemp.Substring(1, 6), font).Width);

            // Draw MFG Number.
            g.DrawString(sTemp.Substring(1, 6), font, brush, new System.Drawing.PointF(xPosition, yPosition));

            xPosition += g.MeasureString(sTemp.Substring(1, 6), font).Width + (11 * lineWidth);

            // Draw Product ID.
            g.DrawString(sTemp.Substring(7), font, brush, new System.Drawing.PointF(xPosition, yPosition));

            // Restore the GraphicsState.
            g.Restore(gs);
        }
Exemplo n.º 44
0
 internal void DrawText(string text, System.Drawing.Font font, Color color, int v1, int v2) => this.surface.DrawText(text, font, color.ToNativeColor(), v1, v2);
Exemplo n.º 45
0
 internal bool DrawTextInRect(ref string text, ref int xRelStart, ref int yRelStart, int v1, int v2, int width, int height, uint flags, Color color, System.Drawing.Font font) => this.surface.DrawTextInRect(ref text, ref xRelStart, ref yRelStart, v1, v2, width, height, flags, color.ToNativeColor(), font);
Exemplo n.º 46
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle   = new System.Windows.Forms.DataGridViewCellStyle();
     System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2  = new System.Windows.Forms.DataGridViewCellStyle();
     System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3  = new System.Windows.Forms.DataGridViewCellStyle();
     System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4  = new System.Windows.Forms.DataGridViewCellStyle();
     System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5  = new System.Windows.Forms.DataGridViewCellStyle();
     System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6  = new System.Windows.Forms.DataGridViewCellStyle();
     System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7  = new System.Windows.Forms.DataGridViewCellStyle();
     System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8  = new System.Windows.Forms.DataGridViewCellStyle();
     System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9  = new System.Windows.Forms.DataGridViewCellStyle();
     System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle10 = new System.Windows.Forms.DataGridViewCellStyle();
     System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle11 = new System.Windows.Forms.DataGridViewCellStyle();
     label1             = new System.Windows.Forms.Label();
     btn_ImportBatchNo  = new System.Windows.Forms.Button();
     btn_QueryRecord    = new System.Windows.Forms.Button();
     btn_Statistics     = new System.Windows.Forms.Button();
     groupBox1          = new System.Windows.Forms.GroupBox();
     label16            = new System.Windows.Forms.Label();
     label12            = new System.Windows.Forms.Label();
     btn_ReadCard       = new System.Windows.Forms.Button();
     tb_Birthday        = new System.Windows.Forms.DateTimePicker();
     tb_RocID           = new System.Windows.Forms.TextBox();
     label3             = new System.Windows.Forms.Label();
     tb_CaseName        = new System.Windows.Forms.TextBox();
     label2             = new System.Windows.Forms.Label();
     groupBox2          = new System.Windows.Forms.GroupBox();
     cb_Sex             = new System.Windows.Forms.ComboBox();
     label14            = new System.Windows.Forms.Label();
     cb_BirthSeq        = new System.Windows.Forms.ComboBox();
     label6             = new System.Windows.Forms.Label();
     tb_Birthday2       = new System.Windows.Forms.DateTimePicker();
     label5             = new System.Windows.Forms.Label();
     tb_ParentRocID     = new System.Windows.Forms.TextBox();
     label4             = new System.Windows.Forms.Label();
     groupBox3          = new System.Windows.Forms.GroupBox();
     tb_Address         = new System.Windows.Forms.TextBox();
     label8             = new System.Windows.Forms.Label();
     tb_Tel             = new System.Windows.Forms.TextBox();
     label7             = new System.Windows.Forms.Label();
     groupBox4          = new System.Windows.Forms.GroupBox();
     btn_LoadRecord     = new System.Windows.Forms.Button();
     btn_Del            = new System.Windows.Forms.Button();
     btn_Cancel         = new System.Windows.Forms.Button();
     btn_Edit           = new System.Windows.Forms.Button();
     btn_Submit         = new System.Windows.Forms.Button();
     tb_InoculationDate = new System.Windows.Forms.DateTimePicker();
     label13            = new System.Windows.Forms.Label();
     cb_BatchNo         = new System.Windows.Forms.ComboBox();
     label11            = new System.Windows.Forms.Label();
     cb_VaccineNo       = new System.Windows.Forms.ComboBox();
     label10            = new System.Windows.Forms.Label();
     cb_VaccineCode     = new System.Windows.Forms.ComboBox();
     label9             = new System.Windows.Forms.Label();
     btn_Save           = new System.Windows.Forms.Button();
     gv_Record          = new System.Windows.Forms.DataGridView();
     Seq                  = new System.Windows.Forms.DataGridViewTextBoxColumn();
     gvtb_TmpID           = new System.Windows.Forms.DataGridViewTextBoxColumn();
     gvtb_CaseName        = new System.Windows.Forms.DataGridViewTextBoxColumn();
     gvtb_RocID           = new System.Windows.Forms.DataGridViewTextBoxColumn();
     gvtb_ParentRocID     = new System.Windows.Forms.DataGridViewTextBoxColumn();
     gvtb_InoculationDate = new System.Windows.Forms.DataGridViewTextBoxColumn();
     gvtb_VaccineCode     = new System.Windows.Forms.DataGridViewTextBoxColumn();
     gvtb_VaccineNo       = new System.Windows.Forms.DataGridViewTextBoxColumn();
     gvtb_BatchNo         = new System.Windows.Forms.DataGridViewTextBoxColumn();
     gvtb_ExportedDate    = new System.Windows.Forms.DataGridViewTextBoxColumn();
     label15              = new System.Windows.Forms.Label();
     button1              = new System.Windows.Forms.Button();
     groupBox1.SuspendLayout();
     groupBox2.SuspendLayout();
     groupBox3.SuspendLayout();
     groupBox4.SuspendLayout();
     ((System.ComponentModel.ISupportInitialize)gv_Record).BeginInit();
     SuspendLayout();
     label1.AutoSize            = true;
     label1.Font                = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     label1.Location            = new System.Drawing.Point(12, 9);
     label1.Name                = "label1";
     label1.Size                = new System.Drawing.Size(104, 16);
     label1.TabIndex            = 0;
     label1.Text                = "預防接種登錄";
     btn_ImportBatchNo.Font     = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     btn_ImportBatchNo.Location = new System.Drawing.Point(490, 9);
     btn_ImportBatchNo.Name     = "btn_ImportBatchNo";
     btn_ImportBatchNo.Size     = new System.Drawing.Size(115, 26);
     btn_ImportBatchNo.TabIndex = 1;
     btn_ImportBatchNo.Text     = "疫苗批號匯入";
     btn_ImportBatchNo.UseVisualStyleBackColor = true;
     btn_ImportBatchNo.Click += new System.EventHandler(btn_ImportBatchNo_Click);
     btn_QueryRecord.Font     = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     btn_QueryRecord.Location = new System.Drawing.Point(611, 9);
     btn_QueryRecord.Name     = "btn_QueryRecord";
     btn_QueryRecord.Size     = new System.Drawing.Size(115, 26);
     btn_QueryRecord.TabIndex = 2;
     btn_QueryRecord.Text     = "接種紀錄明細";
     btn_QueryRecord.UseVisualStyleBackColor = true;
     btn_QueryRecord.Click  += new System.EventHandler(btn_QueryRecord_Click);
     btn_Statistics.Font     = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     btn_Statistics.Location = new System.Drawing.Point(732, 9);
     btn_Statistics.Name     = "btn_Statistics";
     btn_Statistics.Size     = new System.Drawing.Size(144, 26);
     btn_Statistics.TabIndex = 3;
     btn_Statistics.Text     = "疫苗接種人次統計";
     btn_Statistics.UseVisualStyleBackColor = true;
     btn_Statistics.Click += new System.EventHandler(btn_Statistics_Click);
     groupBox1.Controls.Add(label16);
     groupBox1.Controls.Add(label12);
     groupBox1.Controls.Add(btn_ReadCard);
     groupBox1.Controls.Add(tb_Birthday);
     groupBox1.Controls.Add(tb_RocID);
     groupBox1.Controls.Add(label3);
     groupBox1.Controls.Add(tb_CaseName);
     groupBox1.Controls.Add(label2);
     groupBox1.Font        = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     groupBox1.Location    = new System.Drawing.Point(15, 52);
     groupBox1.Name        = "groupBox1";
     groupBox1.Size        = new System.Drawing.Size(874, 98);
     groupBox1.TabIndex    = 4;
     groupBox1.TabStop     = false;
     groupBox1.Text        = "一、請插入健保IC卡讀取個案資料";
     label16.AutoSize      = true;
     label16.Location      = new System.Drawing.Point(40, 29);
     label16.Name          = "label16";
     label16.Size          = new System.Drawing.Size(152, 16);
     label16.TabIndex      = 33;
     label16.Text          = "或自行輸入個案資料";
     label12.AutoSize      = true;
     label12.Font          = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     label12.Location      = new System.Drawing.Point(488, 61);
     label12.Margin        = new System.Windows.Forms.Padding(4, 0, 4, 0);
     label12.Name          = "label12";
     label12.Size          = new System.Drawing.Size(72, 16);
     label12.TabIndex      = 32;
     label12.Text          = "出生日期";
     btn_ReadCard.Font     = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     btn_ReadCard.Location = new System.Drawing.Point(253, -1);
     btn_ReadCard.Name     = "btn_ReadCard";
     btn_ReadCard.Size     = new System.Drawing.Size(100, 28);
     btn_ReadCard.TabIndex = 27;
     btn_ReadCard.Text     = "讀取";
     btn_ReadCard.UseVisualStyleBackColor = true;
     btn_ReadCard.Click   += new System.EventHandler(btn_ReadCard_Click);
     tb_Birthday.Font      = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     tb_Birthday.Format    = System.Windows.Forms.DateTimePickerFormat.Short;
     tb_Birthday.Location  = new System.Drawing.Point(568, 58);
     tb_Birthday.Name      = "tb_Birthday";
     tb_Birthday.Size      = new System.Drawing.Size(114, 27);
     tb_Birthday.TabIndex  = 26;
     tb_RocID.ImeMode      = System.Windows.Forms.ImeMode.Alpha;
     tb_RocID.Location     = new System.Drawing.Point(310, 58);
     tb_RocID.Name         = "tb_RocID";
     tb_RocID.Size         = new System.Drawing.Size(156, 27);
     tb_RocID.TabIndex     = 3;
     tb_RocID.TextChanged += new System.EventHandler(tb_RocID_TextChanged);
     label3.AutoSize       = true;
     label3.Location       = new System.Drawing.Point(235, 61);
     label3.Name           = "label3";
     label3.Size           = new System.Drawing.Size(72, 16);
     label3.TabIndex       = 2;
     label3.Text           = "身分證號";
     tb_CaseName.Location  = new System.Drawing.Point(71, 58);
     tb_CaseName.Name      = "tb_CaseName";
     tb_CaseName.Size      = new System.Drawing.Size(151, 27);
     tb_CaseName.TabIndex  = 1;
     label2.AutoSize       = true;
     label2.Location       = new System.Drawing.Point(25, 61);
     label2.Name           = "label2";
     label2.Size           = new System.Drawing.Size(40, 16);
     label2.TabIndex       = 0;
     label2.Text           = "姓名";
     groupBox2.Controls.Add(cb_Sex);
     groupBox2.Controls.Add(label14);
     groupBox2.Controls.Add(cb_BirthSeq);
     groupBox2.Controls.Add(label6);
     groupBox2.Controls.Add(tb_Birthday2);
     groupBox2.Controls.Add(label5);
     groupBox2.Controls.Add(tb_ParentRocID);
     groupBox2.Controls.Add(label4);
     groupBox2.Font           = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     groupBox2.Location       = new System.Drawing.Point(15, 156);
     groupBox2.Name           = "groupBox2";
     groupBox2.Size           = new System.Drawing.Size(874, 63);
     groupBox2.TabIndex       = 5;
     groupBox2.TabStop        = false;
     groupBox2.Text           = "二、若個案沒有身分證號,請自行輸入以下欄位";
     cb_Sex.DropDownStyle     = System.Windows.Forms.ComboBoxStyle.DropDownList;
     cb_Sex.FormattingEnabled = true;
     cb_Sex.Items.AddRange(new object[2]
     {
         "男",
         "女"
     });
     cb_Sex.Location               = new System.Drawing.Point(618, 24);
     cb_Sex.Name                   = "cb_Sex";
     cb_Sex.Size                   = new System.Drawing.Size(64, 24);
     cb_Sex.TabIndex               = 30;
     label14.AutoSize              = true;
     label14.Location              = new System.Drawing.Point(524, 29);
     label14.Name                  = "label14";
     label14.Size                  = new System.Drawing.Size(88, 16);
     label14.TabIndex              = 29;
     label14.Text                  = "嬰幼兒性別";
     cb_BirthSeq.DropDownStyle     = System.Windows.Forms.ComboBoxStyle.DropDownList;
     cb_BirthSeq.FormattingEnabled = true;
     cb_BirthSeq.Items.AddRange(new object[5]
     {
         "1",
         "2",
         "3",
         "4",
         "5"
     });
     cb_BirthSeq.Location      = new System.Drawing.Point(779, 25);
     cb_BirthSeq.Name          = "cb_BirthSeq";
     cb_BirthSeq.Size          = new System.Drawing.Size(62, 24);
     cb_BirthSeq.TabIndex      = 28;
     label6.AutoSize           = true;
     label6.Location           = new System.Drawing.Point(701, 29);
     label6.Name               = "label6";
     label6.Size               = new System.Drawing.Size(72, 16);
     label6.TabIndex           = 6;
     label6.Text               = "同胎次序";
     tb_Birthday2.CalendarFont = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     tb_Birthday2.Font         = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     tb_Birthday2.Format       = System.Windows.Forms.DateTimePickerFormat.Short;
     tb_Birthday2.Location     = new System.Drawing.Point(394, 24);
     tb_Birthday2.Name         = "tb_Birthday2";
     tb_Birthday2.Size         = new System.Drawing.Size(114, 27);
     tb_Birthday2.TabIndex     = 27;
     label5.AutoSize           = true;
     label5.Location           = new System.Drawing.Point(264, 29);
     label5.Name               = "label5";
     label5.Size               = new System.Drawing.Size(120, 16);
     label5.TabIndex           = 5;
     label5.Text               = "嬰幼兒出生日期";
     tb_ParentRocID.Location   = new System.Drawing.Point(147, 26);
     tb_ParentRocID.Name       = "tb_ParentRocID";
     tb_ParentRocID.Size       = new System.Drawing.Size(111, 27);
     tb_ParentRocID.TabIndex   = 4;
     label4.AutoSize           = true;
     label4.Location           = new System.Drawing.Point(23, 29);
     label4.Name               = "label4";
     label4.Size               = new System.Drawing.Size(120, 16);
     label4.TabIndex           = 1;
     label4.Text               = "父或母身分證號";
     groupBox3.Controls.Add(tb_Address);
     groupBox3.Controls.Add(label8);
     groupBox3.Controls.Add(tb_Tel);
     groupBox3.Controls.Add(label7);
     groupBox3.Font      = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     groupBox3.Location  = new System.Drawing.Point(15, 225);
     groupBox3.Name      = "groupBox3";
     groupBox3.Size      = new System.Drawing.Size(874, 63);
     groupBox3.TabIndex  = 6;
     groupBox3.TabStop   = false;
     groupBox3.Text      = "三、聯絡資訊更新(非必填)";
     tb_Address.Location = new System.Drawing.Point(342, 26);
     tb_Address.Name     = "tb_Address";
     tb_Address.Size     = new System.Drawing.Size(519, 27);
     tb_Address.TabIndex = 7;
     label8.AutoSize     = true;
     label8.Location     = new System.Drawing.Point(263, 32);
     label8.Name         = "label8";
     label8.Size         = new System.Drawing.Size(72, 16);
     label8.TabIndex     = 6;
     label8.Text         = "通訊地址";
     tb_Tel.ImeMode      = System.Windows.Forms.ImeMode.Alpha;
     tb_Tel.Location     = new System.Drawing.Point(71, 26);
     tb_Tel.Name         = "tb_Tel";
     tb_Tel.Size         = new System.Drawing.Size(156, 27);
     tb_Tel.TabIndex     = 5;
     label7.AutoSize     = true;
     label7.Location     = new System.Drawing.Point(25, 32);
     label7.Name         = "label7";
     label7.Size         = new System.Drawing.Size(40, 16);
     label7.TabIndex     = 3;
     label7.Text         = "電話";
     groupBox4.Controls.Add(btn_LoadRecord);
     groupBox4.Controls.Add(btn_Del);
     groupBox4.Controls.Add(btn_Cancel);
     groupBox4.Controls.Add(btn_Edit);
     groupBox4.Controls.Add(btn_Submit);
     groupBox4.Controls.Add(tb_InoculationDate);
     groupBox4.Controls.Add(label13);
     groupBox4.Controls.Add(cb_BatchNo);
     groupBox4.Controls.Add(label11);
     groupBox4.Controls.Add(cb_VaccineNo);
     groupBox4.Controls.Add(label10);
     groupBox4.Controls.Add(cb_VaccineCode);
     groupBox4.Controls.Add(label9);
     groupBox4.Font          = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     groupBox4.Location      = new System.Drawing.Point(15, 294);
     groupBox4.Name          = "groupBox4";
     groupBox4.Size          = new System.Drawing.Size(874, 110);
     groupBox4.TabIndex      = 7;
     groupBox4.TabStop       = false;
     groupBox4.Text          = "四、預防接種登錄";
     btn_LoadRecord.Location = new System.Drawing.Point(142, -1);
     btn_LoadRecord.Name     = "btn_LoadRecord";
     btn_LoadRecord.Size     = new System.Drawing.Size(193, 28);
     btn_LoadRecord.TabIndex = 32;
     btn_LoadRecord.Text     = "檢視離線版接種資料";
     btn_LoadRecord.UseVisualStyleBackColor = true;
     btn_LoadRecord.Click                += new System.EventHandler(btn_LoadRecord_Click);
     btn_Del.Location                     = new System.Drawing.Point(796, 69);
     btn_Del.Name                         = "btn_Del";
     btn_Del.Size                         = new System.Drawing.Size(62, 33);
     btn_Del.TabIndex                     = 31;
     btn_Del.Text                         = "刪除";
     btn_Del.UseVisualStyleBackColor      = true;
     btn_Del.Visible                      = false;
     btn_Del.Click                       += new System.EventHandler(btn_Del_Click);
     btn_Cancel.Location                  = new System.Drawing.Point(728, 69);
     btn_Cancel.Name                      = "btn_Cancel";
     btn_Cancel.Size                      = new System.Drawing.Size(62, 33);
     btn_Cancel.TabIndex                  = 30;
     btn_Cancel.Text                      = "取消";
     btn_Cancel.UseVisualStyleBackColor   = true;
     btn_Cancel.Visible                   = false;
     btn_Cancel.Click                    += new System.EventHandler(btn_Cancel_Click);
     btn_Edit.Location                    = new System.Drawing.Point(660, 69);
     btn_Edit.Name                        = "btn_Edit";
     btn_Edit.Size                        = new System.Drawing.Size(62, 33);
     btn_Edit.TabIndex                    = 29;
     btn_Edit.Text                        = "修改";
     btn_Edit.UseVisualStyleBackColor     = true;
     btn_Edit.Visible                     = false;
     btn_Edit.Click                      += new System.EventHandler(btn_Edit_Click);
     btn_Submit.Font                      = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     btn_Submit.Location                  = new System.Drawing.Point(376, 73);
     btn_Submit.Name                      = "btn_Submit";
     btn_Submit.Size                      = new System.Drawing.Size(116, 33);
     btn_Submit.TabIndex                  = 28;
     btn_Submit.Text                      = "建立接種資料";
     btn_Submit.UseVisualStyleBackColor   = true;
     btn_Submit.Click                    += new System.EventHandler(btn_Submit_Click);
     tb_InoculationDate.Font              = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     tb_InoculationDate.Format            = System.Windows.Forms.DateTimePickerFormat.Short;
     tb_InoculationDate.Location          = new System.Drawing.Point(749, 33);
     tb_InoculationDate.Name              = "tb_InoculationDate";
     tb_InoculationDate.Size              = new System.Drawing.Size(114, 27);
     tb_InoculationDate.TabIndex          = 27;
     label13.AutoSize                     = true;
     label13.Location                     = new System.Drawing.Point(666, 37);
     label13.Name                         = "label13";
     label13.Size                         = new System.Drawing.Size(80, 16);
     label13.TabIndex                     = 10;
     label13.Text                         = "*接種日期";
     cb_BatchNo.DropDownStyle             = System.Windows.Forms.ComboBoxStyle.DropDownList;
     cb_BatchNo.DropDownWidth             = 160;
     cb_BatchNo.FormattingEnabled         = true;
     cb_BatchNo.ImeMode                   = System.Windows.Forms.ImeMode.NoControl;
     cb_BatchNo.Location                  = new System.Drawing.Point(485, 33);
     cb_BatchNo.Name                      = "cb_BatchNo";
     cb_BatchNo.Size                      = new System.Drawing.Size(167, 24);
     cb_BatchNo.TabIndex                  = 9;
     label11.AutoSize                     = true;
     label11.Location                     = new System.Drawing.Point(402, 37);
     label11.Name                         = "label11";
     label11.Size                         = new System.Drawing.Size(80, 16);
     label11.TabIndex                     = 8;
     label11.Text                         = "*疫苗批號";
     cb_VaccineNo.DropDownStyle           = System.Windows.Forms.ComboBoxStyle.DropDownList;
     cb_VaccineNo.FormattingEnabled       = true;
     cb_VaccineNo.Location                = new System.Drawing.Point(299, 33);
     cb_VaccineNo.Name                    = "cb_VaccineNo";
     cb_VaccineNo.Size                    = new System.Drawing.Size(90, 24);
     cb_VaccineNo.TabIndex                = 7;
     cb_VaccineNo.SelectedIndexChanged   += new System.EventHandler(cb_VaccineNo_SelectedIndexChanged);
     label10.AutoSize                     = true;
     label10.Location                     = new System.Drawing.Point(229, 37);
     label10.Name                         = "label10";
     label10.Size                         = new System.Drawing.Size(68, 16);
     label10.TabIndex                     = 6;
     label10.Text                         = "*劑別/型";
     cb_VaccineCode.DisplayMember         = "VaccineCode";
     cb_VaccineCode.DropDownStyle         = System.Windows.Forms.ComboBoxStyle.DropDownList;
     cb_VaccineCode.DropDownWidth         = 500;
     cb_VaccineCode.FormattingEnabled     = true;
     cb_VaccineCode.Location              = new System.Drawing.Point(91, 33);
     cb_VaccineCode.Name                  = "cb_VaccineCode";
     cb_VaccineCode.Size                  = new System.Drawing.Size(136, 24);
     cb_VaccineCode.TabIndex              = 5;
     cb_VaccineCode.ValueMember           = "VaccineCode";
     cb_VaccineCode.SelectedIndexChanged += new System.EventHandler(cb_VaccineCode_SelectedIndexChanged);
     label9.AutoSize                      = true;
     label9.Location                      = new System.Drawing.Point(6, 37);
     label9.Name       = "label9";
     label9.Size       = new System.Drawing.Size(80, 16);
     label9.TabIndex   = 4;
     label9.Text       = "*疫苗名稱";
     btn_Save.Font     = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     btn_Save.Location = new System.Drawing.Point(325, 596);
     btn_Save.Name     = "btn_Save";
     btn_Save.Size     = new System.Drawing.Size(250, 37);
     btn_Save.TabIndex = 29;
     btn_Save.Text     = "儲存,並建立下一個案接種資料";
     btn_Save.UseVisualStyleBackColor = true;
     btn_Save.Click += new System.EventHandler(btn_Save_Click);
     gv_Record.AllowUserToAddRows             = false;
     gv_Record.AutoSizeColumnsMode            = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
     dataGridViewCellStyle.Alignment          = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
     dataGridViewCellStyle.BackColor          = System.Drawing.SystemColors.Control;
     dataGridViewCellStyle.Font               = new System.Drawing.Font("新細明體", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     dataGridViewCellStyle.ForeColor          = System.Drawing.SystemColors.WindowText;
     dataGridViewCellStyle.SelectionBackColor = System.Drawing.SystemColors.Highlight;
     dataGridViewCellStyle.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
     dataGridViewCellStyle.WrapMode           = System.Windows.Forms.DataGridViewTriState.True;
     gv_Record.ColumnHeadersDefaultCellStyle  = dataGridViewCellStyle;
     gv_Record.ColumnHeadersHeightSizeMode    = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
     gv_Record.Columns.AddRange(Seq, gvtb_TmpID, gvtb_CaseName, gvtb_RocID, gvtb_ParentRocID, gvtb_InoculationDate, gvtb_VaccineCode, gvtb_VaccineNo, gvtb_BatchNo, gvtb_ExportedDate);
     dataGridViewCellStyle2.Alignment          = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
     dataGridViewCellStyle2.BackColor          = System.Drawing.SystemColors.Window;
     dataGridViewCellStyle2.Font               = new System.Drawing.Font("新細明體", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     dataGridViewCellStyle2.ForeColor          = System.Drawing.SystemColors.ControlText;
     dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
     dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
     dataGridViewCellStyle2.WrapMode           = System.Windows.Forms.DataGridViewTriState.False;
     gv_Record.DefaultCellStyle           = dataGridViewCellStyle2;
     gv_Record.Location                   = new System.Drawing.Point(15, 411);
     gv_Record.MultiSelect                = false;
     gv_Record.Name                       = "gv_Record";
     gv_Record.ReadOnly                   = true;
     gv_Record.RowTemplate.Height         = 24;
     gv_Record.SelectionMode              = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
     gv_Record.Size                       = new System.Drawing.Size(874, 177);
     gv_Record.TabIndex                   = 30;
     gv_Record.DataBindingComplete       += new System.Windows.Forms.DataGridViewBindingCompleteEventHandler(gv_Record_DataBindingComplete);
     gv_Record.RowHeaderMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(gv_Record_RowHeaderMouseDoubleClick);
     gv_Record.UserDeletedRow            += new System.Windows.Forms.DataGridViewRowEventHandler(gv_Record_UserDeletedRow);
     gv_Record.UserDeletingRow           += new System.Windows.Forms.DataGridViewRowCancelEventHandler(gv_Record_UserDeletingRow);
     Seq.DataPropertyName                 = "Seq";
     dataGridViewCellStyle3.Font          = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     Seq.DefaultCellStyle                 = dataGridViewCellStyle3;
     Seq.FillWeight                       = 23.86793f;
     Seq.HeaderText                       = "序號";
     Seq.MinimumWidth                     = 50;
     Seq.Name      = "Seq";
     Seq.ReadOnly  = true;
     Seq.Resizable = System.Windows.Forms.DataGridViewTriState.False;
     gvtb_TmpID.DataPropertyName           = "ID";
     gvtb_TmpID.HeaderText                 = "TmpID";
     gvtb_TmpID.Name                       = "gvtb_TmpID";
     gvtb_TmpID.ReadOnly                   = true;
     gvtb_TmpID.Visible                    = false;
     gvtb_CaseName.DataPropertyName        = "CaseName";
     dataGridViewCellStyle4.Font           = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     gvtb_CaseName.DefaultCellStyle        = dataGridViewCellStyle4;
     gvtb_CaseName.HeaderText              = "姓名";
     gvtb_CaseName.Name                    = "gvtb_CaseName";
     gvtb_CaseName.ReadOnly                = true;
     gvtb_RocID.DataPropertyName           = "RocID";
     dataGridViewCellStyle5.Font           = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     gvtb_RocID.DefaultCellStyle           = dataGridViewCellStyle5;
     gvtb_RocID.FillWeight                 = 107.8054f;
     gvtb_RocID.HeaderText                 = "身分證號";
     gvtb_RocID.Name                       = "gvtb_RocID";
     gvtb_RocID.ReadOnly                   = true;
     gvtb_ParentRocID.DataPropertyName     = "ParentRocID";
     dataGridViewCellStyle6.Font           = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     gvtb_ParentRocID.DefaultCellStyle     = dataGridViewCellStyle6;
     gvtb_ParentRocID.FillWeight           = 107.8054f;
     gvtb_ParentRocID.HeaderText           = "父或母身分證號";
     gvtb_ParentRocID.Name                 = "gvtb_ParentRocID";
     gvtb_ParentRocID.ReadOnly             = true;
     gvtb_InoculationDate.DataPropertyName = "InoculationDate";
     dataGridViewCellStyle7.Font           = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     gvtb_InoculationDate.DefaultCellStyle = dataGridViewCellStyle7;
     gvtb_InoculationDate.FillWeight       = 107.8054f;
     gvtb_InoculationDate.HeaderText       = "接種日期";
     gvtb_InoculationDate.Name             = "gvtb_InoculationDate";
     gvtb_InoculationDate.ReadOnly         = true;
     gvtb_VaccineCode.DataPropertyName     = "VaccineCode";
     dataGridViewCellStyle8.Font           = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     gvtb_VaccineCode.DefaultCellStyle     = dataGridViewCellStyle8;
     gvtb_VaccineCode.FillWeight           = 107.8054f;
     gvtb_VaccineCode.HeaderText           = "疫苗名稱";
     gvtb_VaccineCode.Name                 = "gvtb_VaccineCode";
     gvtb_VaccineCode.ReadOnly             = true;
     gvtb_VaccineNo.DataPropertyName       = "VaccineNo";
     dataGridViewCellStyle9.Font           = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     gvtb_VaccineNo.DefaultCellStyle       = dataGridViewCellStyle9;
     gvtb_VaccineNo.FillWeight             = 77.8054f;
     gvtb_VaccineNo.HeaderText             = "劑別/型";
     gvtb_VaccineNo.Name                   = "gvtb_VaccineNo";
     gvtb_VaccineNo.ReadOnly               = true;
     gvtb_BatchNo.DataPropertyName         = "VaccBatchNo";
     dataGridViewCellStyle10.Font          = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     gvtb_BatchNo.DefaultCellStyle         = dataGridViewCellStyle10;
     gvtb_BatchNo.FillWeight               = 137.8054f;
     gvtb_BatchNo.HeaderText               = "疫苗批號";
     gvtb_BatchNo.Name                     = "gvtb_BatchNo";
     gvtb_BatchNo.ReadOnly                 = true;
     gvtb_ExportedDate.DataPropertyName    = "ExportedDate";
     dataGridViewCellStyle11.Font          = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     gvtb_ExportedDate.DefaultCellStyle    = dataGridViewCellStyle11;
     gvtb_ExportedDate.FillWeight          = 107.8054f;
     gvtb_ExportedDate.HeaderText          = "匯出日期";
     gvtb_ExportedDate.Name                = "gvtb_ExportedDate";
     gvtb_ExportedDate.ReadOnly            = true;
     label15.AutoSize                      = true;
     label15.Location                      = new System.Drawing.Point(21, 421);
     label15.Name     = "label15";
     label15.Size     = new System.Drawing.Size(29, 12);
     label15.TabIndex = 31;
     label15.Text     = "編輯";
     button1.Font     = new System.Drawing.Font("新細明體", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     button1.Location = new System.Drawing.Point(369, 9);
     button1.Name     = "button1";
     button1.Size     = new System.Drawing.Size(115, 26);
     button1.TabIndex = 33;
     button1.Text     = "清除";
     button1.UseVisualStyleBackColor = true;
     button1.Click           += new System.EventHandler(button1_Click);
     base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
     base.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
     base.ClientSize          = new System.Drawing.Size(901, 644);
     base.Controls.Add(button1);
     base.Controls.Add(label15);
     base.Controls.Add(gv_Record);
     base.Controls.Add(btn_Save);
     base.Controls.Add(groupBox4);
     base.Controls.Add(groupBox3);
     base.Controls.Add(groupBox2);
     base.Controls.Add(groupBox1);
     base.Controls.Add(btn_Statistics);
     base.Controls.Add(btn_QueryRecord);
     base.Controls.Add(btn_ImportBatchNo);
     base.Controls.Add(label1);
     Font               = new System.Drawing.Font("新細明體", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 136);
     base.Name          = "Form_Main";
     base.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
     Text               = "離線版預防接種登錄";
     base.Load         += new System.EventHandler(Form_Main_Load);
     groupBox1.ResumeLayout(false);
     groupBox1.PerformLayout();
     groupBox2.ResumeLayout(false);
     groupBox2.PerformLayout();
     groupBox3.ResumeLayout(false);
     groupBox3.PerformLayout();
     groupBox4.ResumeLayout(false);
     groupBox4.PerformLayout();
     ((System.ComponentModel.ISupportInitialize)gv_Record).EndInit();
     ResumeLayout(false);
     PerformLayout();
 }
Exemplo n.º 47
0
 public static System.Drawing.Image DrawTextImage(String currencyCode, System.Drawing.Font font, System.Drawing.Color textColor, System.Drawing.Color backColor)
 {
     return(DrawTextImage(currencyCode, font, textColor, backColor, System.Drawing.Size.Empty));
 }
Exemplo n.º 48
0
        // CONTROL ADDITION -------------------------------------------------------------------------------------------------------------

        Control addcontrol(string[, ,] controlarray, HtmlTableCell cell, HtmlTableRow row, int col_traverse, int row_traverse)
        {
            // Generic return object
            Control returncontrol = new Control();

            // Specific object generation methods
            switch (controlarray[col_traverse, row_traverse, 0])
            {
            case "LABEL":       // Label control
            {
                // Create new control
                Label newlabel = new Label();

                // Set control properties
                newlabel.Font.Name = "Arial"; newlabel.Font.Size = 11;
                newlabel.ID        = "control_" + col_traverse + "_" + row_traverse;

                // Add control
                cell.Controls.Add(newlabel);
                returncontrol = newlabel;

                break;
            }

            case "TEXTBOX":
            {
                // Create new control
                TextBox newtextbox = new TextBox();
                Label   newlabel   = new Label();

                // Set textbox control properties
                newtextbox.Font.Name = "Arial"; newtextbox.Font.Size = 11;
                newtextbox.ID        = "control_" + col_traverse + "_" + row_traverse;
                newtextbox.Width     = Unit.Pixel(Convert.ToInt16(cell.Width.Substring(0, cell.Width.Length - 2)) * cell.ColSpan - 2 * (layouttable.Border + layouttable.CellPadding));

                // Set label control properties
                newlabel.Font.Name = "Arial"; newlabel.Font.Size = 11;

                // Add control
                cell.Controls.Add(newlabel);
                cell.Controls.Add(new LiteralControl("<br><br>"));
                cell.Controls.Add(newtextbox);

                // Return label for text fill
                //returncontrol = newtextbox;
                returncontrol = newlabel;
                break;
            }

            case "MULTISELECT":
            {
                // Create new control
                ListBox newlistbox = new ListBox();
                Label   newlabel   = new Label();

                // Set listbox control properties
                newlistbox.Font.Name     = "Arial"; newlistbox.Font.Size = 11;
                newlistbox.ID            = "control_" + col_traverse + "_" + row_traverse;
                newlistbox.Width         = Unit.Pixel(Convert.ToInt16(cell.Width.Substring(0, cell.Width.Length - 2)) * cell.ColSpan - 2 * (layouttable.Border + layouttable.CellPadding));
                newlistbox.SelectionMode = ListSelectionMode.Multiple;

                // Set label control properties
                newlabel.Font.Name = "Arial"; newlabel.Font.Size = 11;
                newlabel.ID        = "control_" + col_traverse + "_" + row_traverse + "_label";

                // Add control
                cell.Controls.Add(newlabel);
                cell.Controls.Add(new LiteralControl("<br><br>"));
                cell.Controls.Add(newlistbox);

                // Return label for text fill
                //returncontrol = newtextbox;
                returncontrol = newlistbox;
                break;
            }

            case "IMAGE":
            {
                // Create new control
                Image newimage = new Image();

                // Set control properties
                newimage.ID     = "control_" + col_traverse + "_" + row_traverse;
                newimage.Width  = Unit.Pixel(Convert.ToInt16(cell.Width.Substring(0, cell.Width.Length - 2)) * cell.ColSpan - 2 * (layouttable.Border + layouttable.CellPadding));
                newimage.Height = Unit.Pixel(Convert.ToInt16(row.Height.Substring(0, row.Height.Length - 2)) * cell.RowSpan - 2 * (layouttable.Border + layouttable.CellPadding));

                // Add control
                cell.Controls.Add(newimage);
                returncontrol = newimage;

                break;
            }

            case "TABLE":
            {
                // Enclose table in panel
                Panel tablepanel = new Panel();
                tablepanel.ScrollBars = ScrollBars.Both;
                tablepanel.Width      = Unit.Pixel(Convert.ToInt16(cell.Width.Substring(0, cell.Width.Length - 2)) * cell.ColSpan - (layouttable.Border + layouttable.CellPadding));
                tablepanel.Height     = Unit.Pixel(Convert.ToInt16(row.Height.Substring(0, row.Height.Length - 2)) * cell.RowSpan - (layouttable.Border + layouttable.CellPadding));

                // Create new control
                GridView newtable = new GridView();

                // Set control properties
                newtable.ID                       = "control_" + col_traverse + "_" + row_traverse;
                newtable.Width                    = Unit.Pixel((int)(tablepanel.Width.Value - 17));
                newtable.Height                   = Unit.Pixel((int)(tablepanel.Height.Value - 17));
                newtable.Font.Name                = "Arial"; newtable.Font.Size = 11;
                newtable.HeaderStyle.BackColor    = System.Drawing.Color.Silver;
                newtable.RowStyle.BackColor       = System.Drawing.Color.White;
                newtable.RowStyle.HorizontalAlign = HorizontalAlign.Center;

                // Add control
                tablepanel.Controls.Add(newtable);
                cell.Controls.Add(tablepanel);
                returncontrol = tablepanel;

                break;
            }

            case "SCATTERPLOT":
            {
                Chart  Projection = new Chart();
                Series newseries  = new Series();
                newseries.ChartType = SeriesChartType.Point;
                Projection.ChartAreas.Add(new ChartArea());
                Projection.ChartAreas[0].AxisY.Title = "Second Principal Component";
                Projection.ChartAreas[0].AxisX.Title = "First Principal Component";

                Projection.Width  = Unit.Pixel(Convert.ToInt16(cell.Width.Substring(0, cell.Width.Length - 2)) * cell.ColSpan - 2 * (layouttable.Border + layouttable.CellPadding));
                Projection.Height = Unit.Pixel(Convert.ToInt16(row.Height.Substring(0, row.Height.Length - 2)) * cell.RowSpan - 2 * (layouttable.Border + layouttable.CellPadding));

                DataMiningApp.Analysis.ParameterStream stream;
                Registry.Registry registry;

                stream   = DataMiningApp.Analysis.ParameterStream.getStream(Session);
                registry = Registry.Registry.getRegistry(Session);

                Matrix   PCmatrix = (Matrix)stream.get("PCmatrix");
                String[] features = (String[])stream.get("selectedFeatures");

                System.Data.DataSet ds = (System.Data.DataSet)registry.GetDataset((string)stream.get("dataSetName"));

                //retrieve dataset table (assume one for now)
                System.Data.DataTable dt = ds.Tables[0];

                //raw data
                double[,] rawData = new double[dt.Rows.Count, features.Count()];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    for (int j = 0; j < features.Count(); j++)
                    {
                        rawData[i, j] = (double)dt.Rows[i].ItemArray.ElementAt(dt.Columns[features[j]].Ordinal);
                    }
                }

                //Create matrix to hold data for PCA
                Matrix X = new Matrix(rawData);

                //Remove mean
                Vector columnVector;
                for (int i = 0; i < X.ColumnCount; i++)
                {
                    columnVector = X.GetColumnVector(i);
                    X.SetColumnVector(columnVector.Subtract(columnVector.Average()), i);
                }

                //get first two PCs
                Matrix xy = new Matrix(PCmatrix.RowCount, 2);
                xy.SetColumnVector(PCmatrix.GetColumnVector(0), 0);
                xy.SetColumnVector(PCmatrix.GetColumnVector(1), 1);

                //project
                Matrix projected = X.Multiply(xy);

                DataPoint point;
                Projection.Series.Clear();
                Projection.Legends.Clear();


                //if a label column is selected
                String LabelColumnName = "Species";

                if (!LabelColumnName.Equals(""))
                {
                    //get labels
                    int           labelColumnIndex = dt.Columns[LabelColumnName].Ordinal;
                    List <String> labels           = new List <String>();
                    String        item;

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        item = (String)dt.Rows[i].ItemArray.ElementAt(labelColumnIndex);
                        if (!labels.Contains(item))
                        {
                            labels.Add(item);
                        }
                    }
                    Legend mylegend = Projection.Legends.Add(LabelColumnName);
                    mylegend.TableStyle = LegendTableStyle.Wide;

                    Projection.Legends[0].Docking = Docking.Bottom;
                    System.Drawing.Font font = Projection.Legends[LabelColumnName].Font = new System.Drawing.Font(Projection.Legends[LabelColumnName].Font.Name, 14);

                    //Configure series
                    foreach (String label in labels)
                    {
                        Projection.Series.Add(label);
                        Projection.Series[label].LegendText      = label;
                        Projection.Series[label].IsXValueIndexed = false;
                        Projection.Series[label].ChartType       = SeriesChartType.Point;
                        Projection.Series[label].MarkerSize      = 8;
                    }

                    //Add points
                    for (int i = 0; i < projected.RowCount; i++)
                    {
                        point = new DataPoint(projected[i, 0], projected[i, 1]);
                        String label = dt.Rows[i].ItemArray[labelColumnIndex].ToString();
                        Projection.Series[label].Points.Add(point);
                    }
                }
                else
                {
                    //Single plot graph
                    Projection.Series.Add("series1");
                    Projection.Series[0].IsXValueIndexed = false;
                    Projection.Series[0].ChartType       = SeriesChartType.Point;
                    Projection.Series[0].MarkerSize      = 8;

                    for (int i = 0; i < projected.RowCount; i++)
                    {
                        point = new DataPoint(projected[i, 0], projected[i, 1]);
                        Projection.Series[0].Points.Add(point);
                    }
                }
                cell.Controls.Add(Projection);
                returncontrol = Projection;

                /*
                 * // Create new control
                 * Chart chartcontrol = new Chart();
                 *
                 * // Set chart width and height
                 * chartcontrol.Width = Unit.Pixel(Convert.ToInt16(cell.Width.Substring(0, cell.Width.Length - 2)) * cell.ColSpan - 2 * (layouttable.Border + layouttable.CellPadding));
                 * chartcontrol.Height = Unit.Pixel(Convert.ToInt16(row.Height.Substring(0, row.Height.Length - 2)) * cell.RowSpan - 2 * (layouttable.Border + layouttable.CellPadding));
                 *
                 * // Needed so server knows where to store temporary image
                 * chartcontrol.ImageStorageMode = ImageStorageMode.UseImageLocation;
                 *
                 * ChartArea mychartarea = new ChartArea();
                 * chartcontrol.ChartAreas.Add(mychartarea);
                 *
                 * Series myseries = new Series();
                 * myseries.Name = "Series";
                 * chartcontrol.Series.Add(myseries);
                 *
                 * chartcontrol.Series["Series"].ChartType = SeriesChartType.Point;
                 *
                 * // Add control
                 * cell.Controls.Add(chartcontrol);
                 * returncontrol = chartcontrol;
                 */
                break;
            }

            case "LINEPLOT":
            {
                DataMiningApp.Analysis.ParameterStream stream = DataMiningApp.Analysis.ParameterStream.getStream(Session);
                Vector Weights = (Vector)stream.get("Weights");

                Chart VariancePlot = new Chart();

                VariancePlot.Width  = Unit.Pixel(Convert.ToInt16(cell.Width.Substring(0, cell.Width.Length - 2)) * cell.ColSpan - 2 * (layouttable.Border + layouttable.CellPadding));
                VariancePlot.Height = Unit.Pixel(Convert.ToInt16(row.Height.Substring(0, row.Height.Length - 2)) * cell.RowSpan - 2 * (layouttable.Border + layouttable.CellPadding));

                VariancePlot.Palette = ChartColorPalette.EarthTones;
                Series dataseries = new Series();
                dataseries.ChartType         = SeriesChartType.Line;
                dataseries.MarkerColor       = System.Drawing.Color.Black;
                dataseries.MarkerBorderWidth = 3;
                dataseries.MarkerBorderColor = System.Drawing.Color.Black;
                VariancePlot.Series.Add(dataseries);
                VariancePlot.ChartAreas.Add(new ChartArea());
                VariancePlot.ChartAreas[0].AxisY.Title = "Variance Explained";
                VariancePlot.ChartAreas[0].AxisX.Title = "Principal Component";

                for (int i = 0; i < Weights.Length; i++)
                {
                    VariancePlot.Series[0].Points.InsertY(i, Weights[i]);
                }

                cell.Controls.Add(VariancePlot);
                returncontrol = VariancePlot;

                break;
            }

            case "UPLOAD":
            {
                // Create new controls
                Label       uploadlabel = new Label();
                FileUpload  uploadcontrol = new FileUpload();
                HiddenField savedfile = new HiddenField(); HiddenField savedpath = new HiddenField();
                Button      uploadbutton = new Button();
                GridView    uploadtable  = new GridView();

                // Create panel to enclose table to it can scroll without having to scroll entire window
                Panel tablepanel = new Panel();
                tablepanel.ScrollBars = ScrollBars.Both;
                tablepanel.Width      = Unit.Pixel(Convert.ToInt16(cell.Width.Substring(0, cell.Width.Length - 2)) * cell.ColSpan - (layouttable.Border + layouttable.CellPadding));
                tablepanel.Height     = Unit.Pixel(Convert.ToInt16(row.Height.Substring(0, row.Height.Length - 2)) * cell.RowSpan - (layouttable.Border + layouttable.CellPadding));

                // Set IDs for all controls (necessary to get information after postback on upload)
                uploadlabel.ID   = "control_" + col_traverse + "_" + row_traverse + "_label";
                savedfile.ID     = "control_" + col_traverse + "_" + row_traverse + "_savedfile";
                savedpath.ID     = "control_" + col_traverse + "_" + row_traverse + "_savedpath";
                uploadcontrol.ID = "control_" + col_traverse + "_" + row_traverse;
                uploadtable.ID   = "control_" + col_traverse + "_" + row_traverse + "_table";
                uploadbutton.ID  = "control_" + col_traverse + "_" + row_traverse + "_button";

                // Set control properties
                uploadbutton.Text                    = "Load File";
                uploadbutton.Font.Name               = "Arial"; uploadbutton.Font.Size = 10;
                uploadbutton.Width                   = 100;
                uploadbutton.Click                  += new System.EventHandler(uploadbutton_Click);
                uploadlabel.Font.Name                = "Arial"; uploadlabel.Font.Size = 11;
                uploadlabel.ForeColor                = System.Drawing.Color.Black;
                uploadcontrol.Width                  = Unit.Pixel((int)(tablepanel.Width.Value - 17) - (int)uploadbutton.Width.Value);
                uploadtable.Width                    = Unit.Pixel((int)(tablepanel.Width.Value - 17));
                uploadtable.Height                   = Unit.Pixel((int)(tablepanel.Height.Value - 17));
                uploadtable.Font.Name                = "Arial"; uploadtable.Font.Size = 11;
                uploadtable.HeaderStyle.BackColor    = System.Drawing.Color.Silver;
                uploadtable.RowStyle.BackColor       = System.Drawing.Color.White;
                uploadtable.RowStyle.HorizontalAlign = HorizontalAlign.Center;

                // Add controls to form and format
                tablepanel.Controls.Add(uploadlabel);
                tablepanel.Controls.Add(new LiteralControl("<br><br>"));
                tablepanel.Controls.Add(uploadcontrol);
                tablepanel.Controls.Add(uploadbutton);
                tablepanel.Controls.Add(new LiteralControl("<br><br>"));
                tablepanel.Controls.Add(uploadtable);

                // Add controls to scrollable panel
                cell.Controls.Add(tablepanel);

                // Return uploadcontrol, even though this control itself does not need to be filled (need control type)
                returncontrol = uploadcontrol;

                break;
            }
            }
            return(returncontrol);
        }
Exemplo n.º 49
0
        public WFFont GetFont(string familyName, double emSizeD, WFFontStyle wfs)
        {
            float emSize = (float)emSizeD;
#endif // WPF

#if DEBUG
            Stopwatch sw = Stopwatch.StartNew();
#endif // DEBUG

            if (string.IsNullOrEmpty(familyName))
            {
                familyName = System.Drawing.SystemFonts.DefaultFont.FontFamily.Name;
            }

            WFFont                    font      = null;
            List <WFFont>             fontGroup = null;
            System.Drawing.FontFamily family    = null;

            lock (this.fonts)
            {
                if (this.fonts.TryGetValue(familyName, out fontGroup))
                {
                    if (fontGroup.Count > 0)
                    {
                        family = fontGroup[0].FontFamily;
                    }

                    lock (fontGroup)
                    {
                        font = fontGroup.FirstOrDefault(f => f.Size == emSize && f.Style == wfs);
                    }
                }
            }

            if (font != null)
            {
                return(font);
            }

            if (family == null)
            {
                try
                {
                    family = new System.Drawing.FontFamily(familyName);
                }
                catch (ArgumentException ex)
                {
                    //throw new FontNotFoundException(ex.ParamName);
                    family = System.Drawing.SystemFonts.DefaultFont.FontFamily;
                    Logger.Log("resource pool", "font family error: " + familyName + ": " + ex.Message);
                }

                if (!family.IsStyleAvailable(wfs))
                {
                    try
                    {
                        wfs = FindFirstAvailableFontStyle(family);
                    }
                    catch
                    {
                        return(System.Drawing.SystemFonts.DefaultFont);
                    }
                }
            }

            lock (this.fonts)
            {
                if (fonts.TryGetValue(family.Name, out fontGroup))
                {
                    lock (fontGroup)
                    {
                        font = fontGroup.FirstOrDefault(f => f.Size == emSize && f.Style == wfs);
                    }
                }
            }

            if (font == null)
            {
                font = new WFFont(family, emSize, wfs);

                if (fontGroup == null)
                {
                    lock (this.fonts)
                    {
                        fonts.Add(family.Name, fontGroup = new List <WFFont> {
                            font
                        });
                    }
                    Logger.Log("resource pool", "font resource group added. font groups: " + fonts.Count);
                }
                else
                {
                    lock (fontGroup)
                    {
                        fontGroup.Add(font);
                    }
                    Logger.Log("resource pool", "font resource added. fonts: " + fontGroup.Count);
                }
            }

#if DEBUG
            sw.Stop();
            long ms = sw.ElapsedMilliseconds;
            if (ms > 10)
            {
                Debug.WriteLine("resource pool: font scan: " + sw.ElapsedMilliseconds + " ms.");
            }
#endif // DEBUG
            return(font);
        }
        public void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
        {
            System.Drawing.Font s = (System.Drawing.Font)obj;

            info.SetNodeContent(sm_Converter.ConvertToInvariantString(s));
        }
        /// <summary>
        /// 描画を更新する
        /// </summary>
        public void Refresh()
        {
#if false
            var sw = Stopwatch.StartNew();
#endif
            this.Width = this.BarWidth;

            // Brushを生成する
            var fontColor = string.IsNullOrWhiteSpace(this.FontColor) ?
                            Settings.Default.FontColor.ToWPF() :
                            this.FontColor.FromHTMLWPF();
            var fontOutlineColor = string.IsNullOrWhiteSpace(this.FontOutlineColor) ?
                                   Settings.Default.FontOutlineColor.ToWPF() :
                                   this.FontOutlineColor.FromHTMLWPF();
            var barColor = string.IsNullOrWhiteSpace(this.BarColor) ?
                           Settings.Default.ProgressBarColor.ToWPF() :
                           this.BarColor.FromHTMLWPF();
            var barBackColor    = barColor.ChangeBrightness(0.4d);
            var barOutlineColor = string.IsNullOrWhiteSpace(this.BarOutlineColor) ?
                                  Settings.Default.ProgressBarOutlineColor.ToWPF() :
                                  this.BarOutlineColor.FromHTMLWPF();

            this.FontBrush        = this.CreateBrush(this.FontBrush, fontColor);
            this.FontOutlineBrush = this.CreateBrush(this.FontOutlineBrush, fontOutlineColor);
            this.BarBrush         = this.CreateBrush(this.BarBrush, barColor);
            this.BarBackBrush     = this.CreateBrush(this.BarBackBrush, barBackColor);
            this.BarOutlineBrush  = this.CreateBrush(this.BarOutlineBrush, barOutlineColor);

            // フォントを生成する
            if (this.CachedFont == null ||
                this.CachedFont.Name != this.TextFontFamily ||
                this.CachedFont.Size != this.TextFontSize ||
                this.CachedFont.Style != (System.Drawing.FontStyle) this.TextFontStyle)
            {
                this.CachedFont = new System.Drawing.Font(
                    this.TextFontFamily,
                    this.TextFontSize,
                    (System.Drawing.FontStyle) this.TextFontStyle);
            }

            var tb   = default(OutlineTextBlock);
            var font = this.CachedFont;

            // Titleを描画する
            tb = this.SpellTitleTextBlock;
            var title = string.IsNullOrWhiteSpace(this.SpellTitle) ? " " : this.SpellTitle;
            if (tb.Text != title)
            {
                tb.Text            = title;
                tb.FontFamily      = font.ToFontFamilyWPF();
                tb.FontSize        = font.ToFontSizeWPF();
                tb.FontStyle       = font.ToFontStyleWPF();
                tb.FontWeight      = font.ToFontWeightWPF();
                tb.Fill            = this.FontBrush;
                tb.Stroke          = this.FontOutlineBrush;
                tb.StrokeThickness = 0.2d;
            }

            // リキャスト時間を描画する
            tb = this.RecastTimeTextBlock;
            var recast = this.RecastTime > 0 ?
                         this.RecastTime.ToString("N1") :
                         this.IsReverse ? "Over" : "Ready";
            if (tb.Text != recast)
            {
                tb.Text            = recast;
                tb.FontFamily      = font.ToFontFamilyWPF();
                tb.FontSize        = font.ToFontSizeWPF();
                tb.FontStyle       = font.ToFontStyleWPF();
                tb.FontWeight      = font.ToFontWeightWPF();
                tb.Fill            = this.FontBrush;
                tb.Stroke          = this.FontOutlineBrush;
                tb.StrokeThickness = 0.2d;
            }

            // ProgressBarを描画する
            var foreRect = this.BarRectangle;
            foreRect.Stroke = this.BarBrush;
            foreRect.Fill   = this.BarBrush;
            foreRect.Width  = this.IsReverse ?
                              (double)(this.BarWidth * (1.0d - this.Progress)) :
                              (double)(this.BarWidth * this.Progress);
            foreRect.Height  = this.BarHeight;
            foreRect.RadiusX = 2.0d;
            foreRect.RadiusY = 2.0d;
            Canvas.SetLeft(foreRect, 0);
            Canvas.SetTop(foreRect, 0);

            var backRect = this.BarBackRectangle;
            backRect.Stroke  = this.BarBackBrush;
            backRect.Fill    = this.BarBackBrush;
            backRect.Width   = this.BarWidth;
            backRect.Height  = foreRect.Height;
            backRect.RadiusX = 2.0d;
            backRect.RadiusY = 2.0d;
            Canvas.SetLeft(backRect, 0);
            Canvas.SetTop(backRect, 0);

            var outlineRect = this.BarOutlineRectangle;
            outlineRect.Stroke          = this.BarOutlineBrush;
            outlineRect.StrokeThickness = 1.0d;
            outlineRect.Width           = backRect.Width;
            outlineRect.Height          = foreRect.Height;
            outlineRect.RadiusX         = 2.0d;
            outlineRect.RadiusY         = 2.0d;
            Canvas.SetLeft(outlineRect, 0);
            Canvas.SetTop(outlineRect, 0);

            // バーのエフェクトの色を設定する
            this.BarEffect.Color = this.BarBrush.Color.ChangeBrightness(1.05d);

            this.ProgressBarCanvas.Width  = backRect.Width;
            this.ProgressBarCanvas.Height = backRect.Height;

#if false
            sw.Stop();
            Debug.WriteLine("Spell Refresh -> " + sw.ElapsedMilliseconds.ToString("N0") + "ms");
#endif
        }
        public ActionResult CreatePdf(FormCollection collection)
        {
            // create a PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // create a page in document
            PdfPage page1 = document.AddPage();

            // create the true type fonts that can be used in document text
            System.Drawing.Font sysFont      = new System.Drawing.Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
            PdfFont             pdfFont      = document.CreateFont(sysFont);
            PdfFont             pdfFontEmbed = document.CreateFont(sysFont, true);

            float crtYPos = 20;
            float crtXPos = 5;

            PdfLayoutInfo textLayoutInfo     = null;
            PdfLayoutInfo graphicsLayoutInfo = null;

            #region Layout lines

            PdfText titleTextLines = new PdfText(crtXPos, crtYPos, "Lines:", pdfFontEmbed);
            titleTextLines.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo           = page1.Layout(titleTextLines);

            // advance the Y position in the PDF page
            crtYPos = textLayoutInfo.LastPageRectangle.Bottom + 10;

            // layout a simple line
            PdfLine pdfLine = new PdfLine(new System.Drawing.PointF(crtXPos, crtYPos), new System.Drawing.PointF(crtXPos + 60, crtYPos));
            graphicsLayoutInfo = page1.Layout(pdfLine);

            // layout a thick line
            PdfLine pdfThickLine = new PdfLine(new System.Drawing.PointF(crtXPos + 70, crtYPos), new System.Drawing.PointF(crtXPos + 130, crtYPos));
            pdfThickLine.LineStyle.LineWidth = 3;
            graphicsLayoutInfo = page1.Layout(pdfThickLine);

            // layout a dotted colored line
            PdfLine pdfDottedLine = new PdfLine(new System.Drawing.PointF(crtXPos + 140, crtYPos), new System.Drawing.PointF(crtXPos + 200, crtYPos));
            pdfDottedLine.LineStyle.LineDashPattern = PdfLineDashPattern.Dot;
            pdfDottedLine.ForeColor = System.Drawing.Color.Green;
            graphicsLayoutInfo      = page1.Layout(pdfDottedLine);

            // layout a dashed colored line
            PdfLine pdfDashedLine = new PdfLine(new System.Drawing.PointF(crtXPos + 210, crtYPos), new System.Drawing.PointF(crtXPos + 270, crtYPos));
            pdfDashedLine.LineStyle.LineDashPattern = PdfLineDashPattern.Dash;
            pdfDashedLine.ForeColor = System.Drawing.Color.Green;
            graphicsLayoutInfo      = page1.Layout(pdfDashedLine);

            // layout a dash-dot-dot colored line
            PdfLine pdfDashDotDotLine = new PdfLine(new System.Drawing.PointF(crtXPos + 280, crtYPos), new System.Drawing.PointF(crtXPos + 340, crtYPos));
            pdfDashDotDotLine.LineStyle.LineDashPattern = PdfLineDashPattern.DashDotDot;
            pdfDashDotDotLine.ForeColor = System.Drawing.Color.Green;
            graphicsLayoutInfo          = page1.Layout(pdfDashDotDotLine);

            // layout a thick line with rounded cap style
            PdfLine pdfRoundedLine = new PdfLine(new System.Drawing.PointF(crtXPos + 350, crtYPos), new System.Drawing.PointF(crtXPos + 410, crtYPos));
            pdfRoundedLine.LineStyle.LineWidth    = 5;
            pdfRoundedLine.LineStyle.LineCapStyle = PdfLineCapStyle.RoundCap;
            pdfRoundedLine.ForeColor = System.Drawing.Color.Blue;
            graphicsLayoutInfo       = page1.Layout(pdfRoundedLine);

            // advance the Y position in the PDF page
            crtYPos += 10;

            #endregion

            #region Layout circles

            PdfText titleTextCircles = new PdfText(crtXPos, crtYPos, "Circles:", pdfFontEmbed);
            titleTextCircles.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo             = page1.Layout(titleTextCircles);

            // advance the Y position in the PDF page
            crtYPos = textLayoutInfo.LastPageRectangle.Bottom + 10;

            // draw a simple circle with solid line
            PdfCircle pdfCircle = new PdfCircle(new System.Drawing.PointF(crtXPos + 30, crtYPos + 30), 30);
            page1.Layout(pdfCircle);

            // draw a simple circle with dotted border line
            PdfCircle pdfDottedCircle = new PdfCircle(new System.Drawing.PointF(crtXPos + 100, crtYPos + 30), 30);
            pdfDottedCircle.ForeColor = System.Drawing.Color.Green;
            pdfDottedCircle.LineStyle.LineDashPattern = PdfLineDashPattern.Dot;
            graphicsLayoutInfo = page1.Layout(pdfDottedCircle);

            // draw a circle with colored border line and fill color
            PdfCircle pdfDisc = new PdfCircle(new System.Drawing.PointF(crtXPos + 170, crtYPos + 30), 30);
            pdfDisc.ForeColor  = System.Drawing.Color.Navy;
            pdfDisc.BackColor  = System.Drawing.Color.WhiteSmoke;
            graphicsLayoutInfo = page1.Layout(pdfDisc);

            // draw a circle with thick border line
            PdfCircle pdfThickBorderDisc = new PdfCircle(new System.Drawing.PointF(crtXPos + 240, crtYPos + 30), 30);
            pdfThickBorderDisc.LineStyle.LineWidth = 5;
            pdfThickBorderDisc.BackColor           = System.Drawing.Color.LightSalmon;
            pdfThickBorderDisc.ForeColor           = System.Drawing.Color.LightBlue;

            graphicsLayoutInfo = page1.Layout(pdfThickBorderDisc);

            crtYPos = graphicsLayoutInfo.LastPageRectangle.Bottom + 10;

            #endregion

            #region Layout ellipses and arcs

            PdfText titleTextEllipses = new PdfText(crtXPos, crtYPos, "Ellipses, arcs and slices:", pdfFontEmbed);
            titleTextEllipses.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextEllipses);

            // advance the Y position in the PDF page
            crtYPos = textLayoutInfo.LastPageRectangle.Bottom + 10;

            // draw a simple ellipse with solid line
            PdfEllipse pdfEllipse = new PdfEllipse(new System.Drawing.PointF(crtXPos + 50, crtYPos + 30), 50, 30);
            graphicsLayoutInfo = page1.Layout(pdfEllipse);

            // draw an ellipse with fill color and colored border line
            PdfEllipse pdfFilledEllipse = new PdfEllipse(new System.Drawing.PointF(crtXPos + 160, crtYPos + 30), 50, 30);
            pdfFilledEllipse.BackColor = System.Drawing.Color.WhiteSmoke;
            pdfFilledEllipse.ForeColor = System.Drawing.Color.Green;
            graphicsLayoutInfo         = page1.Layout(pdfFilledEllipse);

            // draw an ellipse arc with colored border line
            PdfEllipseArc pdfEllipseArc1 = new PdfEllipseArc(new System.Drawing.RectangleF(crtXPos + 220, crtYPos, 100, 60), 0, 90);
            pdfEllipseArc1.ForeColor           = System.Drawing.Color.OrangeRed;
            pdfEllipseArc1.LineStyle.LineWidth = 3;
            graphicsLayoutInfo = page1.Layout(pdfEllipseArc1);

            // draw an ellipse arc with fill color and colored border line
            PdfEllipseArc pdfEllipseArc2 = new PdfEllipseArc(new System.Drawing.RectangleF(crtXPos + 220, crtYPos, 100, 60), 90, 90);
            pdfEllipseArc2.ForeColor = System.Drawing.Color.Navy;
            graphicsLayoutInfo       = page1.Layout(pdfEllipseArc2);

            // draw an ellipse arc with fill color and colored border line
            PdfEllipseArc pdfEllipseArc3 = new PdfEllipseArc(new System.Drawing.RectangleF(crtXPos + 220, crtYPos, 100, 60), 180, 90);
            pdfEllipseArc3.ForeColor           = System.Drawing.Color.Green;
            pdfEllipseArc3.LineStyle.LineWidth = 3;
            graphicsLayoutInfo = page1.Layout(pdfEllipseArc3);

            // draw an ellipse arc with fill color and colored border line
            PdfEllipseArc pdfEllipseArc4 = new PdfEllipseArc(new System.Drawing.RectangleF(crtXPos + 220, crtYPos, 100, 60), 270, 90);
            pdfEllipseArc4.ForeColor = System.Drawing.Color.Yellow;
            graphicsLayoutInfo       = page1.Layout(pdfEllipseArc4);


            // draw an ellipse slice
            PdfEllipseSlice pdfEllipseSlice1 = new PdfEllipseSlice(new System.Drawing.RectangleF(crtXPos + 330, crtYPos, 100, 60), 0, 90);
            pdfEllipseSlice1.BackColor = System.Drawing.Color.Coral;
            graphicsLayoutInfo         = page1.Layout(pdfEllipseSlice1);

            // draw an ellipse slice
            PdfEllipseSlice pdfEllipseSlice2 = new PdfEllipseSlice(new System.Drawing.RectangleF(crtXPos + 330, crtYPos, 100, 60), 90, 90);
            pdfEllipseSlice2.BackColor = System.Drawing.Color.LightBlue;
            graphicsLayoutInfo         = page1.Layout(pdfEllipseSlice2);

            // draw an ellipse slice
            PdfEllipseSlice pdfEllipseSlice3 = new PdfEllipseSlice(new System.Drawing.RectangleF(crtXPos + 330, crtYPos, 100, 60), 180, 90);
            pdfEllipseSlice3.BackColor = System.Drawing.Color.LightGreen;
            graphicsLayoutInfo         = page1.Layout(pdfEllipseSlice3);

            // draw an ellipse slice
            PdfEllipseSlice pdfEllipseSlice4 = new PdfEllipseSlice(new System.Drawing.RectangleF(crtXPos + 330, crtYPos, 100, 60), 270, 90);
            pdfEllipseSlice4.BackColor = System.Drawing.Color.Yellow;
            graphicsLayoutInfo         = page1.Layout(pdfEllipseSlice4);

            crtYPos = graphicsLayoutInfo.LastPageRectangle.Bottom + 10;

            #endregion

            #region Layout rectangles

            PdfText titleTextRectangles = new PdfText(crtXPos, crtYPos, "Rectangles:", pdfFontEmbed);
            titleTextRectangles.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextRectangles);

            // advance the Y position in the PDF page
            crtYPos = textLayoutInfo.LastPageRectangle.Bottom + 10;

            // draw a simple rectangle with solid line
            PdfRectangle pdfRectangle = new PdfRectangle(crtXPos, crtYPos, 100, 60);
            graphicsLayoutInfo = page1.Layout(pdfRectangle);

            // draw a rectangle with fill color and colored dotted border line
            PdfRectangle pdfFilledRectangle = new PdfRectangle(crtXPos + 110, crtYPos, 100, 60);
            pdfFilledRectangle.BackColor = System.Drawing.Color.WhiteSmoke;
            pdfFilledRectangle.ForeColor = System.Drawing.Color.Green;
            pdfFilledRectangle.LineStyle.LineDashPattern = PdfLineDashPattern.Dot;
            graphicsLayoutInfo = page1.Layout(pdfFilledRectangle);

            // draw a rectangle with fill color and without border line
            PdfRectangle pdfFilledNoBorderRectangle = new PdfRectangle(crtXPos + 220, crtYPos, 100, 60);
            pdfFilledNoBorderRectangle.BackColor = System.Drawing.Color.LightGreen;
            graphicsLayoutInfo = page1.Layout(pdfFilledNoBorderRectangle);

            // draw a rectangle filled with a thick border line and reounded corners
            PdfRectangle pdfThickBorderRectangle = new PdfRectangle(crtXPos + 330, crtYPos, 100, 60);
            pdfThickBorderRectangle.BackColor               = System.Drawing.Color.LightSalmon;
            pdfThickBorderRectangle.ForeColor               = System.Drawing.Color.LightBlue;
            pdfThickBorderRectangle.LineStyle.LineWidth     = 5;
            pdfThickBorderRectangle.LineStyle.LineJoinStyle = PdfLineJoinStyle.RoundJoin;
            graphicsLayoutInfo = page1.Layout(pdfThickBorderRectangle);

            crtYPos = graphicsLayoutInfo.LastPageRectangle.Bottom + 10;

            #endregion

            #region Layout Bezier curves

            PdfText titleTextBezier = new PdfText(crtXPos, crtYPos, "Bezier curves and polygons:", pdfFontEmbed);
            titleTextBezier.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo            = page1.Layout(titleTextBezier);

            // advance the Y position in the PDF page
            crtYPos = textLayoutInfo.LastPageRectangle.Bottom + 10;

            // the points controlling the Bezier curve
            System.Drawing.PointF pt1 = new System.Drawing.PointF(crtXPos, crtYPos + 50);
            System.Drawing.PointF pt2 = new System.Drawing.PointF(crtXPos + 50, crtYPos);
            System.Drawing.PointF pt3 = new System.Drawing.PointF(crtXPos + 100, crtYPos + 100);
            System.Drawing.PointF pt4 = new System.Drawing.PointF(crtXPos + 150, crtYPos + 50);

            // draw controlling points
            PdfCircle pt1Circle = new PdfCircle(pt1, 2);
            pt1Circle.BackColor = System.Drawing.Color.LightSalmon;
            page1.Layout(pt1Circle);
            PdfCircle pt2Circle = new PdfCircle(pt2, 2);
            pt2Circle.BackColor = System.Drawing.Color.LightSalmon;
            page1.Layout(pt2Circle);
            PdfCircle pt3Circle = new PdfCircle(pt3, 2);
            pt3Circle.BackColor = System.Drawing.Color.LightSalmon;
            page1.Layout(pt3Circle);
            PdfCircle pt4Circle = new PdfCircle(pt4, 2);
            pt4Circle.BackColor = System.Drawing.Color.LightSalmon;
            page1.Layout(pt4Circle);

            // draw the Bezier curve

            PdfBezierCurve bezierCurve = new PdfBezierCurve(pt1, pt2, pt3, pt4);
            bezierCurve.ForeColor           = System.Drawing.Color.LightBlue;
            bezierCurve.LineStyle.LineWidth = 2;
            graphicsLayoutInfo = page1.Layout(bezierCurve);

            #endregion

            #region Layout a polygons

            // layout a polygon without fill color

            // the polygon points
            System.Drawing.PointF[] polyPoints = new System.Drawing.PointF[] {
                new System.Drawing.PointF(crtXPos + 200, crtYPos + 50),
                new System.Drawing.PointF(crtXPos + 250, crtYPos),
                new System.Drawing.PointF(crtXPos + 300, crtYPos + 50),
                new System.Drawing.PointF(crtXPos + 250, crtYPos + 100)
            };

            // draw polygon points
            foreach (System.Drawing.PointF polyPoint in polyPoints)
            {
                PdfCircle pointCircle = new PdfCircle(polyPoint, 2);
                pointCircle.BackColor = System.Drawing.Color.LightSalmon;
                page1.Layout(pointCircle);
            }

            // draw the polygon line
            PdfPolygon pdfPolygon = new PdfPolygon(polyPoints);
            pdfPolygon.ForeColor              = System.Drawing.Color.LightBlue;
            pdfPolygon.LineStyle.LineWidth    = 2;
            pdfPolygon.LineStyle.LineCapStyle = PdfLineCapStyle.ProjectingSquareCap;
            graphicsLayoutInfo = page1.Layout(pdfPolygon);

            // layout a polygon with fill color

            // the polygon points
            System.Drawing.PointF[] polyFillPoints = new System.Drawing.PointF[] {
                new System.Drawing.PointF(crtXPos + 330, crtYPos + 50),
                new System.Drawing.PointF(crtXPos + 380, crtYPos),
                new System.Drawing.PointF(crtXPos + 430, crtYPos + 50),
                new System.Drawing.PointF(crtXPos + 380, crtYPos + 100)
            };

            // draw a polygon with fill color and thick rounded border
            PdfPolygon pdfFillPolygon = new PdfPolygon(polyFillPoints);
            pdfFillPolygon.ForeColor               = System.Drawing.Color.LightBlue;
            pdfFillPolygon.BackColor               = System.Drawing.Color.LightSalmon;
            pdfFillPolygon.LineStyle.LineWidth     = 5;
            pdfFillPolygon.LineStyle.LineCapStyle  = PdfLineCapStyle.RoundCap;
            pdfFillPolygon.LineStyle.LineJoinStyle = PdfLineJoinStyle.RoundJoin;
            graphicsLayoutInfo = page1.Layout(pdfFillPolygon);

            #endregion

            try
            {
                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "PdfGraphics.pdf";

                return(fileResult);
            }
            finally
            {
                document.Close();
            }
        }
Exemplo n.º 53
0
        /// <summary>
        /// Initializes the media events.
        /// </summary>
        private void InitializeMediaEvents()
        {
            Media.MediaOpened     += Media_MediaOpened;
            Media.MediaOpening    += Media_MediaOpening;
            Media.MediaFailed     += Media_MediaFailed;
            Media.MessageLogged   += Media_MessageLogged;
            Media.PropertyChanged += Media_PropertyChanged;
            Unosquare.FFME.MediaElement.FFmpegMessageLogged += MediaElement_FFmpegMessageLogged;

#if HANDLE_RENDERING_EVENTS
            #region Audio and Video Frame Rendering Variables

            System.Drawing.Bitmap   overlayBitmap   = null;
            System.Drawing.Graphics overlayGraphics = null;
            var overlayTextFont      = new System.Drawing.Font("Arial", 14, System.Drawing.FontStyle.Bold);
            var overlayTextFontBrush = System.Drawing.Brushes.WhiteSmoke;
            var overlayTextOffset    = new System.Drawing.PointF(12, 8);
            var overlayBackBuffer    = IntPtr.Zero;

            var vuMeterLeftPen  = new System.Drawing.Pen(System.Drawing.Color.OrangeRed, 12);
            var vuMeterRightPen = new System.Drawing.Pen(System.Drawing.Color.GreenYellow, 12);
            var vuMeterRmsLock  = new object();
            var vuMeterLeftRms  = new SortedDictionary <TimeSpan, double>();
            var vuMeterRightRms = new SortedDictionary <TimeSpan, double>();

            var         vuMeterLeftValue   = 0d;
            var         vuMeterRightValue  = 0d;
            const float vuMeterLeftOffset  = 16;
            const float vuMeterTopOffset   = 50;
            const float vuMeterScaleFactor = 20; // RMS * pixel factor = the length of the VU meter lines

            #endregion

            #region Rendering Event Examples

            Media.RenderingVideo += (s, e) =>
            {
                #region Create the overlay buffer to work with

                if (overlayBackBuffer != e.Bitmap.BackBuffer)
                {
                    lock (vuMeterRmsLock)
                    {
                        vuMeterLeftRms.Clear();
                        vuMeterRightRms.Clear();
                    }

                    if (overlayGraphics != null)
                    {
                        overlayGraphics.Dispose();
                    }
                    if (overlayBitmap != null)
                    {
                        overlayBitmap.Dispose();
                    }

                    overlayBitmap = new System.Drawing.Bitmap(
                        e.Bitmap.PixelWidth, e.Bitmap.PixelHeight, e.Bitmap.BackBufferStride,
                        System.Drawing.Imaging.PixelFormat.Format24bppRgb, e.Bitmap.BackBuffer);

                    overlayBackBuffer = e.Bitmap.BackBuffer;
                    overlayGraphics   = System.Drawing.Graphics.FromImage(overlayBitmap);
                    overlayGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
                }

                #endregion

                #region Read the instantaneous RMS of the audio

                lock (vuMeterRmsLock)
                {
                    vuMeterLeftValue  = vuMeterLeftRms.Where(kvp => kvp.Key > Media.Position).Select(kvp => kvp.Value).FirstOrDefault();
                    vuMeterRightValue = vuMeterRightRms.Where(kvp => kvp.Key > Media.Position).Select(kvp => kvp.Value).FirstOrDefault();

                    // do some cleanup so the dictionary does not grow too big.
                    if (vuMeterLeftRms.Count > 256)
                    {
                        var keysToRemove = vuMeterLeftRms.Keys.Where(k => k < Media.Position).OrderBy(k => k).ToArray();
                        foreach (var k in keysToRemove)
                        {
                            vuMeterLeftRms.Remove(k);
                            vuMeterRightRms.Remove(k);

                            if (vuMeterLeftRms.Count < 256)
                            {
                                break;
                            }
                        }
                    }
                }

                #endregion

                #region Draw the text and the VU meter

                e.Bitmap.Lock();
                var differenceMillis = TimeSpan.FromTicks(e.Clock.Ticks - e.StartTime.Ticks).TotalMilliseconds;

                overlayGraphics.DrawString($"Clock: {e.StartTime.TotalSeconds:00.000} | Skew: {differenceMillis:00.000} | PN: {e.PictureNumber}",
                                           overlayTextFont, overlayTextFontBrush, overlayTextOffset);

                // draw a simple VU meter
                overlayGraphics.DrawLine(vuMeterLeftPen,
                                         vuMeterLeftOffset, vuMeterTopOffset,
                                         vuMeterLeftOffset + 5 + (Convert.ToSingle(vuMeterLeftValue) * vuMeterScaleFactor), vuMeterTopOffset);

                overlayGraphics.DrawLine(vuMeterRightPen,
                                         vuMeterLeftOffset, vuMeterTopOffset + 20,
                                         vuMeterLeftOffset + 5 + (Convert.ToSingle(vuMeterRightValue) * vuMeterScaleFactor), vuMeterTopOffset + 20);

                e.Bitmap.AddDirtyRect(new Int32Rect(0, 0, e.Bitmap.PixelWidth, e.Bitmap.PixelHeight));
                e.Bitmap.Unlock();

                #endregion
            };

            Media.RenderingAudio += (s, e) =>
            {
                // The buffer contains all the samples
                var buffer = new byte[e.BufferLength];
                Marshal.Copy(e.Buffer, buffer, 0, e.BufferLength);

                // We need to split the samples into left and right samples
                var leftSamples  = new double[e.SamplesPerChannel];
                var rightSamples = new double[e.SamplesPerChannel];

                // Iterate through the buffer
                var isLeftSample  = true;
                var sampleIndex   = 0;
                var samplePercent = default(double);

                for (var i = 0; i < e.BufferLength; i += e.BitsPerSample / 8)
                {
                    samplePercent = 100d * Math.Abs((double)((short)(buffer[i] | (buffer[i + 1] << 8)))) / (double)short.MaxValue;

                    if (isLeftSample)
                    {
                        leftSamples[sampleIndex] = samplePercent;
                    }
                    else
                    {
                        rightSamples[sampleIndex] = samplePercent;
                    }

                    sampleIndex += !isLeftSample ? 1 : 0;
                    isLeftSample = !isLeftSample;
                }

                // Compute the RMS of the samples and save it for the given point in time.
                lock (vuMeterRmsLock)
                {
                    // The VU meter should show the audio RMS, we compute it and save it in a dictionary.
                    vuMeterLeftRms[e.StartTime]  = Math.Sqrt((1d / leftSamples.Length) * (leftSamples.Sum(n => n)));
                    vuMeterRightRms[e.StartTime] = Math.Sqrt((1d / rightSamples.Length) * (rightSamples.Sum(n => n)));
                }
            };

            Media.RenderingSubtitles += (s, e) =>
            {
                // a simple example of suffixing subtitles
                if (e.Text != null && e.Text.Count > 0)
                {
                    e.Text[0] = $"{e.Text[0]}\r\n(subtitles)";
                }
            };

            #endregion
#endif
        }
Exemplo n.º 54
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Font"/> class from a <see cref="System.Drawing.Font"/>
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="font">The font.</param>
 public Font(Device device, System.Drawing.Font font)
 {
     D3DX9.CreateFont(device, font.Height, 0, (int)(font.Bold ? FontWeight.Bold : FontWeight.Normal), 0, font.Italic, (int)FontCharacterSet.Default, (int)FontPrecision.Default, (int)FontQuality.Default, (int)FontPitchAndFamily.Default, font.Name, this);
 }
Exemplo n.º 55
0
 /// <summary>
 /// Make various QuestionBoardFooter components conform with MainQuestionBoard's look and feel.
 /// </summary>
 /// <param name="font">QuestionButton Font</param>
 /// <param name="backgroundColor">QuestionButton background Color</param>
 /// <param name="foregroundColor">QuestionButton foreground Color</param>
 abstract public void ApplyQuestionBoardStyle(System.Drawing.Font font, System.Drawing.Color backgroundColor, System.Drawing.Color foregroundColor);
        private void InitializeComponent()
        {
            var dataGridViewCellStyle1 = new DataGridViewCellStyle();
            var resources = new System.ComponentModel.ComponentResourceManager(typeof(SoftSuppliersViewport));

            dataGridView   = new DataGridView();
            idSoftSupplier = new DataGridViewTextBoxColumn();
            softSupplier   = new DataGridViewTextBoxColumn();
            ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
            SuspendLayout();
            //
            // dataGridView
            //
            dataGridView.AllowUserToAddRows            = false;
            dataGridView.AllowUserToDeleteRows         = false;
            dataGridView.AllowUserToResizeRows         = false;
            dataGridView.AutoSizeColumnsMode           = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView.BackgroundColor               = System.Drawing.Color.White;
            dataGridView.BorderStyle                   = BorderStyle.Fixed3D;
            dataGridViewCellStyle1.Alignment           = DataGridViewContentAlignment.MiddleLeft;
            dataGridViewCellStyle1.BackColor           = System.Drawing.SystemColors.Control;
            dataGridViewCellStyle1.Font                = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (byte)204);
            dataGridViewCellStyle1.ForeColor           = System.Drawing.SystemColors.WindowText;
            dataGridViewCellStyle1.Padding             = new Padding(0, 2, 0, 2);
            dataGridViewCellStyle1.SelectionBackColor  = System.Drawing.SystemColors.Highlight;
            dataGridViewCellStyle1.SelectionForeColor  = System.Drawing.SystemColors.HighlightText;
            dataGridViewCellStyle1.WrapMode            = DataGridViewTriState.True;
            dataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
            dataGridView.ColumnHeadersHeightSizeMode   = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            dataGridView.Columns.AddRange(idSoftSupplier, softSupplier);
            dataGridView.Dock          = DockStyle.Fill;
            dataGridView.EditMode      = DataGridViewEditMode.EditOnEnter;
            dataGridView.Location      = new System.Drawing.Point(3, 3);
            dataGridView.MultiSelect   = false;
            dataGridView.Name          = "dataGridView";
            dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView.Size          = new System.Drawing.Size(654, 345);
            dataGridView.TabIndex      = 8;
            //
            // idSoftSupplier
            //
            idSoftSupplier.Frozen     = true;
            idSoftSupplier.HeaderText = "Идентификатор";
            idSoftSupplier.Name       = "idSoftSupplier";
            idSoftSupplier.ReadOnly   = true;
            idSoftSupplier.Visible    = false;
            //
            // softSupplier
            //
            softSupplier.HeaderText   = "Наименование";
            softSupplier.MinimumWidth = 100;
            softSupplier.Name         = "softSupplier";
            //
            // SoftSuppliersViewport
            //
            BackColor  = System.Drawing.Color.White;
            ClientSize = new System.Drawing.Size(660, 351);
            Controls.Add(dataGridView);
            Font    = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (byte)204);
            Icon    = (System.Drawing.Icon)resources.GetObject("$this.Icon");
            Name    = "SoftSuppliersViewport";
            Padding = new Padding(3);
            Text    = "Поставщики ПО";
            ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
            ResumeLayout(false);
        }
Exemplo n.º 57
0
 public ToolStripMenuItemWithChannelOption()
 {
     Font = new System.Drawing.Font("Arial", 16);
 }
Exemplo n.º 58
0
        /// <summary>
        /// Converts a font to a string.
        /// </summary>
        /// <param name="font">Font</param>
        /// <returns>font values as a string</returns>

        public static string ConvertFontToString(System.Drawing.Font font)
        {
            return(string.Format("{0}{3}{1}{3}{2}", font.Name, font.Size.ToString(System.Globalization.CultureInfo.InvariantCulture), font.Style.ToString(), Constants.FONT_SEPARATOR));
        }
Exemplo n.º 59
0
        protected void buttonCreatePdf_Click(object sender, EventArgs e)
        {
            // create a PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // display the outlines when the document is opened
            document.Viewer.PageMode = PdfPageMode.Outlines;

            // create the true type fonts that can be used in document
            System.Drawing.Font sysFont      = new System.Drawing.Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
            PdfFont             pdfFont      = document.CreateFont(sysFont);
            PdfFont             pdfFontEmbed = document.CreateFont(sysFont, true);

            System.Drawing.Font sysFontBold = new System.Drawing.Font("Times New Roman", 12, System.Drawing.FontStyle.Bold,
                                                                      System.Drawing.GraphicsUnit.Point);
            PdfFont pdfFontBold      = document.CreateFont(sysFontBold);
            PdfFont pdfFontBoldEmbed = document.CreateFont(sysFontBold, true);

            System.Drawing.Font sysFontBig = new System.Drawing.Font("Times New Roman", 16, System.Drawing.FontStyle.Bold,
                                                                     System.Drawing.GraphicsUnit.Point);
            PdfFont pdfFontBig      = document.CreateFont(sysFontBig);
            PdfFont pdfFontBigEmbed = document.CreateFont(sysFontBig, true);

            // create a reference Graphics used for measuring
            System.Drawing.Bitmap   refBmp      = new System.Drawing.Bitmap(1, 1);
            System.Drawing.Graphics refGraphics = System.Drawing.Graphics.FromImage(refBmp);
            refGraphics.PageUnit = System.Drawing.GraphicsUnit.Point;

            // create page 1
            PdfPage page1 = document.AddPage();

            float crtXPos = 10;
            float crtYPos = 20;

            #region Create Table of contents

            // create table of contents title
            PdfText tableOfContentsTitle = new PdfText(crtXPos, crtYPos, "Table of Contents", pdfFontBigEmbed);
            page1.Layout(tableOfContentsTitle);

            // create a top outline for the table of contents
            PdfDestination tableOfContentsDest = new PdfDestination(page1, new System.Drawing.PointF(crtXPos, crtYPos));
            document.CreateTopOutline("Table of Contents", tableOfContentsDest);

            // advance current Y position in page
            crtYPos += pdfFontBigEmbed.Size + 10;

            // create Chapter 1 in table of contents
            PdfText chapter1TocTitle = new PdfText(crtXPos + 30, crtYPos, "Chapter 1", pdfFontBoldEmbed);
            // layout the chapter 1 title in TOC
            page1.Layout(chapter1TocTitle);

            // get the bounding rectangle of the chapter 1 title in TOC
            System.Drawing.SizeF      textSize = refGraphics.MeasureString("Chapter 1", sysFontBold);
            System.Drawing.RectangleF chapter1TocTitleRectangle = new System.Drawing.RectangleF(crtXPos + 30, crtYPos, textSize.Width, textSize.Height);

            // advance current Y position in page
            crtYPos += pdfFontEmbed.Size + 10;

            // create Subchapter 1 in table of contents
            PdfText subChapter11TocTitle = new PdfText(crtXPos + 60, crtYPos, "Subchapter 1", pdfFontEmbed);
            // layout the text
            page1.Layout(subChapter11TocTitle);

            // get the bounding rectangle of the subchapter 1 title in TOC
            textSize = refGraphics.MeasureString("Subchapter 1", sysFont);
            System.Drawing.RectangleF subChapter11TocTitleRectangle = new System.Drawing.RectangleF(crtXPos + 60, crtYPos, textSize.Width, textSize.Height);

            // advance current Y position in page
            crtYPos += pdfFontEmbed.Size + 10;

            // create Subchapter 2 in table of contents
            PdfText subChapter21TocTitle = new PdfText(crtXPos + 60, crtYPos, "Subchapter 2", pdfFontEmbed);
            // layout the text
            page1.Layout(subChapter21TocTitle);

            // get the bounding rectangle of the subchapter 2 title in TOC
            textSize = refGraphics.MeasureString("Subchapter 2", sysFont);
            System.Drawing.RectangleF subChapter21TocTitleRectangle = new System.Drawing.RectangleF(crtXPos + 60, crtYPos, textSize.Width, textSize.Height);

            // advance current Y position in page
            crtYPos += pdfFontEmbed.Size + 10;

            // create Chapter 2 in table of contents
            PdfText chapter2TocTitle = new PdfText(crtXPos + 30, crtYPos, "Chapter 2", pdfFontBoldEmbed);
            // layout the text
            page1.Layout(chapter2TocTitle);

            // get the bounding rectangle of the chapter 2 title in TOC
            textSize = refGraphics.MeasureString("Capter 2", sysFontBold);
            System.Drawing.RectangleF chapter2TocTitleRectangle = new System.Drawing.RectangleF(crtXPos + 30, crtYPos, textSize.Width, textSize.Height);

            // advance current Y position in page
            crtYPos += pdfFontEmbed.Size + 10;

            // create Subchapter 1 in table of contents
            PdfText subChapter12TocTitle = new PdfText(crtXPos + 60, crtYPos, "Subchapter 1", pdfFontEmbed);
            // layout the text
            page1.Layout(subChapter12TocTitle);

            // get the bounding rectangle of the subchapter 1 title in TOC
            textSize = refGraphics.MeasureString("Subchapter 1", sysFont);
            System.Drawing.RectangleF subChapter12TocTitleRectangle = new System.Drawing.RectangleF(crtXPos + 60, crtYPos, textSize.Width, textSize.Height);

            // advance current Y position in page
            crtYPos += pdfFontEmbed.Size + 10;

            // create Subchapter 2 in table of contents
            PdfText subChapter22TocTitle = new PdfText(crtXPos + 60, crtYPos, "Subchapter 2", pdfFontEmbed);
            // layout the text
            page1.Layout(subChapter22TocTitle);

            // get the bounding rectangle of the subchapter 2 title in TOC
            textSize = refGraphics.MeasureString("Subchapter 2", sysFont);
            System.Drawing.RectangleF subChapter22TocTitleRectangle = new System.Drawing.RectangleF(crtXPos + 60, crtYPos, textSize.Width, textSize.Height);

            // advance current Y position in page
            crtYPos += pdfFontEmbed.Size + 10;

            // create the website link in the table of contents
            PdfText visitWebSiteText = new PdfText(crtXPos + 30, crtYPos, "Visit HiQPdf Website", pdfFontEmbed);
            visitWebSiteText.ForeColor = System.Drawing.Color.Navy;
            // layout the text
            page1.Layout(visitWebSiteText);

            // get the bounding rectangle of the website link in TOC
            textSize = refGraphics.MeasureString("Visit HiQPdf Website", sysFont);
            System.Drawing.RectangleF visitWebsiteRectangle = new System.Drawing.RectangleF(crtXPos + 30, crtYPos, textSize.Width, textSize.Height);

            // create the link to website in table of contents
            document.CreateUriLink(page1, visitWebsiteRectangle, "http://www.hiqpdf.com");

            // advance current Y position in page
            crtYPos += pdfFontEmbed.Size + 10;

            // create a text note at the end of TOC
            PdfTextNote textNote = document.CreateTextNote(page1, new System.Drawing.PointF(crtXPos + 10, crtYPos),
                                                           "The table of contents contains internal links to chapters and subchapters");
            textNote.IconType = PdfTextNoteIconType.Note;
            textNote.IsOpen   = true;

            #endregion

            #region Create Chapter 1 content and the link from TOC

            // create page 2
            PdfPage page2 = document.AddPage();

            // create the Chapter 1 title
            PdfText chapter1Title = new PdfText(crtXPos, 10, "Chapter 1", pdfFontBoldEmbed);
            // layout the text
            page2.Layout(chapter1Title);

            // create the Chapter 1 root outline
            PdfDestination chapter1Destination = new PdfDestination(page2, new System.Drawing.PointF(crtXPos, 10));
            PdfOutline     chapter1Outline     = document.CreateTopOutline("Chapter 1", chapter1Destination);
            chapter1Outline.TitleColor = System.Drawing.Color.Navy;

            // create the PDF link from TOC to chapter 1
            document.CreatePdfLink(page1, chapter1TocTitleRectangle, chapter1Destination);

            #endregion

            #region Create Subchapter 1 content and the link from TOC

            // create the Subchapter 1
            PdfText subChapter11Title = new PdfText(crtXPos, 300, "Subchapter 1 of Chapter 1", pdfFontEmbed);
            // layout the text
            page2.Layout(subChapter11Title);

            // create subchapter 1 child outline
            PdfDestination subChapter11Destination = new PdfDestination(page2, new System.Drawing.PointF(crtXPos, 300));
            PdfOutline     subchapter11Outline     = document.CreateChildOutline("Subchapter 1", subChapter11Destination, chapter1Outline);

            // create the PDF link from TOC to subchapter 1
            document.CreatePdfLink(page1, subChapter11TocTitleRectangle, subChapter11Destination);

            #endregion

            #region Create Subchapter 2 content and the link from TOC

            // create the Subchapter 2
            PdfText subChapter21Title = new PdfText(crtXPos, 600, "Subchapter 2 of Chapter 1", pdfFontEmbed);
            // layout the text
            page2.Layout(subChapter21Title);

            // create subchapter 2 child outline
            PdfDestination subChapter21Destination = new PdfDestination(page2, new System.Drawing.PointF(crtXPos, 600));
            PdfOutline     subchapter21Outline     = document.CreateChildOutline("Subchapter 2", subChapter21Destination, chapter1Outline);

            // create the PDF link from TOC to subchapter 2
            document.CreatePdfLink(page1, subChapter21TocTitleRectangle, subChapter21Destination);

            #endregion

            #region Create Chapter 2 content and the link from TOC

            // create page 3
            PdfPage page3 = document.AddPage();

            // create the Chapter 2 title
            PdfText chapter2Title = new PdfText(crtXPos, 10, "Chapter 2", pdfFontBoldEmbed);
            // layout the text
            page3.Layout(chapter2Title);

            // create chapter 2 to outline
            PdfDestination chapter2Destination = new PdfDestination(page3, new System.Drawing.PointF(crtXPos, 10));
            PdfOutline     chapter2Outline     = document.CreateTopOutline("Chapter 2", chapter2Destination);
            chapter2Outline.TitleColor = System.Drawing.Color.Green;

            // create the PDF link from TOC to chapter 2
            document.CreatePdfLink(page1, chapter2TocTitleRectangle, chapter2Destination);

            #endregion

            #region Create Subchapter 1 content and the link from TOC

            // create the Subchapter 1
            PdfText subChapter12Title = new PdfText(crtXPos, 300, "Subchapter 1 of Chapter 2", pdfFontEmbed);
            // layout the text
            page3.Layout(subChapter12Title);

            // create subchapter 1 child outline
            PdfDestination subChapter12Destination = new PdfDestination(page3, new System.Drawing.PointF(crtXPos, 300));
            PdfOutline     subchapter12Outline     = document.CreateChildOutline("Subchapter 1", subChapter12Destination, chapter2Outline);

            // create the PDF link from TOC to subchapter 1
            document.CreatePdfLink(page1, subChapter12TocTitleRectangle, subChapter12Destination);

            #endregion

            #region Create Subchapter 2 content and the link from TOC

            // create the Subchapter 2
            PdfText subChapter22Title = new PdfText(crtXPos, 600, "Subchapter 2 of Chapter 2", pdfFontEmbed);
            // layout the text
            page3.Layout(subChapter22Title);

            // create subchapter 2 child outline
            PdfDestination subChapter22Destination = new PdfDestination(page3, new System.Drawing.PointF(crtXPos, 600));
            PdfOutline     subchapter22Outline     = document.CreateChildOutline("Subchapter 2", subChapter22Destination, chapter2Outline);

            // create the PDF link from TOC to subchapter 2
            document.CreatePdfLink(page1, subChapter22TocTitleRectangle, subChapter22Destination);

            #endregion

            // dispose the graphics used for measuring
            refGraphics.Dispose();
            refBmp.Dispose();

            try
            {
                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                // inform the browser about the binary data format
                HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

                // let the browser know how to open the PDF document and the file name
                HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=PdfOutlines.pdf; size={0}",
                                                                                            pdfBuffer.Length.ToString()));

                // write the PDF buffer to HTTP response
                HttpContext.Current.Response.BinaryWrite(pdfBuffer);

                // call End() method of HTTP response to stop ASP.NET page processing
                HttpContext.Current.Response.End();
            }
            finally
            {
                document.Close();
            }
        }
Exemplo n.º 60
0
        /// <summary>
        /// Export a font html element with the specified font and text
        /// </summary>
        /// <param name="p_Writer"></param>
        /// <param name="p_DisplayText"></param>
        /// <param name="p_Font"></param>
        public static void ExportHTML_Element_Font(System.Xml.XmlTextWriter p_Writer, string p_DisplayText, System.Drawing.Font p_Font)
        {
            if (p_Font != null)
            {
                p_Writer.WriteAttributeString("style", "font-size:" + p_Font.SizeInPoints + "pt");

                if (p_Font.Bold)
                {
                    p_Writer.WriteStartElement("b");
                }

                if (p_Font.Underline)
                {
                    p_Writer.WriteStartElement("u");
                }

                if (p_Font.Italic)
                {
                    p_Writer.WriteStartElement("i");
                }
            }

            //displaytext
            if (p_DisplayText == null || p_DisplayText.Trim().Length <= 0)
            {
                p_Writer.WriteRaw("&nbsp;");
            }
            else
            {
                //l_Display = l_Display.Replace("\r\n","<br>");
                p_Writer.WriteString(p_DisplayText);
            }

            if (p_Font != null)
            {
                //i
                if (p_Font.Italic)
                {
                    p_Writer.WriteEndElement();
                }

                //u
                if (p_Font.Underline)
                {
                    p_Writer.WriteEndElement();
                }

                //b
                if (p_Font.Bold)
                {
                    p_Writer.WriteEndElement();
                }
            }
        }