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


C# SizeF.ToSize方法代码示例

本文整理汇总了C#中System.Drawing.SizeF.ToSize方法的典型用法代码示例。如果您正苦于以下问题:C# SizeF.ToSize方法的具体用法?C# SizeF.ToSize怎么用?C# SizeF.ToSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.SizeF的用法示例。


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

示例1: CreateBarcode

        private static Bitmap CreateBarcode(String data)
        {
            data = data.ToUpper();

            if (data.Length > 0)
            {
                if (data[0] != '*')
                {
                    data = "*" + data;
                }

                if (data[data.Length - 1] != '*')
                {
                    data = data + "*";
                }
            }

            Bitmap barCode = new Bitmap(1, 1);

            System.Drawing.Font threeOfNine = new System.Drawing.Font("Free 3 of 9", 240, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
            System.Drawing.Font timesNR = new System.Drawing.Font("Times New Roman", 80, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);

            Graphics graphics = Graphics.FromImage(barCode);

            SizeF dataSize = new SizeF();

            SizeF dataSize_bar = graphics.MeasureString(data, threeOfNine);
            SizeF dataSize_text = graphics.MeasureString(data, timesNR);

            if (dataSize_bar.Width > dataSize_text.Width)
            {
                dataSize.Width = dataSize_bar.Width;
            }
            else
            {
                dataSize.Width = dataSize_text.Width;
            }

            dataSize.Height = (dataSize_bar.Height + dataSize_text.Height);

            barCode = new Bitmap(barCode, dataSize.ToSize());

            graphics = Graphics.FromImage(barCode);

            graphics.Clear(Color.White);

            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;

            graphics.DrawString(data, threeOfNine, new SolidBrush(Color.Black), ((dataSize.Width/2f)-(dataSize_bar.Width/2f)), 0);
            graphics.DrawString(data, timesNR, new SolidBrush(Color.Black), ((dataSize.Width / 2f) - (dataSize_text.Width / 2f)), dataSize_bar.Height);

            graphics.Flush();

            threeOfNine.Dispose();

            graphics.Dispose();

            return barCode;
        }
开发者ID:althor880,项目名称:Barcode_Generator,代码行数:59,代码来源:Program.cs

示例2: GetWidth

		// 根据Font,得到字符串的宽度
		// parameter:
		//		g	Graphics对象
		//		font	Font对象
		//		strText	字符串
		// return:
		//		字符串的宽度
		public static int GetWidth(Graphics g,
			Font font,
			string strText)
		{
			SizeF sizef = new SizeF();
			sizef = g.MeasureString(
				strText,
				font);
			return sizef.ToSize().Width + 6;    // 微调
		}
开发者ID:paopaofeng,项目名称:dp2,代码行数:17,代码来源:GraphicsUtil.cs

示例3: timer1_Tick

        private void timer1_Tick(object sender, EventArgs e)
        {
            //Thread.Sleep(100);
            label3.Text = load + l1;
            if (i < 10)
            {
                label2.Text = "0" + i.ToString();
            }
            else
            {
                label2.Text = i.ToString();
            }

            int r = random.Next(100, 150);
            int g = random.Next(50, 100);
            int b = random.Next(150, 250);

            SizeF s = new SizeF(textBox2.Size.Width + 2, textBox2.Size.Height);
            textBox2.Size = s.ToSize();

            if (i % 5 == 0)
            {

                textBox2.BackColor = Color.FromArgb(r, g, b);
                label1.ForeColor = Color.FromArgb(b, r, g);
                textBox1.BackColor = Color.FromArgb(g, b, r);
                label3.Text = load + l2;
            }
            textBox2.Update();
            label1.Update();
            textBox1.Update();
            label3.Update();
            Thread.Sleep(100);
            if (textBox2.Size.Width >= textBox1.Size.Width)
            {
                timer1.Stop();
                Thread.Sleep(1000);
                this.Hide();
                main.ShowDialog();
            }
            i++;
        }
开发者ID:rahulpandroid,项目名称:test,代码行数:42,代码来源:frm_Welcome.cs

示例4: CalculateMinimumSize

        private Size CalculateMinimumSize()
        {
            using ( Graphics g = Graphics.FromHwnd( Handle ) )
             {
            _sizeText = g.MeasureString( Text, Font, -1, _stringFormat );
             }

             // MeasureString() cuts off the bottom pixel for descenders no matter
             // which StringFormatFlags are chosen
             //
             _sizeText.Height += 1F;

             return _sizeText.ToSize();
        }
开发者ID:EddyBeaupre,项目名称:WinCDP-GUI,代码行数:14,代码来源:SeparatorControl.cs

示例5: OnPaint

        protected override void OnPaint(PaintEventArgs e)
        {
            if (target == null)
                return;
            if (scale <= float.Epsilon)
                return;

            //calc startPlace
            var r = target.VisibleRange;
            if (startPlace.iLine > r.Start.iLine)
                startPlace.iLine = r.Start.iLine;
            else
            {
                var endP = target.PlaceToPoint(r.End);
                endP.Offset(0, -(int)(ClientSize.Height / scale) + target.CharHeight);
                var pp = target.PointToPlace(endP);
                if (pp.iLine > startPlace.iLine)
                    startPlace.iLine = pp.iLine;
            }
            startPlace.iChar = 0;
            //calc scroll pos
            var linesCount = target.Lines.Count;
            var sp1 = (float)r.Start.iLine / linesCount;
            var sp2 = (float)r.End.iLine / linesCount;

            //scale graphics
            e.Graphics.ScaleTransform(scale, scale);
            //draw text
            var size = new SizeF(ClientSize.Width / scale, ClientSize.Height / scale);
            target.DrawText(e.Graphics, startPlace, size.ToSize());

            //draw visible rect
            var p0 = target.PlaceToPoint(startPlace);
            var p1 = target.PlaceToPoint(r.Start);
            var p2 = target.PlaceToPoint(r.End);
            var y1 = p1.Y - p0.Y;
            var y2 = p2.Y + target.CharHeight - p0.Y;

            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

            using (var brush = new SolidBrush(Color.FromArgb(50, ForeColor)))
            using (var pen = new Pen(brush, 1 / scale))
            {
                var rect = new Rectangle(0, y1, (int)((ClientSize.Width - 1) / scale), y2 - y1);
                e.Graphics.FillRectangle(brush, rect);
                e.Graphics.DrawRectangle(pen, rect);
            }

            //draw scrollbar
            if (scrollbarVisible)
            {
                e.Graphics.ResetTransform();
                e.Graphics.SmoothingMode = SmoothingMode.None;

                using (var brush = new SolidBrush(Color.FromArgb(200, ForeColor)))
                {
                    var rect = new RectangleF(ClientSize.Width - 3, ClientSize.Height*sp1, 2,
                                              ClientSize.Height*(sp2 - sp1));
                    e.Graphics.FillRectangle(brush, rect);
                }
            }

            needRepaint = false;
        }
开发者ID:huoxudong125,项目名称:FastColoredTextBox,代码行数:64,代码来源:DocumentMap.cs

示例6: OnHandleCreated

		protected override void OnHandleCreated(EventArgs e)
		{
			if ( builder.Length > 0 )
			{
				this.exactSize = MeasureString( builder.ToString() );
				this.AutoScrollMinSize = exactSize.ToSize();
			}

			this.OnFontChanged(e);

			base.OnHandleCreated (e);
		}
开发者ID:kobida,项目名称:nunitv2,代码行数:12,代码来源:SimpleTextDisplay.cs

示例7: Write

		public void Write( string text )
		{
			int lengthSoFar = builder.Length;

			builder.Append( text );

			if ( this.IsHandleCreated )
			{
				bool isUpdateVisible = this.AutoScrollPosition.Y + this.AutoScrollMinSize.Height <= this.ClientRectangle.Height;

				if ( text != null && lengthSoFar > 0 && builder[lengthSoFar-1] == '\n' ) // use fast path
				{

					SizeF textSize = MeasureString( text );
					this.exactSize = new SizeF( 
						Math.Max( this.exactSize.Width, textSize.Width ),
						this.exactSize.Height + textSize.Height - this.fastPathHeightAdjust );
					this.AutoScrollMinSize = exactSize.ToSize();
				}
				else
				{
					this.exactSize = MeasureString( builder.ToString() );
					this.AutoScrollMinSize = exactSize.ToSize();
				}
				
				if ( isUpdateVisible ) this.Invalidate();
			}
		}
开发者ID:kobida,项目名称:nunitv2,代码行数:28,代码来源:SimpleTextDisplay.cs

示例8: CreateLabel

        private static Bitmap CreateLabel(String data)
        {
            data = data.ToUpper();

            Bitmap docTypeLabel = new Bitmap(1, 1);

            System.Drawing.Font timesNR = new System.Drawing.Font("Times New Roman", 80, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);

            Graphics graphics = Graphics.FromImage(docTypeLabel);

            SizeF dataSize = new SizeF();

            SizeF dataSize_text = graphics.MeasureString(data, timesNR);

            dataSize.Width = dataSize_text.Width;

            dataSize.Height = dataSize_text.Height;

            docTypeLabel = new Bitmap(docTypeLabel, dataSize.ToSize());

            graphics = Graphics.FromImage(docTypeLabel);

            graphics.Clear(Color.White);

            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;

            graphics.DrawString(data, timesNR, new SolidBrush(Color.Black), ((dataSize.Width / 2f) - (dataSize_text.Width / 2f)), 0);

            graphics.Flush();

            timesNR.Dispose();

            graphics.Dispose();

            return docTypeLabel;
        }
开发者ID:althor880,项目名称:Barcode_Generator,代码行数:36,代码来源:OnBase_Barcodes_Parent.cs


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