怎么把从textbox输入的值变成label的背景颜色,窗体启动时标签上的文字能沿窗体的主对交线循环移动
怎么把输入的值变成label的背景颜色呢,标签循环移动
怎么把从textbox输入的值变成label的背景颜色,窗体启动时标签上的文字能沿窗体的主对交线循环移动
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- CSDN专家-showbo 2022-03-05 15:08关注
下面这个是碰到边界回弹示例,对角线首先label得放到对角线上,代码计算出来会跳动
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp8 { public partial class Form2 : Form { public Form2() { InitializeComponent(); t = new Timer(); t.Enabled = false; t.Interval = 100;//100ms移动一次 t.Tick += T_Tick; } int x = 5, y = 5; private void T_Tick(object sender, EventArgs e) { label1.Location = new Point(label1.Location.X + x, label1.Location.Y+y); if (label1.Location.X > this.ClientRectangle.Width - label1.Width || label1.Location.X < 0) x = -x; if (label1.Location.Y > this.ClientRectangle.Height - label1.Height || label1.Location.Y < 0) y = -y; } Timer t; private void textBox1_TextChanged(object sender, EventArgs e) { label1.ForeColor = Color.FromName(textBox1.Text); } private void button1_Click(object sender, EventArgs e) { t.Enabled = button1.Text=="移动"; button1.Text = t.Enabled ? "停止" : "移动"; } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
- ¥20 怎么用dlib库的算法识别小麦病虫害
- ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
- ¥15 java写代码遇到问题,求帮助
- ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
- ¥15 有了解d3和topogram.js库的吗?有偿请教
- ¥100 任意维数的K均值聚类
- ¥15 stamps做sbas-insar,时序沉降图怎么画
- ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
- ¥15 关于#Java#的问题,如何解决?