先添加dll,追加命名空间using Microsoft.VisualBasic;
strSeniorAmount=Interaction.InputBox(strUnitAlertMessage,"上位転換数を入力してください","1", -1,-1);
try
{
Convert.ToDecimal(strSeniorAmount);
}
catch
{
MessageBox.Show("ご数字を入力してください。",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
我的问题
1.能不能限制inputbox的输入类型和长度或者最大值,最小值
2.如何区分点inputbox的确定和取消按钮事件
当inputbox为空时,点击确定,给出提示,点取消或者关闭,不提示,终止操作
当inputbox不为空时,错误不错误都行,点击确定,判断合法性,点击取消或者关闭,不提示,终止操作
strSeniorAmount=Interaction.InputBox(strUnitAlertMessage,"上位転換数を入力してください","1", -1,-1);
try
{
Convert.ToDecimal(strSeniorAmount);
}
catch
{
MessageBox.Show("ご数字を入力してください。",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
我的问题
1.能不能限制inputbox的输入类型和长度或者最大值,最小值
2.如何区分点inputbox的确定和取消按钮事件
当inputbox为空时,点击确定,给出提示,点取消或者关闭,不提示,终止操作
当inputbox不为空时,错误不错误都行,点击确定,判断合法性,点击取消或者关闭,不提示,终止操作
解决方案 »
- c# picturebox
- 请问如何在datagridview里,一行结束后,按下tab自动跳到下一行的第二个cell???
- 怎么修改文件权限
- b/s结构的系统的公共变量?
- 我的一个form里嵌了一个浏览器控件,当里边的浏览器关闭了之后,我想把这个form也关闭。该怎么去做呢 谢谢
- 对 .Net QuickStart 一段代码的不解,请指点!
- 有几个问题想请教大家一下
- c#软件开发?
- 请问哪里有关c#的查询和detail页面显示的程序
- 急!版主呢?看看我的帖子--“如何从JAVA转成C#”!
- 菜鸟求救:怎样才能实现类似<meta http-equiv="Content-Type" content="text/html; charset=gb2的功能?
- help me
再取得你要改的对象
2.同上建议,自己做个VBInputBox类,比用他的好internal sealed class VBInputBox : Form
{
// Fields
private Container components;
private Label Label;
private Button MyCancelButton;
private Button OKButton;
public string Output;
private TextBox TextBox; // Methods
internal VBInputBox()
{
this.Output = "";
this.InitializeComponent();
} internal VBInputBox(string Prompt, string Title, string DefaultResponse, int XPos, int YPos)
{
this.Output = "";
this.InitializeComponent();
this.InitializeInputBox(Prompt, Title, DefaultResponse, XPos, YPos);
} protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
} private void InitializeComponent()
{
ComponentResourceManager manager = new ComponentResourceManager(typeof(VBInputBox));
this.OKButton = new Button();
this.MyCancelButton = new Button();
this.TextBox = new TextBox();
this.Label = new Label();
this.SuspendLayout();
manager.ApplyResources(this.OKButton, "OKButton", CultureInfo.CurrentUICulture);
this.OKButton.Name = "OKButton";
this.MyCancelButton.DialogResult = DialogResult.Cancel;
manager.ApplyResources(this.MyCancelButton, "MyCancelButton", CultureInfo.CurrentUICulture);
this.MyCancelButton.Name = "MyCancelButton";
manager.ApplyResources(this.TextBox, "TextBox", CultureInfo.CurrentUICulture);
this.TextBox.Name = "TextBox";
manager.ApplyResources(this.Label, "Label", CultureInfo.CurrentUICulture);
this.Label.Name = "Label";
this.AcceptButton = this.OKButton;
manager.ApplyResources(this, "$this", CultureInfo.CurrentUICulture);
this.CancelButton = this.MyCancelButton;
this.Controls.Add(this.TextBox);
this.Controls.Add(this.Label);
this.Controls.Add(this.OKButton);
this.Controls.Add(this.MyCancelButton);
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "VBInputBox";
this.ResumeLayout(false);
this.PerformLayout();
} private void InitializeInputBox(string Prompt, string Title, string DefaultResponse, int XPos, int YPos)
{
this.Text = Title;
this.Label.Text = Prompt;
this.TextBox.Text = DefaultResponse;
this.OKButton.Click += new EventHandler(this.OKButton_Click);
this.MyCancelButton.Click += new EventHandler(this.MyCancelButton_Click);
Graphics graphics = this.Label.CreateGraphics();
SizeF ef = graphics.MeasureString(Prompt, this.Label.Font, this.Label.Width);
graphics.Dispose();
if (ef.Height > this.Label.Height)
{
int num = ((int) Math.Round((double) ef.Height)) - this.Label.Height;
Label label = this.Label;
label.Height += num;
TextBox textBox = this.TextBox;
textBox.Top += num;
this.Height += num;
}
if ((XPos == -1) && (YPos == -1))
{
this.StartPosition = FormStartPosition.CenterScreen;
}
else
{
if (XPos == -1)
{
XPos = 600;
}
if (YPos == -1)
{
YPos = 350;
}
this.StartPosition = FormStartPosition.Manual;
Point point = new Point(XPos, YPos);
this.DesktopLocation = point;
}
} private void MyCancelButton_Click(object sender, EventArgs e)
{
this.Close();
} private void OKButton_Click(object sender, EventArgs e)
{
this.Output = this.TextBox.Text;
this.Close();
}
}
Collapse Methods
たのみます