当前位置: 首页>>代码示例>>C#>>正文


C# StringFormat类代码示例

本文整理汇总了C#中StringFormat的典型用法代码示例。如果您正苦于以下问题:C# StringFormat类的具体用法?C# StringFormat怎么用?C# StringFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StringFormat类属于命名空间,在下文中一共展示了StringFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRequest

    /// <summary>
    /// this version outputs gif to web page
    /// ProcessRequest is intrinsic function of hppthandler, do not change the name
    /// </summary>
    /// <param name="context"></param>
    public void ProcessRequest(HttpContext context)
    {
        //for a custom httphandler make sure it's referenced in web.config in httpHandlers
        //<add verb="GET" path="*barcode.gif" type="barcode_handler" validate ="false" />
        //
        if(context.Request["code"] != null){

            string _code = wwi_security.DecryptString(context.Request["code"].ToString(),"publiship"); //code to use
            int _wd = 120; //context.Request["wd"] != null ? wwi_func.vint(context.Request["wd"].ToString()) : 120; //width
            int _ht = 30; //context.Request["ht"] != null ? wwi_func.vint(context.Request["ht"].ToString()) : 30; //height

            Barcode128 _bc = new Barcode128();
            _bc.CodeType = Barcode.CODE128;
            _bc.ChecksumText = true;
            _bc.GenerateChecksum = true;
            _bc.Code = _code;

            //draws directly to web page with no code underneath bar
            //System.Drawing.Bitmap _bm = new System.Drawing.Bitmap(_bc.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
            //_bm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);

            //draws with actual code underneath bar
            //create bitmap from System.Drawing library, add some height for actual code underneath
            Bitmap _bm = new Bitmap(_wd, _ht + 10);
            //provide this, else the background will be black by default
            Graphics _gr = Graphics.FromImage(_bm);
            
            _gr.PageUnit = GraphicsUnit.Pixel;
            _gr.Clear(Color.White); 
            //draw the barcode
            _gr.DrawImage(_bc.CreateDrawingImage(Color.Black, System.Drawing.Color.White), new Point(0,0));
            //place text underneath - if you want the placement to be dynamic, calculate the point based on size of the image
            System.Drawing.Font _ft = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
            SizeF _sz = _gr.MeasureString(_code, _ft); 
            //position text
            _wd = (_wd - (int)_sz.Width) / 2;
            
            StringFormat _sf = new StringFormat();
            _sf.Alignment = StringAlignment.Center;
            _sf.LineAlignment = StringAlignment.Center;

            _gr.DrawString(_code, _ft, SystemBrushes.WindowText,_wd,_ht, _sf);
            //output as gif to web page,  can also save it to external file
            _bm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
        }//end if
    }
开发者ID:Publiship,项目名称:WWI_CRM_folders,代码行数:51,代码来源:barcode_handler.cs

示例2: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        // Since we are outputting a Jpeg, set the ContentType appropriately
        Response.ContentType = "image/jpeg";    // Create a Bitmap instance that's 468x60, and a Graphics instance
        const int width = 480, height = 270;
        Bitmap objBitmap = new Bitmap(width, height);
        Graphics objGraphics = Graphics.FromImage(objBitmap);

        // Create a white background
        objGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height);
        objGraphics.DrawRectangle(new Pen(Color.Black, 1), 0, 0, width - 1, height - 1);

        //// Create a LightBlue background
        //objGraphics.FillRectangle(new SolidBrush(Color.LightBlue), 5, 5,
        //    width - 10, height - 10);

        //// Create the advertising pitch
        Font fontBanner = new Font("Verdana", 10, FontStyle.Regular);
        StringFormat stringFormat = new StringFormat();

        //// center align the advertising pitch
        stringFormat.Alignment = StringAlignment.Center;
        stringFormat.LineAlignment = StringAlignment.Center;

        String label = "Chart for: " + PersonInfo.SelectedRecord.Name.ToString();
        objGraphics.DrawString(label, fontBanner, new SolidBrush(Color.Black), new Rectangle(0, 0, width, height/10), stringFormat);

        // Save the image to the OutputStream
        objBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);

        // clean up...
        objGraphics.Dispose();
        objBitmap.Dispose();
    }
