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

推荐订阅源

WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Visual Studio Blog
宝玉的分享
宝玉的分享
IT之家
IT之家
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
I
InfoQ
B
Blog RSS Feed
T
Threatpost
博客园_首页
M
MIT News - Artificial intelligence
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
U
Unit 42
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
Scott Helme
Scott Helme
T
Tor Project blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
S
Schneier on Security
Vercel News
Vercel News
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
L
LangChain Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
S
Security Affairs
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
大猫的无限游戏
大猫的无限游戏
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
罗磊的独立博客

博客园 - 扬中源

解决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;
        }