首页

winform 鼠标聚焦 焦点时变色

c#

2020-9-10

下载地址

鼠标焦点变色

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FocusChangeColor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_Enter(object sender, EventArgs e)
        {
            ((TextBox)sender).BackColor = Color.CornflowerBlue;
        }

        private void textBox1_Leave(object sender, EventArgs e)
        {
            ((TextBox)sender).BackColor = Color.White;
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                int n = Convert.ToInt32(((TextBox)sender).Tag.ToString());
                Clear_Control(this.Controls, n, 6);
            }
        }

        #region  遍历指定的控件
        /// <summary>
        /// 遍历指定的控件
        /// </summary>
        /// <param Con="ControlCollection">可视化控件</param>
        /// <param n="int">控件标识</param>
        /// <param m="int">最大标识</param>
        public void Clear_Control(Control.ControlCollection Con, int n, int m)
        {
            int tem_n=0;
            foreach (Control C in Con)
            { //遍历可视化组件中的所有控件
                if (C.GetType().Name == "TextBox")  //判断是否为TextBox控件
                {
                    if (n == m)
                        tem_n = 1;
                    else
                        tem_n = n   1;
                    if (Convert.ToInt32(((TextBox)C).Tag.ToString())==tem_n)
                        ((TextBox)C).Focus();   //清空当前控件
                }
            }
        }
        #endregion
    }
}
资源下载此资源下载价格为3D币,请先

资源文件列表

焦点变色/FocusChangeColor.sln , 938
焦点变色/FocusChangeColor.suo , 14336
焦点变色/FocusChangeColor/bin/Debug/FocusChangeColor.exe , 11264
焦点变色/FocusChangeColor/bin/Debug/FocusChangeColor.pdb , 24064
焦点变色/FocusChangeColor/bin/Debug/FocusChangeColor.vshost.exe , 14328
焦点变色/FocusChangeColor/bin/Debug/FocusChangeColor.vshost.exe.manifest , 490
焦点变色/FocusChangeColor/FocusChangeColor.csproj , 3743
焦点变色/FocusChangeColor/Form1.cs , 1908
焦点变色/FocusChangeColor/Form1.Designer.cs , 9151
焦点变色/FocusChangeColor/Form1.resx , 5814
焦点变色/FocusChangeColor/obj/Debug/FocusChangeColor.csproj.FileListAbsolute.txt , 1123
焦点变色/FocusChangeColor/obj/Debug/FocusChangeColor.csproj.GenerateResource.Cache , 847
焦点变色/FocusChangeColor/obj/Debug/FocusChangeColor.exe , 11264
焦点变色/FocusChangeColor/obj/Debug/FocusChangeColor.Form1.resources , 180
焦点变色/FocusChangeColor/obj/Debug/FocusChangeColor.pdb , 24064
焦点变色/FocusChangeColor/obj/Debug/FocusChangeColor.Properties.Resources.resources , 180
焦点变色/FocusChangeColor/Program.cs , 497
焦点变色/FocusChangeColor/Properties/AssemblyInfo.cs , 1364
焦点变色/FocusChangeColor/Properties/Resources.Designer.cs , 2882
焦点变色/FocusChangeColor/Properties/Resources.resx , 5612
焦点变色/FocusChangeColor/Properties/Settings.Designer.cs , 1101
焦点变色/FocusChangeColor/Properties/Settings.settings , 249

发表评论

没有账号? 忘记密码?

社交账号快速登录