【问题标题】:Populating values in text box based on values in another text box根据另一个文本框中的值填充文本框中的值
【发布时间】:2020-04-10 03:07:29
【问题描述】:

我想弄清楚的是如何根据另一个文本框的值填充文本框?

假设 textbox1 值是 .txt 文件的文件路径,我希望 textbox2 更新为“这是一个文本文件”或类似的东西。我该怎么做呢?

提前致谢。

【问题讨论】:

  • here。调用main方法为:Dim extensionInfo = FileExtentionInfo(AssociationQuery.FriendlyDocName, Path.GetExtension("c:\somefile.txt"))。你会得到类似:Text Document。查看其他选项(例如,指定AssociationQuery.FriendlyAppName,您可能会得到Notepad,或默认开启程序,无论是什么)。否则,您必须构建一个Dictionary(Of string, string),其中 Key 是扩展名,Value 是您要与该扩展名关联的字符串。
  • 非常感谢你们! @esqew 是的,我明白这一点,只是想帮助我们朝着正确的方向前进。

标签: vb.net


【解决方案1】:

将数据绑定与自定义 .Format 事件处理程序一起使用

Public Sub New()
  InitializeComponent()

  ' Bind Text property of one textbox to Text property of another
  Dim binding = 
    txtDesc.DataBindings.Add("Text", txtFile, "Text", True, DataSourceUpdateMode.OnPropertyChanged)

  ' Add format handler to manipulate output for another textbox
  AddHandler binding.Format, Sub(sender, e)
                               Dim extension = Path.GetExtension(e.Value.ToString())
                               e.Value = $"This is a {extension} file"
                             End Sub

End Sub

【讨论】:

    猜你喜欢
    • 2021-12-04
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 2012-02-06
    • 1970-01-01
    相关资源
    最近更新 更多