开发者ID:miguel69,项目名称:Health-e,代码行数:34,代码来源:GenerateChart.aspx.cs

示例3: ApplyTextWatermark

    protected override void ApplyTextWatermark(ImageProcessingActionExecuteArgs args, Graphics g)
    {
        // Draw a filled rectangle
        int rectangleWidth = 14;
        using (Brush brush = new SolidBrush(Color.FromArgb(220, Color.Red)))
        {
            g.FillRectangle(brush, new Rectangle(args.Image.Size.Width - rectangleWidth, 0, rectangleWidth, args.Image.Size.Height));
        }

        using (System.Drawing.Drawing2D.Matrix transform = g.Transform)
        {
            using (StringFormat stringFormat = new StringFormat())
            {
                // Vertical text (bottom -> top)
                stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
                transform.RotateAt(180F, new PointF(args.Image.Size.Width / 2, args.Image.Size.Height / 2));
                g.Transform = transform;

                // Align: top left, +2px displacement 
                // (because of the matrix transformation we have to use inverted values)
                base.ContentAlignment = ContentAlignment.MiddleLeft;
                base.ContentDisplacement = new Point(-2, -2);

                base.ForeColor = Color.White;
                base.Font.Size = 10;

                // Draw the string by invoking the base Apply method
                base.StringFormat = stringFormat;
                base.ApplyTextWatermark(args, g);
                base.StringFormat = null;
            }
        }
    }
开发者ID:Gordon-from-Blumberg,项目名称:Piczard.Examples,代码行数:33,代码来源:MyInheritedFilter.cs

示例4: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "image/jpeg";
        Response.Clear();

        string s = DLL.SessionFacade.ConfirmCode;

        Font f = new Font("Times New Roman", 26, FontStyle.Italic | FontStyle.Bold, GraphicsUnit.Pixel);
        StringFormat format = new StringFormat();
        format.Alignment = StringAlignment.Center;
        format.LineAlignment = StringAlignment.Center;

        Bitmap bmp = new Bitmap(110, 40, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        Graphics g = Graphics.FromImage(bmp);
        g.Clear(Color.White);

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

        g.DrawString(s, f, Brushes.Black, new RectangleF(0, 0, bmp.Width, bmp.Height), format);
        /*
        for (int i = -2; i < bmp.Width / 10; i++)
        {
            g.DrawLine(Pens.OrangeRed, i * 10, 0, i * 10 + 20, bmp.Height);
        }
        for (int i = -2; i < bmp.Width / 10 + 10; i++)
        {
            g.DrawLine(Pens.Blue, i * 10, 0, i * 10 - 60, bmp.Height);
        }
        */
        g.Dispose();

        bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
    }
开发者ID:sqzhuyi,项目名称:cnopenblog,代码行数:34,代码来源:Captcha.aspx.cs

示例5: Decrypt

        /// <summary>
        /// Returns <paramref name="data"/> decrypted based on encryption original <paramref name="stringFormat"/>, <paramref name="key"/> and <paramref name="encryptionProvider"/>.
        /// </summary>
        public static string Decrypt(string data, string key, EncryptionProvider encryptionProvider, StringFormat stringFormat)
        {
            Argument.IsNotNull(data, "data");
            Argument.IsNotNull(key, "key");

            var encryptionAlgorithm = GetEncryptionAlgorithm(encryptionProvider);

            var dataBytes = Util.StringToBytes(data, stringFormat, defaultEncoding).ToArray();

            encryptionAlgorithm.Key = CreateCryptoKey(encryptionAlgorithm, key);
            encryptionAlgorithm.IV = CreateCryptoIv(encryptionAlgorithm, DefaultInitializationVector);

            var result = new byte[dataBytes.Length];

            using (var ms = new MemoryStream(dataBytes, 0, dataBytes.Length))
            {
                using (var cs = new CryptoStream(ms, encryptionAlgorithm.CreateDecryptor(), CryptoStreamMode.Read))
                {
                    cs.Read(result, 0, dataBytes.Length);
                }
            }

            // Clean trailing zeros.
            result = Util.CleanBytes(result).ToArray();

            return Util.BytesToTextString(result, defaultEncoding);
        }
