winforms

Using TransactionScope with typed dataset

I have a WinForm application querying SqlCe database using typed-dataset tabledapters. I have a main form assembly and a database assembly which handles every db operation. I'm having problems with updating using tableadapter in a transaction and I'd appreciate if anyone could give me any ideas why. Update() method gives this error: "...

Can you use Settings.Settings file for ASP.Net sites also?

I have a code base that has been used as an ASP.Net web application. It's now branching out and being used as part of two WinForms applications. The main difference is that the WinForms apps should store their settings "per user" and the web app only needs to store the settings at the "application" level. They are the same settings, bu...

How do I store a rating in a song?

I want to be able to store information about a song that has been opened using my application. I would like for the user to be able to give the song a rating and this rating be loaded every time the users opens that file using my application. I also need to know weather I should store the ratings in a database or an xml file. ...

How do I extend a WinForm's Dispose method?

I am getting this warning from FxCop: "'RestartForm' contains field 'RestartForm.done' that is of IDisposable type: 'ManualResetEvent'. Change the Dispose method on 'RestartForm' to call Dispose or Close on this field." Ok, I understand what this means and why this is what needs to be done... Except System.Windows.Forms.Form doesn'...

What is Delphi's equivalent of C#'s invoke action on form(How to invoke in Delphi) ?

Hello, In my C# project,I used the following code to access my form outside its own class. public static FormMain singletonInstance { get; private set; } public static void PFA(Action<FormMain> action) //PFA = PerForm Action { var form = FormMain.singletonInstance; if (form != null) { form....

What are the common practices for notifying a user of invalid input?

In my company, I've seen several approaches for notifying a user when their input is invalid (our validation is generally done when the user clicks some form of a "Submit" button). Here are the most common approaches I've seen: Using the ErrorProvider class to communicate which controls contain invalid input. (this is my current pref...

Is there a more performant alternative to ImageList.Images.Add?

I have a winforms ImageList which contains 200 256x256 images. When I add the images, 1 by one, half of the programs time spent on the Add method according to ANTS .NET profiler. So the program takes 10 secs to launch and 5 is spent there. That is very slow in my opinion. I implemented the same thing using ImageList.Images.AddRange. T...

Image.FromFile is very SLOW. Any alternatives, optimizations?

I have a winforms image list which contains say like 200 images 256x256. I use the method Images.FromFile to load the images and then add them to the image list. According to ANTS .NET profiler, half of the program's time is spent in Images.FromFile. Is there a better way to load an image to add to an image list? Another thing that mi...

Fast way to enumerate all files including sub-folders

Does anyone know of a faster way to enumerate through a directory and sub-folders to gather all the files in the enumeration? This is what I have right now: Public Shared allFiles() As String allFiles = Directory.GetFiles(<ServerLocation>, "*.*", SearchOption.AllDirectories) Thanks! JFV EDIT: I am enumerating these files from a ser...

Parent window and thread affinity

I'm having a WinForms application where I would like to perform some long-running operations, e.g. imagine Explorer copying 2 big files in parallel. For each of those long-running operations I'm starting a separate UI thread (which includes pumping messages/Application.Run/Application.ExitThread) where I create an instance of the IProgre...

Tool tip vanishes after drag and drop

Hi I have got a C# UserControl in a Windows Forms Application which supports drag and drop. In my case, the location of the Control is not changed when dragging, only a new Control is spawned where the cursor is released. This UserControl also owns a ToolTip. When I move my mouse over the Control, the tool tip pops up. Drag and drop als...

C# Set the visibility of a label using the result of String.IsNullOrEmpty

Hi I am trying to set the visibility of a label based on a textbox string being empty. I have the following code: MyLabel.Visible = String.IsNullOrEmpty(MyTextBox.Text); Why does MyLabel not appear when the textbox is left empty? Update I have tried placing this code in the Text_Changed event of the textbox and it still doesn't w...

C# - Partial Class in the VS2005 project

Possible Duplicate: In Visual Studio (2008) is there a way to have a custom dependent file on another custom file? How can I add a partial class in a VS2005 project so that it shows up as a code behind file for the main file? For example: I want to keep my class-properties in a file named, MyClass.cs and I want to keep my class...

Can I put commands after Form.Close() ?

In C#, Suppose I am in a form, and I pressed a button I made to close it. this.Close(); some_action(); //can I do this?? can I perform another action after I closed the form or does the thread die and everything after that is lost? ...

Associating Windows Forms TreeView items to actual data

So - working with C# and Windows Forms, I have a bunch of "Task" classes. Every class has a List<Task>, so that they can have any number of children (and the children can obviously have more children...) These tasks are stored in a "Project" class (in a List<Task>, obviously), which is then serialized to XML. I have a function to recurs...

To handle exception with every form or just at main

I have a question about handling exception. I have a Winform that uses a webservice proxy on each form for data retrieval and processing. Here is where I really got confused and having a long time deciding which is better. A. For each call in the web service do a try catch to display the error message and allow the user to re try the pr...

Calling Console.WriteLine(ex.Message) to prevent warning message

We usually catch exception in the upper level of a code like the GUI (forms). But I usually have this kind of code try { } catch(Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show("Application has encountered error...."); } I could just catch(Exception) without the identifier because I do not need the message on runti...

How do I determine when to show a tooltip?

I'm writing a calendar control in .Net WinForms that will show a tooltip for each date. What's the best way to determine when to show the tooltip? Showing it immediately in MouseMove would make it get in the way, so I'd like it to show when the mouse hovers over each date cell. The MouseHover event only fires on the first hover after ...

Should a cancel button ask for confirmation?

If a user clicks a cancel button should it pop up a dialogue asking for confirmation? If so, should this be all the time, or only when there are unsaved changes on a form? ...

Application.Exit

Hello everyone, I am using VSTS 2008 + .Net 3.5 + C# to develop Windows Forms application. My confusion is, seems Application.Exit does not force application to terminate? If not, which method should I call to make application terminate? EDIT 1: Normally the main method is like this, how to exit Main function gracefully without callin...