问题描述
|
我正在处理继承自
TextBox
的CustomControl
,可以通过在拖动鼠标的同时按住ѭ2re来调整大小,但有时在调整大小时,线条会像这样被切断:
如果发生这种情况,我想调整选择的高度,以使线条不会被切断。这是我到目前为止的代码:
double LineHeight = ??;
double requiredHeightAdjustment = this.Height % LineHeight;
if (requiredHeightAdjustment != 0)
{
this.Height -= requiredHeightAdjustment;
}
- 编辑 -
万一将来有人需要,这就是我的最终选择:
double fontHeight = this.FontSize * this.FontFamily.LineSpacing;
double requiredHeightAdjustment = this.Height % fontHeight;
var parent = this.Parent as FrameworkElement;
if (requiredHeightAdjustment != 0)
{
double upwardAdjustedHeight = (fontHeight - requiredHeightAdjustment) + this.Height;
if (requiredHeightAdjustment >= fontHeight / 2 && this.MaxHeight >= upwardAdjustedHeight
&& (parent == null || parent.ActualHeight >= upwardAdjustedHeight))
this.Height = upwardAdjustedHeight;
else
this.Height -= requiredHeightAdjustment;
}
该解决方案还对选择的TextBox
尺寸进行了最小的必要更改,而不是始终进行负更改。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)