永远不会调用OnPaint覆盖

我已经在这里待了几天,这让我很生气。 我有一个inheritance自System.Windows.Forms.Panel的控件,我试图覆盖OnPaint。 它很简单,直截了当地说它。 public class CollapsiblePanel : System.Windows.Forms.Panel { public CollapsiblePanel() { // // Required for the Windows Form Designer // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // SetStyle ( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.Selectable , true ); } protected override void OnPaint(PaintEventArgs e) { // […]

当鼠标hover在按钮WPF上时如何制作一个改变图像的图像按钮?

我正在尝试制作一个图像按钮,当鼠标hover在按钮上时会改变图像,我尝试了一些东西 这是我尝试的最后一件事,但它不起作用: 我想只使用XAML,没有cs文件谢谢

从任何过程中获取密钥

我在网上看过很多解决方案,但没有一个完全符合我的要求。 我的应用程序在后台运行时,在给定进程(而不是我的控制台应用程序)中按下任何键的最佳/最简单方法是什么? 我不需要修改器或任何东西。

SQL Server,C#:事务回滚的超时exception

我有一个奇怪的问题。 我有一个.NET程序,我的进程逻辑需要在SQL Server 2005数据库上运行一个长时间的事务(~20分钟)。 没关系,因为没有人并行访问数据库。 当出现问题时,应该回滚事务。 不常见且没有任何可见模式的DbTransaction对象上的Rollback()操作会抛出DbTransaction : 消息:“超时已到期。在操作完成之前已经过了超时时间,或者服务器没有响应。” 堆栈跟踪: 在System.Data.SqlClient.SqlInternalConnection.OnError(SqlExceptionexception,布尔breakConnection) 在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 在System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj,UInt32错误) 在System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult,TdsParserStateObject stateObj) 在System.Data.SqlClient.TdsParserStateObject.ReadPacket(Int32 bytesExpected) 在System.Data.SqlClient.TdsParserStateObject.ReadBuffer() 在System.Data.SqlClient.TdsParserStateObject.ReadByte() 在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte [] buffer,TransactionManagerRequestType request,String transactionName,TransactionManagerIsolationLevel isoLevel,Int32 timeout,SqlInternalTransaction transaction,TdsParserStateObject stateObj,Boolean isDelegateControlRequest) 在System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest,String transactionName,IsolationLevel iso,SqlInternalTransaction internalTransaction,Boolean isDelegateControlRequest) 在System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest,String name,IsolationLevel iso,SqlInternalTransaction internalTransaction,Boolean isDelegateControlRequest) 在System.Data.SqlClient.SqlInternalTransaction.Rollback() 在System.Data.SqlClient.SqlTransaction.Rollback() 我不知道这是否真的是一个超时问题,因为代码有时会工作,有时候不会。 此外,我知道的唯一超时是ConnectionTimeout和CommandTimeout […]

公共静态字符串MyFunc()上的“预期的类,委托,枚举,接口或结构”错误。 什么是“字符串”的替代品?

