CrowdCountControl好玩吗 CrowdCountControl玩法简介,crowd control怎么玩
时间:2023-10-05 07:57:46
来源:
浏览:
C# WinForm自定义控件
一、开发环境和工具
1、WIN10系统
2、Visual Studio社区版 2019(C#)
二、创建自定义控件窗体
① 添加一个自定义控件,右键解决方案,点击添加,然后点击用户控件
②选择用户控件(Windows窗体)
③得到如下图所示控件
④从左侧工具箱拖曳控件并布局,如下图所示
⑤查看工具箱就能够看见我们的自定义控件已经在工具箱生成了
三、添加相应函数
①设置名称
public void SetName(string Name){ this.lab_Name.Text = Name; return;}
②更新测试时间
public void UpdateTimer(int Sec){ string StrHour; string StrMin; string StrSec; if ((Sec / 3600) < 10) StrHour = "0" + (Sec / 3600).ToString(); else StrHour=(Sec / 3600).ToString(); if (((Sec % 3600) / 60) < 10) StrMin = "0" + ((Sec % 3600) / 60).ToString(); else StrMin= ((Sec % 3600) / 60).ToString(); if (((Sec % 3600) % 60) < 10) StrSec = "0" + ((Sec % 3600) % 60).ToString(); else StrSec= ((Sec % 3600) % 60).ToString(); this.textBox_TestTimer.Text = StrHour + ":" + StrMin + ":" + StrSec; return;}
③更新测试状态
public void UpdateTestState(bool LedRed,bool LedGreen, bool LedYellow){ if (!LedRed) this.lab_LedRed.BackColor = System.Drawing.Color.Firebrick; else this.lab_LedRed.BackColor = System.Drawing.Color.Red; if (!LedGreen) this.lab_LedGreen.BackColor = System.Drawing.Color.ForestGreen; else this.lab_LedGreen.BackColor = System.Drawing.Color.Lime; if (!LedYellow) this.lab_LedYellow.BackColor = System.Drawing.Color.ForestGreen; else this.lab_LedYellow.BackColor = System.Drawing.Color.Yellow; return;}
④设置ID
public void SetID(int IDIndex){ if(IDIndex<10) this.lab_IDValue.Text ="00" + IDIndex.ToString(); else if(IDIndex < 100) this.lab_IDValue.Text = "0" + IDIndex.ToString(); else if (IDIndex < 1000) this.lab_IDValue.Text = IDIndex.ToString(); return;}
四、控件应用
using System;using System.Collections.Generic;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApp1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } int Sec = 0; UserControl2<> userControl1 = new UserControl2<1024>; //创建控件数组 private Layout layout = new Layout(); /// <summary> /// 更新测试时间 /// </summary> /// <param name="count"></param> /// <param name="Sec"></param> private void UpdataTimer(int count,int Sec) { for (int i = 0; i < count; i++) { userControl1.UpdateTimer(Sec) ; } } /// <summary> /// 添加控件,count为添加控件数量 /// </summary> /// <param name="count"></param> private void AddControl(int count) { int PanelWidth; int PanelHeight; int ColCount = 0; this.panel1.Controls.Clear();//清除面板控件 PanelWidth = this.panel1.Width; PanelHeight = this.panel1.Height; layout.RowGap = Convert.ToInt32(textBox_RowGap.Text); layout.ColGap = Convert.ToInt32(textBox_ColGap.Text); layout.LeftGap = Convert.ToInt32(textBox_LeftGap.Text); layout.TopGap = Convert.ToInt32(textBox_TopGap.Text); layout.Height = 134; layout.Width =218; //根据面板宽度,计算多少列 ColCount = (PanelWidth - layout.LeftGap - layout.RightGap) / (layout.Width + layout.ColGap); for (int i = 0; i < count; i++) { userControl1 = new UserControl2(); //实例化控件 //根据列距,行距,计算控件位置 userControl1.Location = new System.Drawing.Point((i % ColCount) * (layout.Width + layout.ColGap) +layout.LeftGap,(i / ColCount) * (layout.Height + layout.RowGap) + layout.TopGap); //更新测试状态 userControl1.UpdateTestState(true, true,true); //设置名称 userControl1.SetName("名称" + (i + 1).ToString()); //设置ID userControl1.SetID(i + 1); //设置控件宽度和高度 userControl1.Width = layout.Width; userControl1.Height = layout.Height; //添加相应控件 this.panel1.Controls.Add(userControl1); } this.timer1.Start(); } private void button1_Click_2(object sender, EventArgs e) { AddControl(32); } private void timer1_Tick(object sender, EventArgs e) { Sec++; UpdataTimer(32, Sec); //更新测试时间 } }}
五、效果演示
视频加载中...
<script src="https://lf3-cdn-tos.bytescm.com/obj/cdn-static-resource/tt_player/tt.player.js?v=20160723"></script>
标题:CrowdCountControl好玩吗 CrowdCountControl玩法简介,crowd control怎么玩
链接:https://www.miaoshengapp.cn/yxgl/123236.html
版权:文章转载自网络,如有侵权,请联系删除!
资讯推荐
热门手游
更多
热门攻略
-
CrisisResponse好玩吗 CrisisResponse玩法简介, 2023-10-05
-
CRIMESIGHT好玩吗 CRIMESIGHT玩法简介,crimesight攻略视频 2023-10-05
-
Creator2好玩吗 Creator2玩法简介, 2023-10-05
-
crashlands怎么造锯子 crashlands锯子制作教程, 2023-10-05
-
crashlands怎么回血 crashlands速刷回血植物方法, 2023-10-05
-
CranePrizePool好玩吗 CranePrizePool玩法简介, 2023-10-05
-
CraftTank好玩吗 CraftTank玩法简介,crafttankpc端 2023-10-05
热游排行榜