vb.net - 根据另一个文本框中的值填充文本框中的值
问题描述
我想弄清楚的是如何根据另一个文本框的值填充文本框?
假设 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
推荐阅读
- sql-server - 为什么字符串数据列的旋转与 row_number 一起使用?
- mongodb - MongoDB的自定义排序功能
- javascript - 单击jquery时更改颜色?
- python - 我需要将一些图像与它们的输出相关联,但图像是凌乱的 Python 3
- python - AttributeError:“TraitCompound”对象没有属性“克隆”
- node.js - 猫鼬和快递路由器问题不止一次
- java - 如何在 CompletableFuture 完成后通过垃圾收集进行回收?
- python - python中的子字符串导致列对象不可调用
- javascript - 如何使用数组将带有 id 的 PHP 表值链接到 javascript?
- ansible - ansible 与默认 remote_user 连接,即使我指定另一个