MdiChild有不同的表格标题 [英] MdiChild with different form title

查看:61
本文介绍了MdiChild有不同的表格标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序会打开图像文件并每次创建一个mdichild来显示它们。 mdichild表单Text属性获取没有路径的打开文件的名称。



如果用户决定两次打开同一个文件,我想要mdichild文本是唯一的添加,例如文件名的后缀(myfile.jpg和myfile(1).jpg)。这是为了让用户知道他正在处理的文件的副本。



你怎么能实现这个窗口标题的更改?



如果你看这段代码:



 Foreach(在这个孩子的形式.MdiChildren)
{
if(child.Text.Contains(filename)== true
{
count = count + 1;
//这里添加后缀的代码(count)
}
}





如果用户决定关闭此mdichild,则需要更新计数减去1。 br />


这当然只对第一个文件打开。为了使它适用于每个文件我应该使用表,例如,文件名和计数为字段。



你会使用哪种数据结构?它是正确的方式还是有更聪明的东西?

解决方案

不仅你的架构很难看,它根本不能正常工作,因为它会导致重复,如果用户关闭不是最后一个文件。



您可以使用以下内容:每次按文件名递增数字。您只需要具有唯一的文件缓冲区标识,而不是一组连续的数字。如果用户删除的数字少于最后一个数字,请执行相同的操作。例如,您有1,2,3,4。用户删除2.您有1,3,4。然后您再添加一个相同文件的副本。设为1,3,4,5。然后数字2将丢失。在所有示例中,我只考虑每个完整文件名的数字,以及所有这些数字。



但是!在用户关闭的每个文件上,执行以下操作:检查是否关闭某个文件的所有副本。在这种情况下,您的计数器将被重置为,比如说1.可能你不应该显示这个1,直到你有2.这解决了问题。



支持映射文件和副本数量的模式,使用字典,如 System.Collections.Generic.Dictionary< string,FileCopyDescriptor> ,其中 FileCopyDescriptor 可以是一些数据类,用于存储文件缓冲区对象或其表单的副本号和引用。但不要使用表格。继续阅读...



这是一个想法:谁需要MDI?为什么要折磨自己并吓跑你的用户?

帮自己一个大忙:根本不要使用MDI。没有它,您可以更轻松地实现设计,质量更好。 MDI甚至被微软高度劝阻,事实上,微软将其从WPF中删除并且很难支持它。更重要的是,如果您使用MDI,您将吓跑所有用户。只是不要。请参阅:

http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [ ^ ],

如何在WPF中创建MDI父窗口? [ ^ ]。



我可以解释做什么。请看我过去的答案:

如何在WPF中创建MDI父窗口? [解决方案2 ],

关于在WPF中使用MDI窗口的问题 [ ^ ],

麦当劳给出错误 [ ^ ],

如何设置子窗体最大化,最后一个子窗体最小化 [ ^ ]。



-SA


我会让MDI父母去做。

如果打开每个孩子,那么它可以访问每个孩子,以及他们的Text属性。 br />
它可以轻松处理子项的FormClosing事件,并在那时更新其他子Text属性。

我可能会在子表单中添加一个属性(ImageFilePath 或类似的允许父母检测两个是否有相同的图像文件加载。

不需要新的结构,只有需要了解其他类的类参与名称操作。 / BLOCKQUOTE>

My program opens image files and creates each time a mdichild to visualize them. The mdichild form "Text" property gets the name of the opened file without path.

If the user decides to open the same file twice, I would like the mdichild "Text" to be unique adding, for example a suffix to the file name (myfile.jpg and myfile(1).jpg). This to let the user know on which copy of the file he is working on.

How could you implement this window title change ?

If you look at this code:

Foreach (Form child in this.MdiChildren)
{
 if (child.Text.Contains(filename) == true
{
count = count + 1;
// here the code to add the suffix (count)
}
}



If the user decides to close this mdichild, you need to update count subtracting 1.

This works of course only with the first file opened. To make it work for each file I should use a "table", for example, with filename and count as fields.

Which kind of data structure would you use for this ? Is it the right way or is there something smarter ?

解决方案

Not only your schema is ugly, it won''t really work at all, because it will lead to duplicates, if a user closes not the last file.

You can use the following: increment the number every time, per file name. You only need to have unique identification of file buffers, not really a continues set of numbers. If the user removes some number less then the last one, do the same. For example, you have 1, 2, 3, 4. The user removes 2. You have 1, 3, 4. Then you add one more copy of the same file. Make it 1, 3, 4, 5. Then number 2 will keep missing. In all example, I take into account only the numbers per one full file name, of for all these numbers.

But! On each file closed by the user, do the following: check up if it closes all of the copies of some file. In this case, your counter will be reset to, say 1. Probably you should not show this 1 until you have 2. That solves the problem.

To support the schema of mapping the files and numbers of their copies, use the dictionary like System.Collections.Generic.Dictionary<string, FileCopyDescriptor>, where FileCopyDescriptor can be some data class storing the copy number and reference to the file buffer object or its form. But don''t go with forms. Keep reading…

Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don''t. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA


I would get the MDI parent to do it.
If opens each of the children, so it has access to each of them, and their Text properties.
It can easily handle the FormClosing event for the children, and update the other child Text properties at that point.
I would probably add a property to the child forms ("ImageFilePath" or similar) to allow the parent to detect if two have the same image file loaded.
No new structures needed, and only the classes that need to know about others are involved in the name manipulation.


这篇关于MdiChild有不同的表格标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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