页面设置预览实现

先看下效果图
这里写图片描述
这里使用的控件有label,TextBox,PictureBox,tabControl,groupBox,Button。
TextBox使用的事件处理函数是KeyUp。没有使用TextChanged。原因是TextChanged需要移走光标后才更新,KeyUp是实时更新。
这里写图片描述
这里也做了谢简单的判断,如输入非数字的检查,合理的设置范围,详细看代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TextBox_Check
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private UInt16 d_width = 50;
private UInt16 d_height = 24;
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
UInt32 i = 0;
string text = ((TextBox)sender).Text;
if (-1 == Integer_Check(text, out i))
{
MessageBox.Show(“输入错误! \n请输入正确的数字!!!\n”);
((TextBox)sender).Text = “”;
return;
}
if (text == “”)
{
d_width = 1;
}
else
{
d_width = (ushort)(Convert.ToInt32(text));
}
if (d_width == 0 || d_width > 108)
{
MessageBox.Show(“输入值过大!!!\n请输入1-108之间的整数!!!\n”);
d_width = 50;
return;
}
this.pictureBox1.Size = new Size(d_width * 2, d_height * 2);
this.Refresh();
return;
}
private int Integer_Check(string text, out UInt32 Var)
{
Var = 0;
if (text.Length > 0)
{
foreach (char c in text)
{
if (c > 47 && c < 58)
{
continue;
}
else
{
return -1;
}
}
Var = (Convert.ToUInt32(text));
if (Var > 65535)
{
return -2;
}
}
else
{
Var = 0;
}
return 0;
}
private void textBox2_KeyUp(object sender, KeyEventArgs e)
{
UInt32 i = 0;
string text = ((TextBox)sender).Text;

        if (-1 == Integer_Check(text, out i))
        {
            MessageBox.Show("输入错误! \n请输入正确的数字!!!\n");
            ((TextBox)sender).Text = "";
            return;
        }
        if (text == "")
        {
            d_height = 1;
        }
        else
        {
            d_height = (ushort)(Convert.ToInt32(text));
        }
        if (d_height == 0 || d_width > 108)
        {
            MessageBox.Show("输入值过大!!!\n请输入1-108之间的整数!!!\n!!!\n");
            d_height = 50;
            return;
        }
        this.pictureBox1.Size = new Size(d_width * 2, d_height * 2);
        this.Refresh();
        return;
    }
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

楚楚3107

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值