Tag: winforms

DataGridView列显示虽然标记为不可见

我在这里绑定了绑定源生成代码的DGV。 // dgvDocumentList // this.dgvDocumentList.AllowUserToAddRows = false; this.dgvDocumentList.AllowUserToDeleteRows = false; this.dgvDocumentList.AutoGenerateColumns = false; this.dgvDocumentList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgvDocumentList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dMTitleDataGridViewTextBoxColumn, this.urlCol, this.idCol}); this.dgvDocumentList.DataSource = this.docListFetchBindingSource; this.dgvDocumentList.Dock = System.Windows.Forms.DockStyle.Fill; this.dgvDocumentList.Location = new System.Drawing.Point(3, 3); this.dgvDocumentList.MultiSelect = false; this.dgvDocumentList.Name = “dgvDocumentList”; this.dgvDocumentList.ReadOnly = true; this.dgvDocumentList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dgvDocumentList.Size = new System.Drawing.Size(336, 493); this.dgvDocumentList.TabIndex = 0; this.dgvDocumentList.CellDoubleClick += […]

在C#Windows窗体中更改控件状态时,如何忽略触发的简单事件?

我在C#Windows窗体中创建一个简单的表单,并遇到一个常见的情况,一个控件可以改变另一个控件的状态,但两个控件的事件都会触发其他一些方法。 例如,考虑一个Checkbox和NumericUpDown ,其中任何一个的状态或值应触发重绘的内容。 NumericUpDown依赖于Checkbox这意味着除非选中Checkbox否则可以禁用或忽略它。 但是,用户可以方便地更改NumericUpDown值,并自动检查Checkbox是否已经存在。 所以这里是有问题的方法: private void chkState_CheckedChanged(object sender, EventArgs e) { RedrawStuff(); } private void numStateValue_ValueChanged(object sender, EventArgs e) { if (!chkState.Checked) chkState.Checked = true; RedrawStuff(); } 问题当然是更改NumericUpDown值会导致RedrawStuff()触发两次。 我的解决方法是引入一个布尔值,我可以有效地否定这种行为,但有时它会变得混乱: bool _preventStateChange; private void chkState_CheckedChanged(object sender, EventArgs e) { if (_preventStateChange) return; RedrawStuff(); } private void numStateValue_ValueChanged(object sender, EventArgs e) { _preventStateChange = true; […]

如何在c#winforms中的app.config文件上动态更新应用程序设置键值对

如何在c#winforms中的app.config文件上动态更新应用程序设置键,值。 键,值列在下面

查询值和目标字段的数量不是相同的错误

我在将数据插入数据库时​​遇到错误。 错误是: “查询值和目标字段的数量不相同”。 插入代码: OleDbConnection vconn = new OleDbConnection(“Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Mutyyba\\Documents\\Database1.accdb”); vconn.Open(); string name = textBox1.Text; string address = textBox3.Text; int rollno = Convert.ToInt32(textBox2.Text); string vquery = “insert into Table1 values(@vname,@vrollno,@vaddress)”; OleDbCommand vcomm = new OleDbCommand(vquery, vconn); vcomm.Parameters.AddWithValue(“@vname”, name); vcomm.Parameters.AddWithValue(“@vrollno”, rollno); vcomm.Parameters.AddWithValue(“@vaddress”, address); vcomm.ExecuteNonQuery(); MessageBox.Show(“your record has been recorded sucessfully!”); vconn.Close(); 我究竟做错了什么?

从另一个类更改文本框

我正在尝试更改位于的文本框的值 public partial class Form1 : Form 来自另一个class级。 我尝试过这样的事情 public void echo(string text) { this.textBox1.AppendText(text + Environment.NewLine); } 从另一个课我称之为 Form1 cout = new Form1(); cout.echo(“Does this work?”); 我得到空白输出。 我也尝试将static关键字添加到echo方法中,但我得到了相同的结果。 我搜索了Stack Overflow并没有得到任何解决方案。 有一件事触发了我,如果我添加cout.Show()相同的表单弹出有效的textBox1内容。 这是为什么? 为什么它不立即显示内容? 我该如何解决这个问题?

Windows窗体combobox控件的奇怪行为

我正在开发一个小型桌面应用程序,我的表单上有几个下拉列表(combobox-es)。 我填充了一个字符串列表,这些字符串将用作所有字符串的数据源。 这是我的Form.cs类的示例: List datasource = new List(); datasource.Add(“string 1”); datasource.Add(“string 2”); 然后我将此列表设置为几个combobox的数据源: cmbDataType1.DataSource = datasource; cmbDataType2.DataSource = datasource; 这一切都发生在同一个方法中,从Form构造函数调用。 这是一个奇怪的部分:在我更改其中一个中的选定值后,将在另一个中设置相同的值。 没有设置SelectedIndexChange事件。 我搞砸了某个地方,但我不能把手指放在哪里……

如何防止禁用的ToolStripMenuItem在鼠标hover时显示边框?

是的,与标题完全相同,在我的项目中,一些toolstripmenuitems被禁用。 但是当我将光标放在菜单项上时,会出现一个蓝色边框,如下所示: 但我不想要这个。 我想这样: 你能帮帮我吗,我该如何防止这个蓝色边框?

MS图雷达轴频率

我想在WinForms应用程序中使用MS Chart控件绘制雷达图表。 这个图表包含1天的数据,我有每秒的数据,所以我有86 400 xy值对。 X轴包含日期,y我的int值。 我的测试代码是这样的: var fromDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); var toDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); List xValues = new List(); List yValues = new List(); var iterDate = fromDate; var i = 0; while (iterDate <= toDate) { xValues.Add(iterDate); yValues.Add(i); iterDate = iterDate.AddSeconds(1); […]

c#chart control删除条形图中条形之间的空格

我有一个使用c#.net图表控件制作的条形图,如下所示: 如您所见,图表上的每对红色和蓝色条之间都有一个空格。 有没有办法删除这些空格? 提前致谢! 编辑: 以下是设计师的作品 chartArea1.Name = “ChartArea1”; this.CHRT_DPS_HPS.ChartAreas.Add(chartArea1); legend1.Name = “Legend1”; this.CHRT_DPS_HPS.Legends.Add(legend1); this.CHRT_DPS_HPS.Location = new System.Drawing.Point(3, 271); this.CHRT_DPS_HPS.Name = “CHRT_DPS_HPS”; series1.ChartArea = “ChartArea1”; series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar; series1.Color = System.Drawing.Color.Red; series1.Legend = “Legend1”; series1.MarkerBorderWidth = 0; series1.Name = “DPS”; series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.String; series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double; series2.ChartArea = “ChartArea1”; series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar; series2.Legend = “Legend1”; […]

WebBrowser从我的表单“窃取”KeyDown事件

我在Form有一个WebBwoser ,我想捕获Ctrl + O组合键以用作菜单项的快捷方式。 我的问题是,如果我单击WebBrowser并按Ctrl + O,将弹出一个Internet Explorer对话框,而不是执行我的菜单项。 我将Form的KeyPreview属性设置为true 。 此外,我为KeyDown事件添加了一个事件处理程序,但在单击WebBrowser后它停止调用。 我怎样才能解决这个问题?