c#-2.0

How to change System.Windows.Forms.ToolStripButton highlight/background color when checked?

为君一笑 提交于 2019-11-27 03:07:10
问题 I have a ToolStripButton that is used as a radio button. When it is checked, a blue outline surrounds the button, but there is no background color. It is not clear enough for the user that the button is checked, so I would like to change the background color to make the check state more visible. How do I go about changing the highlight color when the Checked property is set to true? Here is a code snippet: this.hideInactiveVehiclesToolstripButton.CheckOnClick = true; this

Are event subscribers called in order of subscription?

孤者浪人 提交于 2019-11-27 03:04:55
问题 Is it safe to assume that event subscribers are called in order of subscription? Example: void One(object sender, EventArgs e) {} void Two(object sender, EventArgs e) {} event EventHandler foo; foo += One; foo += Two; Is One() always called before Two() when the event is fired? Edit: You should ofcourse not rely on it, I was just thinking. The idea was, that multicast delegates are similary to the COMMAND pattern. So I was just wondering. Ususally you would use a collection that keeps the

calling managed c# functions from unmanaged c++

随声附和 提交于 2019-11-27 01:09:06
问题 How to call managed c# functions from unmanaged c++ 回答1: Or use a project of mine that allows C# to create unmanaged exports. Those can be consumed as if they were written in a native language. 回答2: I used COM interop first, but by now I switched to IJW (it just works), as it is a lot simpler. I have a wrapper C++/CLR DLL (compile with /clr). A simple example (using statics to make the calls easier): namespace MyClasses { public class MyClass { public static void DoSomething() { MessageBox

Embedding a DOS console in a windows form

寵の児 提交于 2019-11-27 00:52:01
Is it possible to embed a DOS console in a Windows Form or User Control in C# 2.0? We have a legacy DOS product that my Windows app has to interact with, and it's been requested that an instance of the legacy product should run within the Windows application. At the moment, I'm using the user32.dll to locate the window that the DOS product is running in, minimising then maximising the window, and typing characters into the window. This isn't a very good solution to the problem, as it means my application has to store the window name in application settings, and requires that the user returns

how to close a running instance of Word document? (C#)

≡放荡痞女 提交于 2019-11-26 21:05:10
问题 I could see a lot of very similar threads all around, but nothing seem to give me a solution which ought to be very basic. From my winforms application, I need to close a running instance of a word document (opened from the application itself). When I open the word document from the application, I keep a track of it in a list. Now how can I close the same doc? Here is what I tried: private bool CloseWord(string osPath) //here I pass the fully qualified path of the file { try { Word

How to use WebBrowser control DocumentCompleted event in C#?

余生颓废 提交于 2019-11-26 20:14:19
Before starting writing this question, i was trying to solve following // 1. navigate to page // 2. wait until page is downloaded // 3. read and write some data from/to iframe // 4. submit (post) form The problem was, that if a iframe exists on a web page, DocumentCompleted event would get fired more then once (after each document has been completed). It was highly likely that program would have tried to read data from DOM that was not completed and naturally - fail. But suddenly while writing this question 'What if' monster inspired me, and i fix'ed the problem, that i was trying to solve. As

static readonly field initializer vs static constructor initialization

a 夏天 提交于 2019-11-26 19:18:34
问题 Below are two different ways to initialize static readonly fields. Is there a difference between the two approaches? If yes, when should one be preferred over the other? class A { private static readonly string connectionString = WebConfigurationManager.ConnectionStrings["SomeConnection"].ConnectionString; } class B { private static readonly string connectionString; static B() { connectionString = WebConfigurationManager.ConnectionStrings["SomeConnection"].ConnectionString; } } 回答1: There is

C# thread pool limiting threads

瘦欲@ 提交于 2019-11-26 18:00:54
问题 Alright...I've given the site a fair search and have read over many posts about this topic. I found this question: Code for a simple thread pool in C# especially helpful. However, as it always seems, what I need varies slightly. I have looked over the MSDN example and adapted it to my needs somewhat. The example I refer to is here: http://msdn.microsoft.com/en-us/library/3dasc8as(VS.80,printer).aspx My issue is this. I have a fairly simple set of code that loads a web page via the

C#: multiline text in DataGridView control

我的未来我决定 提交于 2019-11-26 17:55:15
Is it possible for the DataGridView control to display multiline text in a cell? I am using Visual Studio 2005 and C#. bniwredyc You should set DefaultCellStyle.WrapMode property of column to DataGridViewTriState.True . After that text in cells will be displayed correctly. Example ( DataGridView with one column): dataGridView1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True; dataGridView1.Rows.Add("test" + Environment.NewLine + "test"); ( Environment.NewLine = \r\n in Windows) dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dgv.Columns[1].DefaultCellStyle

How do I prevent print screen

放肆的年华 提交于 2019-11-26 17:45:46
问题 I have a requirement that an application I am working on prevent the user from being able to easily capture the contents of the screen. I have communicated that there is no feasible way to completely prevent this from happening, but I'm looking for methods to introduce some hurdles to the process. I'm using C#/.NET 2.0 and WinForms 回答1: You can't. The best you can do is render to a hardware accelerated device on an overlay, similar to what video players used to do. Basically, you paint your