vb.net - MeasureText() - SizeF 到英寸

我想我不知道要使用什么搜索词,这应该很简单...我用什么来确定字符串的宽度(以英寸为单位)。

        Dim sSize As System.Drawing.SizeF
        Dim fFont As New Font("Arial", 12)
        sSize = Me.CreateGraphics().MeasureString(txtAddr.Text, fFont)

此处的单位是 IDE 使用的任何单位。我不确定这是一个常量值,如果是,转换应该很简单。

无论如何,当使用指定字体以 100% 打印文本时,我想将返回的单位转换为英寸。我该怎么做?


谢谢汉斯!

        Dim boxGraphics As Graphics = txtAddr.CreateGraphics()
        Dim sSize As System.Drawing.SizeF = boxGraphics.MeasureString(txtAddr.Text, New Font("Arial", 12))
        Dim iInches As Single = sSize.Width / boxGraphics.DpiX

可能感兴趣的 DYMO LabelWriter 450 代码的开始:

        ' project ref to DYMO.Label.Framework .net 3.5/4
        ' Imports DYMO.Label.Framework
        Dim olabel As Label
        olabel = Label.Open("H:\INFO\Forms\ADMIN\Dymo Labels\APCDAddress.label")
        olabel.SetObjectText("ADDRESS", txtAddr.Text) ' case sensitive
        olabel.Print("\\PC3090-117\DYMO LabelWriter 450 Twin Turbo")
        MsgBox("Printed")

我将添加代码来处理对于标签来说可能太大的地址文本,因此是 OP。 DYMO 布局可以设置为缩小以适合文本,但在制作地址标签时有实际限制。

最佳答案

来自@HansPassant:除以 Graphics.DpiX

   Dim boxGraphics As Graphics = txtAddr.CreateGraphics()
    Dim sSize As System.Drawing.SizeF = boxGraphics.MeasureString(txtAddr.Text, New Font("Arial", 12))
    Dim iInches As Single = sSize.Width / boxGraphics.DpiX

https://stackoverflow.com/questions/23256120/

相关文章:

azure - WAStorageEmulator.exe 启动失败

asp.net - 在 RDLC 报告 asp.net 中放置超链接

maven - java.lang.IllegalStateException : Could no

scala - 修复更高种类类型的类型推断

applescript - 如何使用 AppleScript 关闭 MS Office Ribbon

ruby-on-rails - 在 current_password 字段中设计更改验证消息

dart - 如何在 Dart 中产生一个新的隔离?

angularjs - 关于Angular $q defer对象的问题

datomic - 将任意键/值条目与数据实体一起存储

clojure - 是否可以检索定义变量的条件图?