winforms

C#: Using event handlers vs overriding event-firing methods

I am creating a subclass of Button and would like to add custom functionality to some of its events such as OnClick. Which is the more desirable way to do it? Do I override OnClick: protected override void OnClick(EventArgs e) { base.OnClick(e); doStuff(); } or should I instead link up the OnClick event to an event handler d...

How do you set a DateTimePicker to be read only?

I have a DateTimePicker (nullable version) that I need to be read only. I'm not happy with the display if it is disabled, so wanted to know if anyone had a nifty example of how to stop updates on the field? Thanks. ...

Winforms with MEF

I have a winforms App that uses different tabs. I would like to use MEF to be able to add more tabs that are imported at startup. I am having a hard time figuring out how to go about doing this. Edit: Here is what I did. I took the main winforms class and striped it down so that there is only a TabControl in it which I expose to eac...

Raising events asynchronously

I'm looking into options for doing asynchronous event dispatching in a component that has many subscribers to its events. In perusing the options, I ran across this example: public event ValueChangedEvent ValueChanged; public void FireEventAsync(EventArgs e) { Delegate[] delegates = ValueChanged.GetInvocationList(); foreach (De...

Forms Databinding - DataSet not updating?

I have a Form (Compact Framework, actually) with a few fields, a date and a string, among other things. Both TextBox controls are bound to properties in a BindindSource. The BindindSource has a DataSet as its DataSource property, and the DataMember is a table in a SQL CE database. When I want to add a new row, I call bindingSource.AddN...

What causes a window to not appear in the taskbar until it's Alt-Tabbed to in Vista?

When our app is started programatically (either through custom action in MSI installer or when starting a new instance) in Windows Vista (also happens in Windows 7 Beta) it won't appear in the taskbar and isn't focused. Alt-tabbing to it will make it appear in the taskbar properly and stay there. What causes this? I've seen this in so...

Data-bound WinForms form - how to format dates?

I have a form with a date value in a TextBox control. The form uses data binding with a BindingSource against a DataSet and a SQL 2005 CE database. Where do I control the formatting of the date? Nowhere in the properties along the way did I see a possibility to strip out the time part, for instance. I could of course do it in the databa...

Reading lots of characters and updating a textbox

I am reading data from a stream (provided by a process) character by character and adding it to a textbox so the user can see. The only problem is, this is SLOW. The user needs to see the data as it is given to the program (with little to no delay). I would like something like how terminals handle text, it can scroll by so fast that it's...

How do I find out which control has focus in .Net Winforms?

How do I find out which control has focus in winforms? ...

.Net Winforms Tell if Exit button was pressed

I'm using some controls that trap validation when anything happens--including when users press the exit button. Is there a way to tell if the exit button was pressed? ...

C# Implementing Auto-Scroll in a ListView while Drag & Dropping

Hi, How do I implement Auto-Scrolling (e.g. the ListView scrolls when you near the top or bottom) in a Winforms ListView? I've hunted around on google with little luck. I can't believe this doesn't work out of the box! Thanks in advance Dave ...

Getting screenshot of Child Window

Hello Everyone, If I have a handle to a window, how do I take a screenshot of any new child windows when they show up? Right now I have code that takes a screenshot every .1 seconds of a windows form. When I click on a drop down list box the subsequent screenshots do not include it. Using spy++ I can see that a new child window was c...

saving a file and automatically create directories

i am concatenating a number of variables and i want to save that string as a file path. is there a way it will automatically create all appropriate directories if they dont exist without having to check "if exists" on each one for example . . "C:\" + a + "\" + b+ "\" + d + "\" + d + ".txt" ...

How to update GUI from another thread in C#?

What is the simplest way to update an label from another thread? My problem: I have a winform(thread1), from that I'm starting another thread(thread2). While thread2 is processing some files I would like to update a label on the winform, with status from thread2. How can I do that? ...

Extracting keyboard layouts from windows

OK, this is a slightly weird question. We have a touch-screen application (i.e., no keyboard). When users need to enter text, the application shows virtual keyboard - hand-built in WinForms. Making these things by hand for each new language is monkey work. I figure that windows must have this keyboard layout information hiding somewher...

How do I change the ForeColor of a GroupBox without having that color applied to every child control as well?

I need to change the group box text to a specific color without changing the color of what is inside the group box. The following code sets the ForeColor of the GroupBox to pink but this settings cascades to all the child controls as well: groupbox.ForeColor = Color.Pink How do I change the ForeColor of a GroupBox without having tha...

Validating Event Results in Loss of Button Click Event in Winforms

Background: I have a form with a "clear form" and a "cancel" button. If I have invalid data inside a dropdown and click either of these buttons the dropdown's validating event fires. I've added code to the validating event to succeed when either "clear" or "cancel" are pressed. Problem: I would expect that the next thing that will h...

Windows Forms - Report Designer

Are there solutions available for allowing users to define report layouts within a WinForms app? We are playing with xml, xslt, and Word have some ok results, but are wondering if there are better options. We would like to: Set margins, padding, positioning of elements Declare column based or continuous report elements Does not need ...

Why can't I enter text in Winform hosted in ATL dialog?

I am working on embedding winform controls into an ATL dialog (see here for how I did so far). Now I have encountered a rather strange problem. For some reason, the text fields in my winforms display fine, but I am unable to change the text in them by typing on the keyboard. However, I can copy and paste text from elsewhere into the te...

What are the benefits to closing a form and reloading all the data as opposed to hiding and showing the form in C#?

When working with Windows forms in C#, is it safer/more beneficial resource-wise to completely close the form each time and reload the data when you need the form again, as opposed to just hiding the form and keeping it all in memory? ...