公元 2025 年 11 月 10 日

仿QQ窗体自动收缩

2023/5/31 1:05:21

模仿QQ主窗体自动收缩的功能,展示部分功能。

        private void Timer1_Tick(object sender, EventArgs e)
        {
            if (Top < 3 && Tem_place == 0)//如果窗体被移到屏幕的顶部
            {
                if (Handle == FormNameAt(Cursor.Position.X, Cursor.Position.Y))//当鼠标移致到该窗体上
                {
                    panel_Title.Tag = 1;//设置标识,用于判断窗体在屏幕顶部
                    timer2.Enabled = false;//不对窗体进行拉伸操作
                    Top = 0;//使窗体致顶
                }
                else
                {
                    panel_Title.Tag = 1;//设置标识,用于判断窗体在屏幕顶部
                    timer2.Enabled = true;//将窗体在顶部进行隐藏
                }
            }
            else
            {
                if (Left < 3 || Right > GetSystemMetrics(0) - 3)//如果窗体被移到屏幕的左端或右端
                {
                    if (Left < 3)//如果窗体被移到屏幕的左端
                    {
                        if (Handle == FormNameAt(Cursor.Position.X, Cursor.Position.Y))//当鼠标移致到该窗体上
                        {
                            panel_Title.Tag = 2;//设置标识,用于判断窗体在屏幕左端
                            timer2.Enabled = false;
                            Frm_Height = Height;
                            Left = 0;//使窗体致左
                            Top = 0;
                            Height = Screen.AllScreens[0].Bounds.Height;
                            Tem_place = 1;
                        }
                        else
                        {
                            panel_Title.Tag = 2;
                            timer2.Enabled = true;//将窗体在左端进行隐藏
                        }
                    }
                    if (Right > GetSystemMetrics(0) - 3)//如果窗体被移到屏幕的右端
                    {
                        if (Handle == FormNameAt(Cursor.Position.X, Cursor.Position.Y))//当鼠标移致到该窗体上
                        {
                            panel_Title.Tag = 3;//设置标识,用于判断窗体在屏幕右端
                            timer2.Enabled = false;
                            Frm_Height = Height;
                            Left = GetSystemMetrics(0) - Width;//使窗体致右
                            Top = 0;
                            Height = Screen.AllScreens[0].Bounds.Height;
                            Tem_place = 1;
                        }
                        else
                        {
                            panel_Title.Tag = 3;
                            timer2.Enabled = true;//将窗体在右端进行隐藏
                        }
                    }
                }
            }
        }

 

经常用到的东西,记录下来,然后用的时候想不起来。

1.遍历整个 dataGridView1 控件

for (int i = 0; i < dataGridView1.RowCount; i++)
{
    for (int j = 0; j < dataGridView1.ColumnCount; j++)
    {
        //打印第i行第j列数据
        Console.WriteLine(Convert.ToString(dataGridView1[j, i].Value));
        // 注意dataGridView1[j,i]代表的是第i行第j列
    }
}

2.模糊查找数据并定位并加入是否还要继续查找

int row = dataGridView1.Rows.Count;//得到总行数
int cell = dataGridView1.Rows[1].Cells.Count;//得到总列数
string strTxt = txtFind.Text;//得到输入的字符串,并付值给变量
Regex r = new Regex(strTxt); // 定义一个Regex对象实例 
for (int i = 0; i < row; i++)//得到总行数并在之内循环
{
    for (int j = 0; j < cell; j++)//得到总列数并在之内循环
    {
        Match m = r.Match(dataGridView1.Rows[i].Cells[j].Value.ToString()); // 在字符串中模糊匹配 
        if (m.Success)
        {   //对比TexBox中的值是否与dataGridView中的值相同(上面这句)
            dataGridView1.CurrentCell = dataGridView1[j, i];//定位到相同的单元格
            if (MessageBox.Show("是否需要继续查找?", "", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                //如果选择了取消就会返回,如果选择了确定,就会继续查找匹配的.
                return;//返回
            }
        }
    }
}

 

1/1, 2«1»
公告

欢迎加入我们!!!

开关电源 交流QQ群: 392599244

另启动 交流QQ群: 154186357

EM.CMS 交流QQ群: 26032741

恶魔界 交流QQ群: 7261922

搜索
最新评论
站点数据
栏目总数: 9 个
文章数量: 16 篇
评论数量: 1 条
标签云: 25 个
自定义标签: 0 个
合作伙伴: 3 位
附件数量: 22 个
当前在线: 65 人