C# 机房合作代码块

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yujing1314/article/details/84500777

一、dataGridView

1.右键出快捷菜单

            if (e.Button == MouseButtons.Right)
            {
                if (e.RowIndex >= 0)
                {
                    //若行已是选中状态就不再进行设置
                    if (DGVInfo.Rows[e.RowIndex].Selected == false)
                    {
                        DGVInfo.ClearSelection();
                        DGVInfo.Rows[e.RowIndex].Selected = true;
                    }
                    //只选中一行时设置活动单元格
                    if (DGVInfo.SelectedRows.Count == 1)
                    {
                        DGVInfo.CurrentCell = DGVInfo.Rows[e.RowIndex].Cells[e.ColumnIndex];
                    }
                    //弹出操作菜单
                    contextMenuStrip2.Show(MousePosition.X, MousePosition.Y);
                }
            }

2.datagridview怎么操作完之后刷新

DGVInfo.DataSource = dt;
            DGVInfo.Refresh();

二、界面

1.messbox


选择是否执行对话框
 if (MessageBox.Show("您确定要退出系统吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {}

2.点击一个按钮执行另一个按钮


btnOffLine_Click(sender,e);

3.清空Text文本

    foreach (Control Ctrol in this.Controls)
                {
                    if (Ctrol is TextBox)
                    {
                        Ctrol.Text = "";
                    }
                }

4.PasswordChar 为0

txt_Password.PasswordChar = '\0';

5. 控件随窗体变大

this.WindowState = FormWindowState.Maximized;           
            panel1.Width = this.Width;
            ```

猜你喜欢

转载自blog.csdn.net/yujing1314/article/details/84500777