如何设置propery绑定 [英] how to set propery bindings

查看:59
本文介绍了如何设置propery绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我制作了一个包含动态添加的文本框和标签的表单。有没有办法设置属性绑定到这些,所以当用户关闭并重新打开窗体时,控件和用户输入仍然存在。



我知道我可以做它具有正常的附加控制但不能用于动态。



谢谢

Hi
I made a form with dynamically added textboxes and labels. is there a way to set property bindings to these so when a user closes and reopens the form the controls and user input will still be there.

I know I can do it with a normal added control but cant work it out for dynamic.

Thanks

推荐答案

不,没有自动的方法:您必须使用应用程序设置文件或通过您自己设计的文件存储有关您在非易失性存储(即磁盘)中添加的控件的信息。然后重新加载infor并在下次打开表单时重新添加控件。





我不确定我知道你的意思

我知道如何使用每个循环我认为

是这样的吗?


No, there is no automatic way to do this: you have to store the information on what controls you added where in nonvolatile storage (ie, on disk) either with the Application settings file, or via a file of your own devising. Then reload the infor and re-add the controls next time you open the form.


"I'm not sure I know what you mean
I know how to use for each loop I think
like this?

For Each ctrl In FlowLayoutPanel1.Controls
     If TypeOf ctrl Is TextBox Then
         If ctrl.Name = ask Then
             ctrl.Dispose()
         End If
     End If
 Next ctrl



我真的不明白怎么样写下代码





是的 - 这是一个For Each循环,我只是稍微偏离它们。

For Each是最简单的循环之一 - 它几乎可以与Arrays到Lists中的每个集合一起使用,等等(基本上IEnumerable中的任何一个俱乐部都可以进入对于每个循环,但不要担心...

依次对集合中的每个项目进行处理,并使用该实例在循环中执行代码。它就像一堆硬币:如果你想知道有多少是头部,有多少是尾巴,你可以依次拿出每个顶部的顶部并查看它,记下头部或尾部并继续前进接下来。



在你的代码中,Collection是 FlowLayoutPanel1.Controls ,每个Control都被放入 ctrl 依次变量。



您也可以使用字符串执行此操作:


I don't really understand how to write that code"


Yep - that's a For Each loop and I'll just digress into them a bit.
For Each is one of the simplest kinds of loop - it works with (almost) every collection from Arrays to Lists, and so on (basically anything which is in the IEnumerable "club" can go in a For Each loop, but don;t worry about that just yet)
What is does is takes each item in the collection in turn, and executes the code in the loop using that instance. It's like a pile of coins: if you want to know how many are Heads and how many are Tails, you take each one of the top of the pile in turn and look at it, write down the Head or Tail and move on to the next.

In your code the Collection is FlowLayoutPanel1.Controls and each Control is put into the ctrl variable in turn.

You can do this with strings as well:

Dim lines As String() = File.ReadAllLines("D:\Temp\myData.txt")
For Each line As String In lines
    ...
Next



所以你想去的地方t开始是:


So where you want to start is:

Dim lines As String() = File.ReadAllLines("D:\Temp\myData.txt")
For Each line As String In lines
    ' Process each line into two control texts
    Dim input As String = "label data|textbox data"
    Dim parts As String() = input.Split("|"C)
    Dim forTheLable As String = parts(0)
    Dim forTheTextbox As String = parts(1)
    ' And create the controls
    ...
Next

然后你所要做的就是从点击事件处理程序中提取代码进入这里,你就完成了。



这有意义吗?

Then all you have to do is extract the code from your click event handler into here and you're done.

Does that make sense?


你必须在某个地方保存数据,否则你赢了无法再次访问它。

因此,存储在数据库或文件中,并在加载页面时再次读取它们。
You have to save the Data somewhere otherwise you won't be able to access it again.
So, store in Database or files and read them again while loading the page.


这篇关于如何设置propery绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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