C#中调用VB中Inputbox类的实现方法
作者:wenjunsu 时间:2023-09-06 18:12:57
C#自己没有Inputbox这个类,但是Inputbox也蛮好用的,所以有两种方法可以使用
一:间接调用vb中的Inputbox功能
1。在项目中添加对Microsoft.VisualBasic引用
2。在项目中添加命名空间Using Microsoft.VisualBasic;
3。以后就可以直接使用VB中的好多类库(爽啊……)
例如:textBox1.Text=Microsoft.VisualBasic.Interaction.InputBox(“提示性文字”, “对话框标题”, “默认值”, X坐标, Y坐标);
上面的 X坐标, Y坐标 可以取值为 –1 和 -1,表示屏幕中间位置显示。
二:还可以自己写一个InputBox()这个函数。动态生成一个FORM以及TEXTBOX和BUTTON等,确定好位置,返回用户输入的字符串。
public partial class InputBox : Form
{
private InputBox()
{
InitializeComponent();
}
public String getValue()
{
return textBox1.Text;
}
public static bool Show(String title,String inputTips,bool isPassword,ref String value)
{
InputBox ib = new InputBox();
if (title != null)
{
ib.Text = title;
}
if (inputTips != null)
{
ib.label1.Text = inputTips;
}
if (isPassword)
{
ib.textBox1.PasswordChar = '*';
}
if (ib.ShowDialog()==DialogResult.OK)
{
value = ib.getValue();
ib.Dispose();
return true;
}
else
{
ib.Dispose();
return false;
}
}
}使用方法
String value;
if (InputBox.Show("用户输入", "密码:", true, ref value))
{
//输入成功后的操作
}
标签:C#,VB,Inputbox
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解SpringMVC @RequestBody接收Json对象字符串
2022-03-20 05:00:10
SpringBoot整合SpringTask实现定时任务的流程
2022-03-28 22:24:40
java集合迭代器Iterator中的remove陷阱
2022-06-17 16:11:54
Java执行JS脚本工具
2022-04-07 08:00:16
![](https://img.aspxhome.com/file/2023/9/62159_0s.png)
Java设计模式之GOF23全面讲解
2023-06-24 06:15:06
![](https://img.aspxhome.com/file/2023/8/78228_0s.jpg)
c语言实现可自定义的游戏地图
2021-10-25 14:38:34
![](https://img.aspxhome.com/file/2023/8/112298_0s.jpg)
Java事务管理学习之Spring和Hibernate详解
2023-04-11 00:01:25
![](https://img.aspxhome.com/file/2023/4/62684_0s.png)
SpringBoot中使用多线程的方法示例
2021-05-24 19:56:04
![](https://img.aspxhome.com/file/2023/0/71690_0s.png)
基于Class.forName()用法及说明
2021-06-20 19:09:30
![](https://img.aspxhome.com/file/2023/7/61877_0s.png)
Android中Listview下拉刷新和上拉加载更多的多种实现方案
2022-11-19 17:00:43
springboot配置文件绑定实现解析
2022-06-07 23:32:38
![](https://img.aspxhome.com/file/2023/7/61917_0s.png)
Android开发之DatePickerDialog、TimePickerDialog时间日期对话框用法示例
2022-10-25 21:21:12
![](https://img.aspxhome.com/file/2023/8/106038_0s.gif)
并发编程之Java内存模型顺序一致性
2023-04-11 08:12:25
![](https://img.aspxhome.com/file/2023/8/132198_0s.png)
android倒计时控件示例
2022-12-01 05:34:53
SpringBoot注入自定义的配置文件的方法详解
2021-12-24 02:28:06
![](https://img.aspxhome.com/file/2023/2/66682_0s.png)
Eclipse转Itellij IDEA导入Git/svn本地项目的详细步骤
2021-11-06 12:57:10
![](https://img.aspxhome.com/file/2023/1/103821_0s.png)
Android实现屏幕录制功能
2022-10-29 15:26:36
![](https://img.aspxhome.com/file/2023/8/117158_0s.jpg)
Java使用Tesseract-Ocr识别数字
2022-12-30 05:15:44
![](https://img.aspxhome.com/file/2023/7/125887_0s.png)
UnityShader3实现彩光效果
2021-09-02 03:48:53
![](https://img.aspxhome.com/file/2023/9/129659_0s.gif)
Android 中 ActivityLifecycleCallbacks的实例详解
2022-08-12 06:03:34