开发者ID:hudo,项目名称:SwissKnife,代码行数:30,代码来源:EncryptionHelper.cs

示例6: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        string monthString = Request.QueryString["Month"];

        if (String.IsNullOrEmpty(monthString))
        {
            monthString = "201004";
        }

        int year = Int32.Parse(monthString.Substring(0, 4));
        int month = Int32.Parse(monthString.Substring(4));  // never mind input checking
        Organization organization = Organization.PPSE;

        monthString = new DateTime(year, month, 1).ToString("MMMM yyyy", new CultureInfo("sv-SE"));

        SalaryTaxData data = GetSalaryData(year, month, organization);

        Response.ContentType = "image/jpeg";

        Image form = Image.FromFile(MapPath("/Data/ImageTemplates/salarytaxes-se.png"));

        using (Graphics graphics = Graphics.FromImage(form))
        {
            StringFormat rightAlign = new StringFormat();
            rightAlign.Alignment = StringAlignment.Far;

            Font fontHandwriting = new Font("Courier New", 64, FontStyle.Bold);
            Font fontPreprinted = new Font("Courier New", 30, FontStyle.Bold);

            Brush brushHandwriting = Brushes.Blue;
            Brush brushPreprinted = Brushes.Red;

            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            graphics.DrawString(organization.Name, fontPreprinted, brushPreprinted, 150, 170);
            graphics.DrawString(monthString, fontPreprinted, brushPreprinted, 680, 292);
            graphics.DrawString(monthString, fontPreprinted, brushPreprinted, 620, 1460);
            graphics.DrawString(String.Format("{0,4}-{1:D2}-{2:D2}", year, month+1, 12), fontPreprinted, brushPreprinted, 820, 160);
            graphics.DrawString("802430-4514", fontPreprinted, brushPreprinted, 1110, 160);

            graphics.DrawString(data.SalaryTotal.ToString("F0"), fontHandwriting, brushHandwriting, 792, 358, rightAlign); // Salary total sub
            graphics.DrawString(data.SalaryTotal.ToString("F0"), fontHandwriting, brushHandwriting, 792, 558, rightAlign); // Salary total total
            graphics.DrawString(data.SalaryMain.ToString("F0"), fontHandwriting, brushHandwriting, 792, 692, rightAlign); // Salary age main
            graphics.DrawString(data.SalaryTotal.ToString("F0"), fontHandwriting, brushHandwriting, 792, 1524, rightAlign); // Salary total again
            graphics.DrawString(data.SalaryTotal.ToString("F0"), fontHandwriting, brushHandwriting, 792, 1725, rightAlign); // Salary total again
            graphics.DrawString(data.TaxAdditiveMain.ToString("F0"), fontHandwriting, brushHandwriting, 1510, 692, rightAlign); // Emp fee main
            graphics.DrawString(data.TaxAdditiveTotal.ToString("F0"), fontHandwriting, brushHandwriting, 1510, 1326, rightAlign); // Emp fee total
            graphics.DrawString(data.TaxSubtractive.ToString("F0"), fontHandwriting, brushHandwriting, 1510, 1525, rightAlign); // Deducted main
            graphics.DrawString(data.TaxSubtractive.ToString("F0"), fontHandwriting, brushHandwriting, 1510, 1726, rightAlign); // Deducted total
            graphics.DrawString(data.TaxTotal.ToString("F0"), fontHandwriting, brushHandwriting, 1510, 1793, rightAlign); // Tax cost total
        }

        using (Stream responseStream = Response.OutputStream)
        {
            form.Save(responseStream, ImageFormat.Jpeg);
        }


    }
开发者ID:SwarmCorp,项目名称:Swarmops,代码行数:60,代码来源:ViewSalariesTaxMonthlyForm.aspx.cs