我尝试使用以下静态函数时收到错误。 错误: 预期的类,委托,枚举,接口或结构 function(和类): namespace MyNamespace { public class MyClass { // Some other static methods that use Classes, delegates, enums, interfaces, or structs public static string MyFunc(string myVar){ string myText = myVar; //Do some stuff with myText and myVar return myText; } } } 这导致编译器愤怒地(红色)为public static string的字符串部分加下划线。 所以,我认为这意味着string不是类,委托,枚举,接口或结构。 我可以使用什么而不是string来返回字符串或类似字符串的对象? 在C#中似乎没有String (大写字母S)类。 编辑 :括号与某些注释代码不匹配 – […]

ASP.NET MVC3 WebGrid格式:参数

我试图在ASP.NET MVC3中使用新的WebGrid,并且我希望显示一组链接图标,执行各种操作(编辑,查看,删除)……为此,我有一个HtmlHelper扩展,基本上输出HTML: 扩展返回MvcHtmlString,它在Razor视图中单独使用时工作正常.Eg:@ Html.ActionLinkIconForEditAction(“Customer”,2) 问题是我需要在传递对象的ID时在WebGrid列中调用此帮助程序(每个操作一次)。 我难以理解的问题是编译器给我一个错误,说它无法将MvcHtmlString(或’lambda expression’取决于我尝试的调用)转换为格式预期的System.Func … 例如,这有效: grid.Column(header: “”, format: @@Html.ActionLinkIconForEditAction(“Customer”, 2)) 但这不是: grid.Column(header: “”, format: (customer) => @@Html.ActionLinkIconForEditAction(“Customer”, customer.Id)) grid.Column(header: “”, format: (customer) => Html.ActionLinkIconForEditAction(“Customer”, customer.Id)) 我明白了: Error 4 Argument 3: cannot convert from ‘lambda expression’ to ‘System.Func’ 或者这个电话: grid.Column(header: “”, format: Html.ActionLinkIconForEditAction(“Customer”, customer.Id)), 我明白了: Error 5 Argument 3: cannot convert from […]

Castle Windsor注册类与构造函数参数

我有以下课程: public class DatabaseFactory : Disposable, IDatabaseFactory where C : DbContext, BaseContext, new() { private C dataContext; private string connectionString; public DatabaseFactory(string connectionString) { this.connectionString = connectionString; } public C Get() { return dataContext ?? (dataContext = Activator.CreateInstance(typeof(C), new object[] {connectionString}) as C); } protected override void DisposeCore() { if (dataContext != null) dataContext.Dispose(); } […]

使用相同元素的多个副本初始化C#数组

在C ++标准模板库(STL)中,可以使用以下构造函数创建一个由同一元素的多个副本组成的向量: std::vector v(10, 2.0); 这将创建10个双打的向量,最初设置为2.0。 我想在C#中做类似的事情,更具体地说,创建一个n个双精度数组,所有元素都初始化为相同的值x 。 我提出了以下单行程序,依赖于generics集合和LINQ: double[] v = new double[n].Select(item => x).ToArray(); 但是,如果局外人会阅读此代码,我认为代码实际上不会立即显现。 我也关注性能,我想通过for循环初始化数组元素会更快(虽然我没有检查过)。 有没有人知道更清洁和/或更有效的方法来执行这项任务?

应用CQRS – 是否需要对薄读取层进行unit testing?

鉴于实现CQRS的一些建议提倡相当接近金属的查询实现,例如直接针对数据库(或者可能是基于LINQ的ORM)的ADO.NET查询,尝试unit testing是错误的他们? 我想知道它是否真的有必要吗? 我对此事的看法: 提供可模拟的“薄读取层”的额外架构复杂性似乎与将建筑仪式保持在最低限度的建议的本质相反。 有效覆盖用户可能构成的每个查询角度的unit testing数量是可怕的。 具体来说,我正在ASP.NET MVC应用程序中尝试CQRS,并且想知道是否打扰unit testing我的控制器操作方法,或者只是测试域模型。 提前谢谢了。

WCF NamedPipe CommunicationException – “管道已结束。 (109,0x6d)。“

我正在编写带有“状态工具”的Windows服务。 该服务托管一个名为管道端点的WCF,用于进程间通信。 通过命名管道,状态工具可以定期查询服务以获取最新的“状态”。 在我的开发机器上,我有多个IP地址; 其中一个是具有192.168.1.XX地址的“本地”网络。 另一个是“公司”网络,具有10.0.X.XX地址。 Windows服务在单个IP地址上收集UDP多播流量。 到目前为止,Windows服务只要使用“192.168.1.XX”地址就可以正常工作。 它始终正确地向客户报告状态。 一旦我切换到另一个“公司”IP地址(10.0.X.XX)并重新启动服务,我在检索状态时会得到连续的“CommunicationExceptions”: “There was an error reading from the pipe: The pipe has been ended. (109, 0x6d).” 现在,我不认为UDP客户端的“声明的”IP地址应该与Named-Pipe接口的function有关; 它们完全是应用程序的独立部分! 以下是相关的WCF配置部分: //On the Client app: string myNamedPipe = “net.pipe://127.0.0.1/MyNamedPipe”; ChannelFactory proxyFactory = new ChannelFactory( new NetNamedPipeBinding(), new EndpointAddress(myNamedPipe)); //On the Windows Service: string myNamedPipe = “net.pipe://127.0.0.1/MyNamedPipe”; myService = […]