如何应对不同长度的标签–动态布局 [英] How to cope with different lengths of labels– dynamic layout

查看:107
本文介绍了如何应对不同长度的标签–动态布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须启用winforms应用程序中的所有文本才能被替换;它是一个旧的应用程序,处于维护"状态.该应用程序是用.NET v1.1编写的,后来是.NET v2的,因此它不使用任何布局控件.

I have to enable all the text in a winforms application to be replaced; it is an old application and is in "maintenance". The application was written in .NET v1.1 and later bits of it in .NET v2 therefore it does not use any layout controls.

我遇到的问题是,当字符串长于默认字符串时,我需要应对UI.但是,由于风险,我不希望对代码进行大量更改.

The problem I have is that I need to make the UI cope when a string is longer then the default string. However I don’t wish to make lots of changes to the code due to the risk.

过去,我发现简单的更改(例如将面板添加到窗体并将其拖动到窗体上)丢失了事件挂钩等.由于WinForms设计器在其中移动代码的方式,它非常很难使用DIFF来发现此类问题.因此希望尽可能避免对控制树进行任何更改.

In the past I have found that simple changes like adding a panel to a form and dragging the current controls on to it have lost event hook-up etc. Due to the way the WinForms designer moves the code about, it is very hard to use DIFF to spot this sort of problem. So wish to avoid any changes to the control tree if possible.

所以我正在寻找某种布局管理器,可以将其添加到表单中而不必更改其余代码(或控制树)–有什么理想吗?

So I am looking for some sort of layout manager that I can just add to a form without having to change the rest of the code (or control tree) – any ideals?

我还应该考虑其他选择吗?

Any other options I should be looking at?

(替换字符串的人员没有技能来重新安排控件本身;这也将是维护的噩梦,因为标签可能需要为每个客户提供不同的值)

(The people that are replacing the strings do not have the skill set to rearrange the controls themselves; it would also be a maintenance nightmare as label may need to have different values for each customer)

(回答如果我是你,我不会从这里开始是没有用的")

(Answers that say, "If I was you I would not start from here are not useful")

有人知道控制树外部的布局管理器吗?例如,我可以将其指向一个表单,它将取代控件的布局,而不必使所有控件成为布局管理器的子级.

Does anyone know of a layout manager that is external to the control tree? E.g I can point it at a form and it will take over the layout of the controls, without having to make all the controls children of the layout manager.

也请参阅此msdn论坛上的主题.

推荐答案

我在布局管理器方面没有太多经验,而且我并不是真正的UI设计师,所以我很犹豫是否要回复,但是看到没有另一个似乎是,我坚持自己的想法.

I don't have much experience with layout managers, and I'm not really a UI designer, so I am hesitant about replying, but seeing that no-one else seems to be, I chip in with my thoughts.

如果唯一的问题是您不信任设计师进行剪切和粘贴(即,您相信它可以进行重新调整大小),则可以手动执行该步骤.

If your only problem is that you don't trust the designer to do the cut and paste (ie you trust it to do the re-sizing), then you can do that part manually.

我过去所做的事情(不是因为我不信任设计师,而是因为我发现这样做有时更容易)是

What I have done in the past (not because I don't trust the designer, but because I find it is sometimes easier to do it this way,) is :

(假设使用C#并将新面板添加到现有表单中)

(Assuming C# and adding a new panel to an existing form)

1)确保我有备份(通常在源代码管理中)

1) Make sure I have a backup (usually in source control)

2)将面板添加到表单中(通常与设计者一起使用)

2) Add the panel to the form (usually with the designer)

3)关闭设计器并打开代码(xxx.cs或xxx.designer.cs),并找到将所有顶级控件添加到表单的位置,然后将其移动(除面板外)以添加它们到面板.

3) Close the designer and open the code (xxx.cs or xxx.designer.cs) and find where it adds all the top level controls to the form and move all of them (apart from the panel) to add them to the panel.

例如,您从一个类似的名字开始(希望有更有意义的名字)

Ie you start with some like (hopefully with more meaningful names)

this.form1.Controls.Add(this.label1);
this.form1.Controls.Add(this.textBox1);
etc.
this.form1.Controls.Add(this.panel1);

并以

this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.textBox1);
etc 

this.form1.Controls.Add(this.panel1);

较新的表格可能使用如下语法: this.form1.Controls.AddRange(new System.Windows.Forms.Control [] { this.label1, this.TextBox1,
等等 this.panel1});

Newer forms may use the syntax something like this.form1.Controls.AddRange(new System.Windows.Forms.Control[] { this.label1, this.TextBox1,
etc this.panel1});

但本金相同.

4)再做一次备份. (这是我希望拥有一个源代码管理程序包的地方,该程序包使我能够进行临时/私有/个人备份,而不会被其他人看到.)

4) Do another backup. (This is where I wished I had a source control package that allowed me to do a temporary/private/personal backup without make it visible to other people.)

5)在设计器中打开表单,并检查所有控件是否存在.

5) Open the form in the designer and check that all the controls are there.

6)根据需要开始修改布局.

6) Start amending the layout as needed.

或者,我还没有尝试过,但是如果您无法配置超越比较",我会感到非常惊讶(请参阅 http ://www.scootersoftware.com )只是比较事件挂钩行(即包含+ =字符的行),这样可以更轻松地发现是否丢失了任何内容.

Alternatively, I haven't tried it, but I would be very surprised if you could not configure Beyond Compare (see http://www.scootersoftware.com) to just compare event hook up lines (ie those containing a += characters) and that should make it a lot easier to spot that if any have been lost.

这篇关于如何应对不同长度的标签–动态布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