示例7: Encrypt

        /// <summary>
        /// Returns <paramref name="data"/> encrypted in target <paramref name="stringFormat"/> based on <paramref name="key"/> and <paramref name="encryptionProvider"/>.
        /// </summary>
        public static string Encrypt(string data, string key, EncryptionProvider encryptionProvider, StringFormat stringFormat)
        {
            Argument.IsNotNull(data, "data");
            Argument.IsNotNull(key, "key");

            var encryptionAlgorithm = GetEncryptionAlgorithm(encryptionProvider);

            var dataBytes = defaultEncoding.GetBytes(data);

            encryptionAlgorithm.Key = CreateCryptoKey(encryptionAlgorithm, key);
            encryptionAlgorithm.IV = CreateCryptoIv(encryptionAlgorithm, DefaultInitializationVector);

            string result;

            using (var ms = new MemoryStream())
            {
                using (var cs = new CryptoStream(ms, encryptionAlgorithm.CreateEncryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(dataBytes, 0, dataBytes.Length);
                }

                result = Util.BytesToString(ms.ToArray(), stringFormat);
            }

            return result;
        }
开发者ID:hudo,项目名称:SwissKnife,代码行数:29,代码来源:EncryptionHelper.cs

示例8: StringFormat

        public StringFormat(StringFormat format)
        {
            if (format == null)
                throw new ArgumentNullException ("format");

            Alignment = format.Alignment;
            LineAlignment = format.LineAlignment;
            FormatFlags = format.FormatFlags;
        }
开发者ID:asfungithub,项目名称:sysdrawing-coregraphics,代码行数:9,代码来源:StringFormat.cs

示例9: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        string referenceString = Request.QueryString["Reference"];
        string cultureString = Request.QueryString["Culture"];

        cultureString = cultureString.Substring(0, 2).ToLowerInvariant() + "-" +
                        cultureString.Substring(2).ToUpperInvariant();
        CultureInfo culture = new CultureInfo(cultureString);

        OutboundInvoice invoice = OutboundInvoice.FromReference(referenceString);
        Organization organization = invoice.Organization;

        Response.ContentType = "image/jpeg";
        Image form = Image.FromFile(MapPath("~/Data/ImageTemplates/PPSE-invoice-" + culture + ".png"));

        using (Graphics graphics = Graphics.FromImage(form))
        {
            StringFormat rightAlign = new StringFormat();
            rightAlign.Alignment = StringAlignment.Far;

            Font fontLarge = new Font("Liberation Mono", 12, FontStyle.Bold);
            Font fontMedium = new Font("Liberation Mono", 10, FontStyle.Bold);
            Font fontNormal = new Font("Liberation Mono", 10, FontStyle.Regular);

            Brush brushPrint = Brushes.Blue;

            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            graphics.DrawString(invoice.Amount.ToString("N2", culture), fontLarge, brushPrint, 650, 378);
            graphics.DrawString(invoice.DueDate.ToShortDateString(), fontLarge, brushPrint, 650, 445);
            graphics.DrawString(invoice.Reference, fontLarge, brushPrint, 650, 512);

            graphics.DrawString(invoice.TheirReference, fontMedium, brushPrint, 650, 657);

            graphics.DrawString(invoice.CustomerName, fontMedium, brushPrint, 1500, 378);
            graphics.DrawString(invoice.InvoiceAddressPaper, fontNormal, brushPrint, 1500, 430);

            int yPos = 960;

            foreach (OutboundInvoiceItem item in invoice.Items)
            {
                graphics.DrawString(item.Description, fontNormal, brushPrint, 104, yPos);
                graphics.DrawString(item.Amount.ToString("N2", culture), fontNormal, brushPrint, 2333, yPos, rightAlign);
                yPos += 60;
            }

            graphics.DrawString(invoice.Amount.ToString("N2", culture), fontMedium, brushPrint, 2333, 2940, rightAlign);
        }

        using (Stream responseStream = Response.OutputStream)
        {
            form.Save(responseStream, ImageFormat.Jpeg);
        }


    }
开发者ID:SwarmCorp,项目名称:Swarmops,代码行数:57,代码来源:DisplayOutboundInvoice.aspx.cs

示例10: OnPaint

    protected override void OnPaint(PaintEventArgs pea)
    {
        Graphics grfx = pea.Graphics;
        StringFormat strfmt = new StringFormat();

        strfmt.Alignment = strfmt.LineAlignment = StringAlignment.Center;

        grfx.DrawString("Click to print", Font, new SolidBrush(ForeColor),
            ClientRectangle, strfmt);
    }
