.net-2.0

How do I fire an event safely

二次信任 提交于 2019-12-04 17:24:56
When there are no subscribers to an event how do I ensure that an exception will not be thrown if the event is fired. // Delegate declaration public delegate void _delDisplayChange(object sender,string option); // Event declaration public event _delDisplayChange DisplayChange; //throwing the event DisplayChange(this, "DISTRIBUTION"); Here is the recommended way to do it: protected void RaiseDisplayChanged(string message) { var handlers = DisplayChange; if(handlers != null) handlers(this, message); } Copying the event handlers enumeration before checking does two things: If DisplayChange

Check if date range is sequential in c#?

徘徊边缘 提交于 2019-12-04 17:20:59
问题 Assume I have a user interface where the user can select days. Is there a way to check if the days selected are sequential, such as: 4/4, 4/5, 4/6, 4/7, 4/8, 4/9, 4/10 or 4/29, 4/30, 5/1, 5/2, 5/3 I know I probably can loop through the date range and check, but I was more curious if there was a built in method already to check for this. Regarding the above scenarios, they are in order and they can roll over into the next month. I am using the .NET Framework 2.0 and can't use LINQ. Regarding

asp.net CustomValidator never fires OnServerValidate

自作多情 提交于 2019-12-04 17:07:57
问题 I have the following ASP page: <asp:Content ID="Content2" ContentPlaceHolderID="ShellContent" runat="server"> <form runat="server" id="AddNewNoteForm" method="post""> <fieldset id="NoteContainer"> <legend>Add New Note</legend> <asp:ValidationSummary ID="ValidationSummary1" runat="server" /> <div class="ctrlHolder"> <asp:Label ID="LabelNoteDate" runat="server" Text="Note Date" AssociatedControlID="NoteDateTextBox"></asp:Label> <asp:TextBox ID="NoteDateTextBox" runat="server" class="textInput"

Invoke() is blocking

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 16:58:16
问题 From time to time my applications GUI stops redrawing. There a lot of threads that are firing all kinds of events (like timers or network data ready etc.). Also there are a lot of controls that are subscribing these events. Because of that, all the event handlers play the InvokeRequired/Invoke game. Now I figured out that when the GUI freezes a lot of threads are waiting for Invoke() to return. Looks like the message pump stopped pumping. The handlers look like this: private void

Firing a method in form 1 on click of a button on form2

空扰寡人 提交于 2019-12-04 15:47:49
I am quite new to windows forms. I would like to know if it is possible to fire a method in form 1 on click of a button in form 2? My form 1 has a combobox. My form 2 has a Save button. What I would like to achieve is: When the user clicks on Save in form 2, I need to check if form 1 is open. If it is open, I want to get the instance and call the method that would repopulate the combo on form 1. I would really appreciate if I get some pointers on how I can do work this out. If there any other better way than this, please do let me know. Thanks :) Added: Both form 1 and form 2 are independent

.net - Glass effect in C# 2.0 applications

不打扰是莪最后的温柔 提交于 2019-12-04 15:47:47
How can I give a Vista or Mac OS X style glass effects on windows forms applications in .net 2.0? This is done using interop with the Vista DWM (Desktop Window Manager) API. For example, import these functions: [DllImport("dwmapi.dll")] static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMargins); [StructLayout(LayoutKind.Sequential)] struct Margins { public int cxLeftWidth; public int cxRightWidth; public int cyTopHeight; public int cyBottomHeight; } Then you can use this to "pull down" glass from the top of the window down into the client area: GlassMargins.Top = 40;

How do you provide a default type for generics?

前提是你 提交于 2019-12-04 15:15:17
问题 I have a class that currently has several methods that take integer parameters. These integers map to operations that the application can perform. I'd like to make the class generic so that the consumers of the class can provide an enum type that they have with all the operations in it, then the methods will take parameters of that enum type. However, I want them to be able to not specify a generic type at all, and have it default back to integers with no change in syntax from the current way

Allow wake timers Windows 7/Vista

…衆ロ難τιáo~ 提交于 2019-12-04 14:18:15
问题 I need to allow WakeTimers (computer wake up from sleep/hibernation) for all power plans set on plugged in to Enabled. I tried Win32_PowerSetting but it only works on english version of Windows. I need to use .NET 2.0 Thanks for responses ! 回答1: I suspect you can do this using API calls to powrprof.dll, as well as WMI, but I haven't had the time to figure that approach out. This setting appears to be simply a boolean registry key that is located according to your current power plan: HKEY

C# docking control library

别说谁变了你拦得住时间么 提交于 2019-12-04 14:09:12
问题 I'm looking for a docking control library for C# WinForms that works in NET 2.0, is freeware, doesn't use any P/Invokes (so that it's compatible with Mono) and isn't buggy. WeifenLuo would have been the best option here, but because it uses a ton of P/Invokes, I will never be able to get my software to be cross-platform. So any good suggestions? 回答1: I managed to get WeifenLuo's docking library control (DockPanel Suite) working on Mono, at the cost of some features. If anyone is interested,

.NET (WinForms) Grid Control with Collapse/Expand Capabilities

假如想象 提交于 2019-12-04 11:23:26
Anybody purchased/used a DataGrid/GridView control that allows Collapsing/Expanding Parent-Child relationships? The standard DataGrid control, which I am using in .NET 2.0, seems to have limited capabilities with regards to this functionality. The newer GridView control doesn't support this at all to my knowledge. I was thinking about developing a custom control but that could get expensive for my client.. I need this control for WinForms (not ASP.NET) thanks We've used Janus Grids here for years, very powerful, but have recently started using Developer Express controls on new products . . .