.net-2.0

How do i make sure that List<T>.Contains(T) works with my custom class?

跟風遠走 提交于 2019-12-14 04:17:07
问题 I use .net 2.0 (C#) I have a Person class, and i pupulate List< Person> p from the database. i know for a fact that my list has duplicates, but when i try to remove the duplicates they don't get removed. Does my Person class need to implement any interfaces for List< T>.Contains(T) to work properly? Any other ideas? Thank you. 回答1: Your Person class should implement IEquatable 回答2: You should override Equals and GetHashCode method. 回答3: The example you reference is not a solution for removing

Build VS2008 projects with .Net 2.0/.Net 3.5 using NAnt

微笑、不失礼 提交于 2019-12-14 04:06:00
问题 I'm trying to write a build file to build a simple C# solution but it is failing with the error: Unknown task or datatype . My solution is written in VS2008 but targeted at .Net 2.0 (I'm using Vista if that helps). I've already seen the other question running-builds-using-net-3-5-msbuild-and-nantcontrib and have tried the suggested solution and have made the change to my NAnt.exe.config file. I've tried changing the solution properties to target .net 3.5 (and changing the build file

How to use AddFontResource in c# for Windows CE 5.0 application with .NET 2.0

家住魔仙堡 提交于 2019-12-14 03:04:42
问题 I'm trying to develop a Smart Device program for Windows CE 5.0 device in my car with Visual Stdio 2008 pro and c# with .NET 2.0. I want to add a font using AddFontResourceEx, but I can't get it to work. Here is the code: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private const uint FR_PRIVATE=0x10; [DllImport("GDI32.dll",EntryPoint="AddFontResourceEx")] static extern int AddFontResourceEx(string lpszFilename, uint fl, IntPtr pdv); private void button1_Click

How do I indicate a validation requirement to users of my class?

烈酒焚心 提交于 2019-12-13 15:12:27
问题 I'm implementing a class that wraps around an xml document with a very strictly defined schema. I don't control the schema. One of the properties in the class is for an element value that the schema indicates must match a certain regular expression. In the setter for the property, if a string doesn't match the expression I'm throwing an exception. My question is, how can I better communicate to users of my class the requirements for this field? Is there an attribute I can use? Xml comments

Finding the number of occurences strings in a specific format occur in a given text

帅比萌擦擦* 提交于 2019-12-13 15:09:39
问题 I have a large string, where there can be specific words (text followed by a single colon, like "test:") occurring more than once. For example, like this: word: TEST: word: TEST: TEST: // random text "word" occurs twice and "TEST" occurs thrice, but the amount can be variable. Also, these words don't have to be in the same order and there can be more text in the same line as the word (as shown in the last example of "TEST"). What I need to do is append the occurrence number to each word, for

Prevent from generating Form.resx

有些话、适合烂在心里 提交于 2019-12-13 13:42:02
问题 I have a form that inherits from another from. In the designer, whenever I adjust something like control size or location, VS auto-generates a resx file for that form. The resx just contains some KeyValuePairs for comboboxes, w/c are unnecessary really since these values are already defined in the parent class. Aside from this, the designer.cs also gets update w/ inherited properties such as Text, NumericUpDown.Value, DisplayMember, ValueMember, etc, w/c again are already defined in the

How to put an icon in a MenuItem

强颜欢笑 提交于 2019-12-13 06:41:25
问题 Is there a way to put an icon next to the text in a MenuItem? I use the following code to display a popup menu when the user right clicks in a user control: ContextMenu menu = new ContextMenu(); MenuItem item = new MenuItem("test", OnClick); menu.MenuItems.Add(item); menu.Show(this, this.PointToClient(MousePosition)); I would like to put a icon to the left of the "test" string in the popup menu so that the user more easily recognizes it. Is there a way to do this other than by setting the

Open Notepad and add Text not working

白昼怎懂夜的黑 提交于 2019-12-13 04:42:57
问题 I just saw this snippet from the internet but it doesn't work from me. It's suppose to open a new notepad application and add "asdf" into it. Is there any wrong on the code? [DllImport("User32.dll")] public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, [MarshalAs(UnmanagedType.LPStr)] string lParam); void Test() { const int WM_SETTEXT = 0x000C; ProcessStartInfo startInfo = new ProcessStartInfo("notepad.exe"); startInfo.UseShellExecute = false; Process notepad = System

Am I doing it right while reading a file?

此生再无相见时 提交于 2019-12-13 04:29:19
问题 This code is trying to read a file but giving error, System.IO.IOException: The process cannot access the file 'C:\doc.ics' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream.

Convert Html to a Printable Image

帅比萌擦擦* 提交于 2019-12-13 04:28:03
问题 I am working on a project which runs on .NET 2.0. My task is to recreate the data displayed in HTML as a prinatable image (with the resolution of at least 150dpi). I looked into several options, to no avail: The WebBrowser class object. While rendering html as an image, it uses the screen resolution on the server machine. The Sciter by Terra Informatica. It does not exposes a property with which one can set the resolution of the output image Awesomium can be used with .NET 4.0 or higher only.