开发者ID:dbremner,项目名称:hycs,代码行数:10,代码来源:helloPrinter.cs

示例11: Button_Click

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // get stream to save to
            var dlg = new SaveFileDialog();
            dlg.DefaultExt = ".pdf";
            var dr = dlg.ShowDialog();
            if (!dr.HasValue || !dr.Value)
            {
                return;
            }

            // get sender button
            var btn = sender as Button;

            // create document
            var pdf = new C1PdfDocument(PaperKind.Letter);
            pdf.Clear();

            // set document info
            var di = pdf.DocumentInfo;
            di.Author = "ComponentOne";
            di.Subject = "C1.WPF.Pdf demo.";
            di.Title = "Experimental VisualTree Exporter for PDF";

            // walk visual tree
            CreateDocumentVisualTree(pdf, content);

            // render footers
            // this reopens each page and adds content to them (now we know the page count).
            var font = new Font("Arial", 8, PdfFontStyle.Bold);
            var fmt = new StringFormat();
            fmt.Alignment = HorizontalAlignment.Right;
            fmt.LineAlignment = VerticalAlignment.Bottom;
            for (int page = 0; page < pdf.Pages.Count; page++)
            {
                pdf.CurrentPage = page;
                var text = string.Format("C1.WPF.Pdf: {0}, page {1} of {2}",
                    di.Title,
                    page + 1,
                    pdf.Pages.Count);
                pdf.DrawString(
                    text,
                    font,
                    Colors.DarkGray,
                    PdfUtils.Inflate(pdf.PageRectangle, -72, -36),
                    fmt);
            }

            // save document
            using (var stream = dlg.OpenFile())
            {
                pdf.Save(stream);
            }
            MessageBox.Show("Pdf Document saved to " + dlg.SafeFileName);
        }
开发者ID:mdjabirov,项目名称:C1Decompiled,代码行数:55,代码来源:VisualTree.xaml.cs

示例12: TextLineIterator

		internal TextLineIterator(string s, Font font, font.FontRenderContext frc, StringFormat format, float width, float height) {
			_format = (format != null) ? format : new StringFormat();
			_font = font;
			_s = (s != null) ? s : String.Empty;
			_frc = frc;
			FontFamily ff = font.FontFamily;
			_margin = font.Size*ff.GetDrawMargin(font.Style)/ff.GetEmHeight(font.Style);

			_width = width;
			_height = height;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:11,代码来源:TextLineIterator.jvm.cs

示例13: StringToBytes

 internal static IEnumerable<byte> StringToBytes(string input, StringFormat stringFormat, Encoding encoding)
 {
     switch (stringFormat)
     {
         case StringFormat.Base64:
             return Base64ToBytes(input);
         case StringFormat.Hex:
             return HexToBytes(input);
         default:
             return TextToBytes(input, encoding);
     }
 }
开发者ID:hudo,项目名称:SwissKnife,代码行数:12,代码来源:Util.cs

示例14: BytesToString

 internal static string BytesToString(IEnumerable<byte> value, StringFormat stringFormat, Encoding encoding)
 {
     switch (stringFormat)
     {
         case StringFormat.Base64:
             return BytesToBase64String(value);
         case StringFormat.Hex:
             return BytesToHexString(value);
         default:
             return BytesToTextString(value, encoding);
     }
 }
开发者ID:hudo,项目名称:SwissKnife,代码行数:12,代码来源:Util.cs

示例15: MainForm_Paint

	void MainForm_Paint (object o, PaintEventArgs args)
	{
		StringFormat format = new StringFormat ();
		format.Alignment = StringAlignment.Center;
		string text = "this is really long text........................................... with a lot o periods.";
		SizeF sz = args.Graphics.MeasureString (text, Font, 80, format);
		Rectangle bounds = new Rectangle (60, 8, 80, 80);
		args.Graphics.DrawString (text, Font, SystemBrushes.ControlText, bounds, format);

		bounds.Height = (int) sz.Height;
		args.Graphics.DrawRectangle (new Pen (Color.Black), bounds);
	}
开发者ID:mono,项目名称:gert,代码行数:12,代码来源:MainForm.cs


注:本文中的StringFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。