Vb.net 基于另一个文本框中的值填充文本框中的值
我想弄明白的是,如何根据另一个文本框的值填充文本框 假设textbox1值是指向.txt文件的文件路径,我希望textbox2更新为“这是一个文本文件”或类似的内容。我该怎么做呢Vb.net 基于另一个文本框中的值填充文本框中的值,vb.net,Vb.net,我想弄明白的是,如何根据另一个文本框的值填充文本框 假设textbox1值是指向.txt文件的文件路径,我希望textbox2更新为“这是一个文本文件”或类似的内容。我该怎么做呢 提前感谢。使用自定义.Format事件处理程序的数据绑定 Public Sub New() InitializeComponent() ' Bind Text property of one textbox to Text property of another Dim binding = tx
提前感谢。使用自定义
.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
这里:看。将main方法调用为:
Dim extensionInfo=fileextensioninfo(AssociationQuery.FriendlyDocName,Path.GetExtension(“c:\somefile.txt”)
。您将返回类似以下内容:文本文档
。请参阅其他选项(例如,指定AssociationQuery.FriendlyAppName
,您可能会得到,Notepad
,或默认的开启器,无论是什么)。否则,您将不得不构建一个字典(字符串,字符串)
,其中键是扩展名,值是要与该扩展名关联的字符串。非常感谢大家!@esqew是的,我理解这一点,只是想帮助他们朝着正确的方向前进。