Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 基于另一个文本框中的值填充文本框中的值_Vb.net - Fatal编程技术网

Vb.net 基于另一个文本框中的值填充文本框中的值

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

我想弄明白的是,如何根据另一个文本框的值填充文本框

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


提前感谢。

使用自定义
.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是的,我理解这一点,只是想帮助他们朝着正确的方向前进。