Winform 程序,在win7操作系统,低分辨率1366X768 图片 文字 变形
程序开发环境Win10, .Net 4.0 , VS2019
Winform 程序 布局逻辑
使用 private TableLayoutPanel tblPlBack; 作为布局架构,中间模块使用 Panel 和 TableLayoutPanel 布局。
this.tblPlBack.ColumnCount = 6;
this.tblPlBack.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 14F));
this.tblPlBack.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 396F));
this.tblPlBack.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 14F));
this.tblPlBack.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 126F));
this.tblPlBack.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 8F));
this.tblPlBack.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tblPlBack.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 12F));
this.tblPlBack.Controls.Add(this.panel2, 0, 1);
this.tblPlBack.Controls.Add(this.cartShop, 0, 3);
this.tblPlBack.Controls.Add(this.adjustmentShop, 0, 3);
this.tblPlBack.Controls.Add(this.tblOperAndTime, 1, 0);
this.tblPlBack.Controls.Add(this.weightInfoControl, 1, 1);
this.tblPlBack.Controls.Add(this.tableLayoutPanel2, 1, 2);
this.tblPlBack.Controls.Add(this.panelPayToolBar, 1, 5);
this.tblPlBack.Controls.Add(this.panel6, 2, 1);
this.tblPlBack.Controls.Add(this.panelVerticalKeys, 3, 0);
this.tblPlBack.Controls.Add(this.panel66, 4, 1);
this.tblPlBack.Controls.Add(this.lfRight, 5, 0);
this.tblPlBack.Dock = System.Windows.Forms.DockStyle.Fill;
this.tblPlBack.Location = new System.Drawing.Point(0, 0);
this.tblPlBack.Margin = new System.Windows.Forms.Padding(0);
this.tblPlBack.Name = "tblPlBack";
this.tblPlBack.RowCount = 7;
this.tblPlBack.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
this.tblPlBack.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 80F));
this.tblPlBack.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 106F));
this.tblPlBack.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tblPlBack.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 2F));
this.tblPlBack.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 58F));
this.tblPlBack.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 14F));
this.tblPlBack.Size = new System.Drawing.Size(961, 733);
this.tblPlBack.TabIndex = 2;
程序图片文字正常运行效果
程序图片文字变形
程序文字图片本来显示正常, 通过点击功能 弹出框,乱点, 文字就会变形;
机器分辨率
中间竖排按钮 变形文字代码(按钮是动态生成的)
/// <summary>
/// 初始化 前台竖排按键
/// </summary>
/// <param name="commonFunctionSettings"></param>
/// <param name="PageIndex"></param>
/// <param name="PageSize"></param>
private void InitTableLayoutPanel(List<CommonFunctionSettings> commonFunctionSettings, int PageIndex, int PageSize)
{
// 分页处理
List<CommonFunctionSettings> splitList = SplitList(commonFunctionSettings, PageIndex, PageSize);
CommonFunctionSettings mnemonicCode = new CommonFunctionSettings();
mnemonicCode.PageIndex = PageIndex.ToString();
mnemonicCode.name = "助记码";
mnemonicCode.serialNumber = "22";
splitList.Add(mnemonicCode);
CommonFunctionSettings more = new CommonFunctionSettings();
more.PageIndex = PageIndex.ToString();
more.name = "更多功能";
more.serialNumber = "24";
splitList.Add(more);
tableVerticalKeys.Controls.Clear();
tableVerticalKeys.SuspendLayout();
for (int i = 0; i < 25; i++)
{
if (i != 0 && ((i % 2 == 0)))
{
string text = "";
foreach (CommonFunctionSettings item in splitList)
{
if (item.serialNumber.Equals(i.ToString()) && item.PageIndex == PageIndex.ToString())
{
text = item.name;
}
}
WwlkButton btn = new WwlkButton();
btn.AllowDrop = true;
btn.BackColor = System.Drawing.Color.Transparent;
btn.BaseColor = System.Drawing.Color.Transparent;
btn.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(102)))), ((int)(((byte)(102)))));
btn.Font = new System.Drawing.Font("微软雅黑", 10F);
btn.ForeColor = this.SkinColor((FrmNewPosMainImageSale f) => f.btnSelectMember.ForeColor) ?? ColorTranslator.FromHtml("#6D8BD3");
btn.HoverColor = System.Drawing.Color.Empty;
btn.HoverFlag = false;
btn.ImagePart = false;
btn.ImageWidth = 0;
btn.Inflate = 0;
btn.IsListModeShowsOriginalPrice = false;
btn.Location = new System.Drawing.Point(203, 5);
btn.Margin = new System.Windows.Forms.Padding(0);
btn.Name = "btnName" + i;
btn.Padding = new System.Windows.Forms.Padding(0, 0, 0, 0);
btn.PressBorderColor = System.Drawing.Color.White;
btn.PressColor = System.Drawing.Color.FromArgb(((int)(((byte)(43)))), ((int)(((byte)(43)))), ((int)(((byte)(43)))));
btn.Size = new System.Drawing.Size(112, 40);
btn.TabIndex = 8;
btn.Tag = i;
btn.Text = text;
btn.TabIndex = 2;
btn.TabStop = false;
btn.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
btn.TextOffsetX = 0;
btn.TextOffsetY = 0;
btn.Click += CustomButtonControlClick;
btn.Anchor = AnchorStyles.None;
if (string.IsNullOrEmpty(text))
{
btn.Visible = false;
}
tableVerticalKeys.Controls.Add(btn, 0, i - 1);
}
}
tableVerticalKeys.Controls.Add(tableVerticalKeys_PicLeft, 0, 25);
tableVerticalKeys.Controls.Add(tableVerticalKeys_PicRight, 0, 26);
tableVerticalKeys_PicLeft.BackgroundImage = this.SkinImage(Lonlink.POS.Properties.Resources.ResourceManager, (FrmNewPosMainImageSale f) => f.itemsControl.PicLeftName) ?? Lonlink.POS.Properties.Resources.button_direction_上一页1;
tableVerticalKeys_PicRight.BackgroundImage = this.SkinImage(Lonlink.POS.Properties.Resources.ResourceManager, (FrmNewPosMainImageSale f) => f.itemsControl.PicRightName) ?? Lonlink.POS.Properties.Resources.button_direction_下一页1;
tableVerticalKeys.ResumeLayout();
}
WwlkButton
这是第三方的?能不能调试下
在低分辨率下,图片和文字变形可能是由于窗口的缩放问题导致的。在Windows操作系统中,不同的分辨率可能会导致控件的大小和位置发生变化。
解决这个问题的方法之一是使用相对于窗口大小的比例来设置控件的大小和位置。
使用自适应布局,动态调整大小
根据屏幕分辨率来动态调整大小
可以使用自定义布局的方式,解决窗口控件不能自适应的问题。或者采用wpf
来自GPT,供你参考:
问题分析:
文字和图片在低分辨率下变形的问题可能是由于分辨率导致的布局适配问题引起的。当程序在高分辨率开发环境中开发时,可能没有考虑到低分辨率下的布局适配情况。
以下是一些可能导致问题的原因和解决方法:
1、布局控件尺寸固定:如果使用固定像素或绝对尺寸来定义控件大小和位置,那么在低分辨率下,控件可能会超出显示区域或缩小变形。建议使用相对布局或自适应布局来确保在不同分辨率下正确适配。
2、字体大小设置问题:如果字体大小没有根据分辨率进行适当调整,那么在低分辨率下可能会导致文字显示变形或无法完全显示。可以尝试使用合适的字体大小设置,并且可以根据当前分辨率动态调整字体大小。
3、图片拉伸或压缩:如果使用了固定尺寸的图片并进行了拉伸或压缩,可能会导致图片变形。建议使用合适尺寸的图片,并在低分辨率下进行适当缩放或选择其他方式来适应不同分辨率。
4、窗口最小尺寸设置:在低分辨率下,如果窗口大小被限制为比实际内容更小的尺寸,可能会导致内容无法完全显示或重叠。确保设置合适的最小尺寸以避免此问题。
5、缩放模式设置问题:如果使用了错误的缩放模式,可能会导致图片拉伸或压缩。根据实际需求选择合适的缩放模式,如等比例缩放、居中缩放等。
综上所述,要解决文字和图片在低分辨率下变形的问题,需要针对布局逻辑和控件参数进行调整,确保在不同分辨率下都能正确适配和显示。建议您重新评估布局和控件设置,并进行必要的调整以适应低分辨率环境。