社区
C#
帖子详情
Convert.ToInt32(textBox2.Text.Trim() 报错
clleady
2015-11-27 09:47:35
textBox3.Text = Convert.ToString(Convert.ToInt32(textBox1.Text.Trim()) + Convert.ToInt32(textBox2.Text.Trim()));
textbox2输入1.6则
。{输入字符串的格式不正确。}
即输入小数则报错。输入整数相加则正确。
...全文
244
3
打赏
收藏
Convert.ToInt32(textBox2.Text.Trim() 报错
textBox3.Text = Convert.ToString(Convert.ToInt32(textBox1.Text.Trim()) + Convert.ToInt32(textBox2.Text.Trim())); textbox2输入1.6则。{输入字符串的格式不正确。} 即输入小数则报错。输入整数相加则正确。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
Lear_ken
2015-11-28
打赏
举报
回复
第一,你到底是要实现整数计算还是小数计算?要实现整数计算就在输入框控制不要输入小数,否则就改变整数转换函数为小数转换函数; 第二,一般这种转换要么会在输入框限制可输入字符,要么使用数值的TryParse方式。
Poopaye
2015-11-27
打赏
举报
回复
你要转整数就限制好textbox里不能输入0-9,负号以外的字符
clleady
2015-11-27
打赏
举报
回复
该怎么修改? textBox3.Text = Convert.ToString(Convert.ToInt32(textBox1.Text.Trim()) + Convert.ToInt32(1.6)); 直接将textBox2.Text.Trim替换为小数1.6则正常运行。
C#数据结构串的常用实例源码.
字符串的相加,检索,替换,截取,插入,计算长度 private void button1_Click(object sender, EventArgs e) { string a =
text
Box
1.
Text
.ToString(); string b =
text
Box
2.
Text
.ToString(); string c = a + b;
text
Box
3.
Text
= c; } private void button2_Click(object sender, EventArgs e) { string a =
text
Box
1.
Text
.ToString();
text
Box
3.
Text
= a.Length.ToString(); } private void button3_Click(object sender, EventArgs e) { string a =
text
Box
1.
Text
.ToString(); string b =
text
Box
2.
Text
.ToString();
text
Box
3.
Text
= b.Insert(0, a); } private void button4_Click(object sender, EventArgs e) { string a =
text
Box
1.
Text
.ToString();
int
b =
Convert
.To
Int
16(
text
Box
2.
Text
.
Trim
());
text
Box
3.
Text
= a.Remove(b); } private void button5_Click(object sender, EventArgs e) { string a =
text
Box
1.
Text
.ToString(); string b =
text
Box
2.
Text
.ToString(); string c =
text
Box
3.
Text
.ToString();
text
Box
3.
Text
= a.Replace(b,c); } private void button6_Click(object sender, EventArgs e) { string a =
text
Box
1.
Text
.ToString();
int
b =
Convert
.To
Int
16(
text
Box
2.
Text
.
Trim
());
int
c =
Convert
.To
Int
16(
text
Box
3.
Text
.
Trim
());
text
Box
3.
Text
= a.Substring(b, c); }
C#栈和队列的应用实例源码
C#栈和队列的应用实例源码 private void button1_Click(object sender, EventArgs e) { if (
text
Box
3.
Text
.Length > 0) { if (IsIDnum(
text
Box
3.
Text
.
Trim
())) {
int
i =
Convert
.To
Int
32
(
text
Box
3.
Text
.
Trim
()); b.Push(i); str = str +
text
Box
3.
Text
.
Trim
() + ","; label4.
Text
= str;
text
Box
3.
Text
= ""; } else {
text
Box
3.
Text
= "必须为数字"; } } else {
text
Box
3.
Text
= "不能为空"; } } private void button3_Click(object sender, EventArgs e) { if (b.Count == 0) {
text
Box
4.
Text
= "栈为空"; label4.
Text
=""; } else {
text
Box
4.
Text
= b.Pop().ToString();
int
n = str.LastIndexOf(","); str = str.Substring(0, n);
int
m = str.LastIndexOf(","); str = str.Substring(0, m+1); label4.
Text
= str; } }
初级学软件之ASP.NET第三季 ASP.NET控件的使用
初级学软件之ASP.NET第三季 ASP.NET控件的使用 视频课程主讲内容:第一讲 文本类型控件-Label第二讲 文件类型控件-
Text
Box
第三讲 按钮类型-Button第四讲 按钮类型-LinkButton第五讲 按钮类型-ImageButton第六讲 按钮类型-HyperLink第七讲 选择类型-ListBox
单用户登录
登录代码:protected void Button1_Click(object sender, EventArgs e) { SqlConnection myCon = new SqlConnection("Server=(local);Database=db_SingleuserLogin;User Id=sa;Password=111111"); myCon.Open(); SqlCommand myCom = new SqlCommand("select count(*) from tb_Login where UserID= '" +
Text
Box
1.
Text
.
Trim
() + "' and UserPwd='" +
Text
Box
2.
Text
.
Trim
() + "'", myCon);
int
i =
Convert
.To
Int
32
(myCom.ExecuteScalar()); if (i > 0) Response.Redirect("Main.aspx"); else Response.Write("<script language=javascript>alert('你是非法用户或密码错误!')
Text
Box1.
Text
= "";
Text
Box
2.
Text
= ""; }
网页内容变动简易监视器
tb_url.
Text
= tb_url.
Text
.
Trim
(); System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create( new Uri( tb_url.
Text
)); System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); System.IO.Stream responseStream = response.GetResponseStream(); System.IO.StreamReader sr = new System.IO.StreamReader(responseStream, Encoding.UTF8); string content_start = sr.ReadToEnd();
text
Box
1.
Text
= content_start; tb_time.
Text
=tb_time .
Text
.
Trim
(); lb_count.
Text
= tb_time.
Text
; timer1.
Int
erval =
Convert
.To
Int
16(tb_time.
Text
) * 1000; timer1.Enabled = true; timer1s.Enabled = true; listBox1.Items.Add(DateTime .Now .ToString ()+"监视开始!");
C#
110,533
社区成员
642,574
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章