如何检测在C#中的线串溢出? [英] How to detect a string-overflow from a line in C#?

查看:129
本文介绍了如何检测在C#中的线串溢出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何换 - 在C#中,当我在一条线上的在这个网址。不幸的是,我没有足够的声誉问OP直接有关的有一个具体的问题我有(最有可能的人处理这将无限期有)

I wanted to know how to word-wrap in C# when I came across a very good solution to my problem on word-wrapping text in a line in this URL. Unfortunately, I do not have enough reputations to ask the OP directly about one specific problem I am having(and most likely people dealing with this will be having indefinitely)

问题描述:

我可以自动换行一个字符串,如果它需要自动换行,此代码:

Problem Description:
I can word-wrap a string if it needs to be word-wrapped with this code:

Graphics PAddress = e.Graphics;

SizeF PAddressLength = PAddress.MeasureString("Residential Address: " + RAddressTextBox.Text, new Font(fontface, fontsize, FontStyle.Regular),700);

PAddress.DrawString("Residential Address: "+PAddressLength + RAddressTextBox.Text, new Font(fontface, fontsize, FontStyle.Regular), Brushes.Black, new RectangleF(new Point(pagemarginX, newline()),PAddressLength),StringFormat.GenericTypographic);



不过,我找不到地方接收触发每当字长从单一的溢出。行

However, I could not find the place to receive a trigger whenever the word-length overflows from a single line.

例如:

LINE-2的代码每当字长超过 700像素,它移动到下一行。它是通过跟随的RectangleF来换行。它是这样做的自动,这是一个问题,因为这使得它很难知道是否已经越过700像素或没有。

这是

for example:
In LINE-2 of that code, whenever the wordlength exceeds 700px, it moves to the next line. It does that by following the RectangleF to wordwrap. It is doing so automatically, which is a problem since that makes it difficult to know whether it has crossed 700px or not.

This is the format in which information is displayed whenever I tried to print PAddressLength:

{宽度= 633.1881,身高= 47.14897:其中,每当我试图打印的 PAddressLength 显示格式信息}

{Width=633.1881, Height=47.14897}

我在想,如果我可以从使用PAddressLength.Width,那么我可以部分解决这个问题提取宽度值。但是,我会需要计算如果剩余空间(即700像素 - 633.1881px)将容纳下一个字或不(如果有一个)

I am thinking that If I can extract the value of width from that using PAddressLength.Width ,then I can partially solve this problem. But with that, I will need to calculate if the remaining space(i.e 700px - 633.1881px ) will accommodate the next word or not(if there is one)

<强>打破问题:


  • 我的的知道如何自动换行当有一个字符串比使用 Graphics.MeasureString <指定更长/ A>如该解决方案

  • 但是,这^过程自动发生,所以我想知道的如何检测是否自动换行已发生(怎么可能行已经包裹着每条线为700像素宽度最大值)

  • 我需要为知道有才能知道的次数来执行被包裹的行数行()函数,我写的,这给相应的行间距在每次执行。

  • I already know how to word-wrap when there is a string longer than what specify by using Graphics.MeasureString as given in this solution in another question.
  • But that^ process happens automatically, so I want to know how to detect if the word-wrap has occured(and how may lines it has wrapped with each line being 700px width maximum)
  • I need to know the number of lines that have been wrapped in order to know the number of times to execute newline() function that I wrote, which gives appropriate line spacing upon executing each time.

此外,奖金的问题;可能或maynot解决的)有一些方法来提取值的 633.1881 ,然后计算出下一个单词是否(700适合 - 633.1881)PX 空间或不?

ADDITIONALLY, (bonus question; may or maynot solve) Is there some way to extract the value 633.1881 and then calculate whether the next word fits in ( 700 - 633.1881 )px space or not?

推荐答案

有一个超载MeasureString返回在输出参数使用的行数:的 https://msdn.microsoft.com/en-us/library/957webty %28V = vs.110%29.aspx

There is an overload to MeasureString that returns the number of lines used in an out parameter: https://msdn.microsoft.com/en-us/library/957webty%28v=vs.110%29.aspx

这篇关于如何检测在C#中的线串溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