Tag: winforms

将bool属性绑定到WinForm的BackColor属性

我在WinForm应用程序中有一个Form ,它包含一个TextBox ,这个TextBox绑定到Person对象的FirstName属性。 public class Person { string firstName; public string FirstName { get { return firstName; } set { firstName = value; this.isOdd = value.Length % 2; } } bool isOdd; public bool IsOdd { get {return isOdd; } } } 当我的应用程序运行时,此Form显示并且用户可以将他/她的名称键入TextBox,如何将Form BackColor属性绑定到Person对象的IsOdd属性(当IsOdd为True BackColor设置为Color.Green以及何时是否为False , BackColor设置为Color.Red )?

MaskedTextBox的多线掩码

我在Winforms应用程序中有一个MaskedTextBox 。 我需要一个多线面具,fe: “999999\r\n 999999\r\n 999999\r\n 00/00/0000” 我阅读了msdn文档 ,并惊讶地发现没有“新行”或类似的东西。 我知道我可以编写自己的用户控件来解决此问题,但屏蔽文本框将是一个更简单的解决方案。 所以我有两个问题:有没有办法在面具上添加新线? 如果没有,为什么Control支持多行 – 不是没用的? 提前致谢

C#中的SplitContainer拆分器?

我正在使用拆分容器。 出于某种原因,分离器看起来像这样: 很难看到。 在两条黑线的中间是微弱的2条线。 如何解决此问题并在两行之间添加填充? 我使用Fixed Single作为我的边框样式。

如何设置C#winforms应用程序来托管SignalR Hubs?

我已阅读SignalR文档并观看了一些video,但我无法让SignalR在winforms应用程序中托管。 我尝试过在SignalR wiki上使用源代码: https : //github.com/SignalR/SignalR/wiki/Self-host 如果你看一下“Full Sample – Hubs”,那么“server”变量是什么? 我不明白这是如何工作的或如何将其转换为C#。 根据维基“默认的SelfHost实现是基于HttpListener构建的,可以托管在任何类型的应用程序中(控制台,Windows服务等)。” 我想在C#中托管SignalR并在asp.net中使用它。 有谁可以请我解释一下这个问题?

C#Invalidate不调用paint方法

我有OnPaint方法覆盖在屏幕上绘制一个椭圆。 protected override void OnPaint(PaintEventArgs e) { MessageBox.Show(“Paint”); if (debugStarted) { int y = rtbLogicCode.PlaceToPoint(new Place(0, debugLine)).Y; if (rtbLogicCode.GetVisibleState(debugLine).ToString() == “Visible”) { e.Graphics.FillEllipse(new LinearGradientBrush(new Rectangle(0, y, 15, 15), Color.LightPink, Color.Red, 45), 0, y, 15, 15); } base.OnPaint(e); } } private void rtbLogicCode_Scroll(object sender, ScrollEventArgs e) { this.Invalidate(); } 滚动事件(在Richtextbox上)被正确处理,但即使我使表单无效,它也没有调用OnPaint函数(消息框未显示)。 可能的原因是什么? 编辑:我忘了提到我的子窗体的初始化函数(使用MDI属性添加为主窗体的控件),我设置以下样式: private void LogicCodeInit() { […]

如何在没有可见窗口的情况下启动.net Windows窗体应用程序?

我有一个.net Windows窗体应用程序,需要直接打开通知图标(系统托盘),没有可见的窗口。 我意识到我可以在onshown事件或类似的事情中做到这一点。 但如果我这样做,我会得到一个窗口的闪光。 我怎么能避免那个闪光灯? 我已经尝试修改我的Program.cs文件,如下所示: Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm frm = new MainForm(); frm.Visible = false; Application.Run(frm); 但是这不起作用,因为Application.Run()使表单可见。 我很确定我会错过一个简单的答案。 任何帮助是极大的赞赏。

c#:在子项目上显示工具提示

我有一个listview,在其中一列(不是第一列)中我想显示错误代码。 我无法做的是显示工具提示。 我有 this.lstList.ShowItemToolTips = true; … ListViewItem value = lstList.Items.Add(name, name, 0); … if (lstList.Columns.Contains(lstColErrorCode)) { value.SubItems.Add(new ListViewItem.ListViewSubItem(value, errorCode.ToString())); value.ToolTipText = errorCode.ToString(“X”); } 我想得到代码的hex值,显示在十进制值上方的工具提示中,但它显示在名称上方。 我无法得到任何我试图工作的东西(比如试图获得子项目的坐标)。 我将不胜感激任何建议。

DataGridView绑定问题:“索引-1没有值。”

我有一个datagridview绑定到绑定源和窗体上的几个按钮。 一个按钮将一个项目添加到绑定源,另一个按钮删除当前选定的项目。 还有一个事件处理程序,它侦听CurrentChanged事件并更新“删除”按钮的“已启用”状态。 在我从datagridview中删除最后一项之前,所有东西都是笨拙的。 然后我看到一个非常丑陋的例外: at System.Windows.Forms.CurrencyManager.get_Item(Int32 index) at System.Windows.Forms.CurrencyManager.get_Current() at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs e) at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred) at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick) at System.Windows.Forms.DataGridView.SetAndSelectCurrentCellAddress(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick, Boolean clearSelection, Boolean forceCurrentCellSelection)\r\n at System.Windows.Forms.DataGridView.MakeFirstDisplayedCellCurrentCell(Boolean includeNewRow) at System.Windows.Forms.DataGridView.OnEnter(EventArgs […]

更改statusStrip的高度

我在VS2010中有一个带有statusStrip的简单windows窗体,无论我尝试什么,statusStrip的高度都不会改变,改变高度的正确方法是什么? 谢谢

你如何使用Windows客户端应用程序中的openAuth?

我正在考虑将公共API集成到现有的Windows窗体应用程序中。 api需要openAuth身份validation。 我见过的所有这些例子都是基于网络的应用程序。 如何在客户端应用程序上使用openAUth? 谢谢