惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

博客园 - 扬中源

解决Avalonia.Markup.Xaml.XamlLoadException:“No precompiled XAML found for _xxxx.App, make sure to specify x:Class and include your XAML file as AvaloniaResource” vs2022 android模拟器闪退 VS2022 C# grpc遇到的问题 在Avalonia中,如何移除高度的值,使其为NaN 用bat批处理,winrar备份文件夹并排除特定子文件夹 用完我的风扇终于不吵了。 Avalonia跨平台嵌入浏览器的方法 Excel把一列数据变两列,带条件分组的行变列 yellowbrick中ClassificationReport多分类图标一行数据异常全为0 ModuleNotFoundError: No module named 'yellowbrick.features.importances' 动手学深度学习MXNet配置 用Goaccess对Nginx进行性能监控windows版 只能判断文件图片类型,并修改文件名 微信电脑版提取微信小程序中的音频 NFC手机制作备用门禁卡 win7有些电脑form布局发生变化 微信小程序wepy Oracle连接错误解决办法 cef chromium相关
textbox根据内容自动调整高度
扬中源 · 2018-03-22 · via 博客园 - 扬中源

首先将Textbox改为多行模式,设置MutliLine属性为True,对于textbox中文本有回车的,直接通过textbox.lines.count()可以获取到行数。

但是单行无回车的文本如何知道自动换行状态下,高度呢?

首先使用Size size = TextRenderer.MeasureText(textBox2.Text, textBox1.Font);进行测量,然后进行计算,以下代码较粗,仅抛砖引玉。

        /// <summary>
        /// 根据文本内容设置textbox高度
        /// </summary>
        /// <param name="txt1"></param>
        private void SettxtHeight(TextBox txt1)
        {
            int txtHeight = 22;//设置单行的行高
            int MaxLineCount = 10;//设置最大行数
            Size size = TextRenderer.MeasureText(txt1.Text, textBox1.Font);
            int itxtLine = size.Width / txt1.Width +  txt1.Lines.Count()+ 1;
            if (itxtLine > MaxLineCount) { itxtLine = MaxLineCount; }
            txt1.Height = txtHeight * itxtLine;
        }