Tag: winforms

单击背景中的表单时,Datagridview将消失

如标题中所述,我在前面有一个带有Datagridview的表单。 datagridview比后面的我的表单小,我希望每当我点击Datagridview以外的任何地方时,Datagridview都会消失。 我的代码如下所示: this.dataGridView1.Leave += new System.EventHandler(this.focus); 并且Eventhandler的定义如下: private void focus(object sender, EventArgs e) { if(dataGridView1.Focused == false) { dataGridView1.Visible = false; } } 我的问题是,当我的表单中的新事件被激活时,我的Datagridview才会消失,但是当我在表单上的文本框中单击时,我的Datagridview才会消失。 谁能帮我?

点击链接事件webbrowser c#?

我想在我的winform中通过Web浏览器控件在IE浏览器中打开一个链接…当用户点击它在Internet Explorer浏览器中打开的链接时,webbrowser控件将导航到一个页面。

Visual Studio设计器中的抽象通用UserControlinheritance

在我的一个项目中,我正在使用抽象的UserControl。 为了能够在Visual Studio中设计此控件,我使用了本答案中提出的代码。 现在我想使用另一个抽象的UserControl,它也是通用的。 但如果我这样做 [TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<MyBaseControl, UserControl>))] 我收到了编译器错误 CS0416:属性参数不能使用类型参数 删除类型参数显然也无法编译。 我无法从非generics基类派生MyBaseControl,因为它已经从通用基类派生,所以我尝试使用接口进行装饰并使用它如下: [TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider))] 这确实编译但是当我打开设计视图时,我的控件不会被渲染,而是我得到了错误 提供的generics参数的数量不等于generics类型定义的arity。 有办法解决这个问题吗?

C#中Datagridview的数字格式

我想以数字格式设置datagridview值。 目前我得到这个: 我想要这样的东西: 我用过这段代码: dgvmain.DefaultCellStyle.Format = “#.##0”; 而这段代码 dgvmain.Columns[“Amount”].DefaultCellStyle.Format = “#.##0”; 但这两者都不起作用。

如何在DataGridView中使用Enter键作为Tab键

我有一个5列的DataGridView 。 如果在第一列中按Enter键,焦点将移至下一行。 当我按下Enter键时,我想将焦点移到下一列 。 private void dgvComp_CellEnter(object sender, DataGridViewCellEventArgs e) { if (dgvComp.CurrentRow.Cells[e.ColumnIndex].ReadOnly) { SendKeys.Send(“{tab}”); } } 在上面的代码中,我将列2,3和4作为只读列。 如果按Tab键,焦点应直接转到第5列。 我怎样才能做到这一点?

最小化到托盘使forms不可见

我使用NotifyIcon使我的表单最小化到托盘在后台工作。 但是下面的代码根本不显示应用程序图标。 forms完全不可见。 我必须从任务管理器中删除它。 private void Button1_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; if (FormWindowState.Minimized == this.WindowState) { Hide(); this.ShowInTaskbar = false; notifyIcon1.Visible = true; } } 可能是什么原因? 我想看看我的app-icon重新打开表单。

DataGridView覆盖顶部,左侧标题单元格单击(全选)

我想覆盖DataGridView标题/列单元格(顶部,左侧单元格)中鼠标单击的行为。 该单元格会导致选择所有行。 相反,我想阻止它选择所有行。 我看到一个RowHeaderSelect和ColumnHeaderSelect的事件,但没有一个针对该顶部左侧标题单元格的事件。 有任何想法吗? 我只是在失明吗?

是否可以读取文件?

我正在开发一个应用程序,它检查由单独的程序(不是由我编写)对文件所做的更改。 如果检测到更改,则会打开文件,读取最后一行,然后关闭文件。 我正在使用以下代码来确保我的程序不会尝试锁定文件,但只在读取模式下打开它: FileStream fs = new FileStream( _scannerFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); StreamReader sr = new StreamReader(fs); var str = sr.ReadToEnd(); sr.Close(); fs.Close(); 不幸的是,尽管如此,每当我的程序尝试读取文件时,我仍然会收到以下错误: System.IO.IOException was unhandled Message=”The process cannot access the file ‘D:\\LSDATA\\IdText.txt’ because it is being used by another process.” Source=”mscorlib” StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess […]

在Designer中删除GenerateMember和Modifiers属性

我创建了一个Button后代,我隐藏了所有不使用的属性。 我是这样做的: [Browsable(false)] [Bindable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Obsolete(“”, true)] public new Boolean AllowDrop { get; set; } 大多数属性都被正确隐藏,无法使用。 但是有两个属性是我无法摆脱的。 有没有办法在Designer中删除GenerateMember和Modifiers?

在Windows窗体中切换开关控件

我正在使用CheckBox设计一个Toggle Switch CheckBox ,但是目前我的控件只画了一个圆圈。 如何绘制如下图像的圆形图形以及如何根据控件的值更改圆的位置以表示已检查和未检查的状态,如下图所示: 这是我的代码: public class MyCheckBox:CheckBox { public MyCheckBox() { this.Appearance = System.Windows.Forms.Appearance.Button; this.BackColor = Color.Transparent; this.TextAlign = ContentAlignment.MiddleCenter; this.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.FlatAppearance.BorderColor = Color.RoyalBlue; this.FlatAppearance.BorderSize = 2; } protected override void OnPaint(PaintEventArgs e) { this.OnPaintBackground(e); using (var path = new GraphicsPath()) { var c = e.Graphics.ClipBounds; var r = this.ClientRectangle; r.Inflate(-FlatAppearance.BorderSize, […]