winforms

C#/.NET: how do I close the application from a parent window?

I have a Windows application that has 2 Forms. From one form I am opening a 2nd form. When opening the 2nd form I am hiding 1 form and in the second foem I am starting a thread. Now I want to close the application. But I was not able to do that. On my 1st form I have tried: Form1 frm = new Form1(this, tcpClient); frm.ShowDialog(); this...

Is there a tool for winforms which can tell you what control your mouse is hovering on

I seem to remember a tool that could be used at runtime to tell you what the type of a control was when you hovered your mouse over the control. is there something similar for .Net? ...

windowservice versus API

Can anyone tell me the difference between windowservice and API. ...

How do I get ToolStripMenuItem Shortcut Key to work when WinForms control is hosted in VB6 Form.

We have a scenario where we are exposing a set of WinForms UserControls via COM to a Legacy VB6 application. We have 3 different controls which have a MenuStrip on it that has the Control-F shortcut key mapped to a menu item which invokes a control specific find items dialog when the shortcut is entered. When we try testing this code in ...

C# Execute function at specific time

Hello everyone. I made a little Windows Forms program to do some auto backup of some files on my disk. Right now I need to push a button before it is executed, but I want to make the program running and at 3am run the function that does the backup. I've researched a bit and found out i need a timer for this, but I've failed to use it s...

Inconsistant behavior of ListBox.SelectedIndices when SelectionMode = MultiExtended.

I have a Windows.Forms.ListBox on my form. Its SelectionMode is set to MultiExtended. That allows the user use both CTRL/Click and Shift/Click to select a multiple items. The behavior of the SelectedIndices list is inconsistant. If the user selects n consecutive items by doing a series of CTRL/Click operations, the list will have a Cou...

Is Winforms accessible from unmanaged C++?

Some classic Windows/C++ applications can't easily be moved to managed C++.net, due to use of external libraries. Is it feasible to use newer GUI libraries like winforms (or even WPF) with such applications, 'dropping in' new controls to replace stale-looking MFC? Or is it not really worth it, and would take a lot of time? ...

C# - Best way to retrieve accurate date?

What is the best way to retrieve the current date? Currently I am storing the date like this: string date = DateTime.Now.ToString("yyyyMMdd"); Obviously, if the user changes the date on their system, this will also be affected. I need a way to access an accurate date (preferable in central time) and store it as a string within my ap...

What is a good way to implement events in Passive View?

Hi, I am learning the Passive View pattern to keep my C# WinForms application easier to test and maintain. It has worked well so far but I wonder if there is a better way to implement Events than the way I am doing it now (and keeping them testable). This is what it looks like (omitting code not relevant for this example). Basically w...

How to hook up CNTL-x/c/v keypress events for cut/copy/paste routines

(This should be an easy one... but Googling for it is a mess of rabbit trails.) I have a Windows Forms app, with a TabControl. On the first tab (which is a bunch of textboxes), the CNTL-x/c/v keyboard shortcuts for cut/copy/paste work as expected. On the second tab (which is a DataGridView), the keyboard shortcuts don't do anything. Ho...

How do I Programmatically change Connection String un LINQ C# Winforms

Hey Guys. This question may be redundant, but i could not totally understand how to do this. I need to be able to, when the users Run my Winforms app, can search for the instance of SQL if the previous one are not available. I already have the check for the DB existence, and also made a dialog wich search for all the available instance, ...

Printing contents of controls in C#?

I have never printed anything using C#. I was just wondering what the standard way to do this was. On my form I have a few listboxes and a few textboxes. I would like to print their contents and show them in a print preview, with a nice layout in a table. Then from their I would like the user to be able to print. Thanks in advance! ...

Assignment to apparently nonexistent variables in VB.NET

I have some VB.NET (which I don't normally deal with) code which must be converted to C# (which I normally do). The code happens to be in a Windows Forms app. I notice a couple of places such as: Public Sub New() ParentWindow = Me where there is no ParentWindow variable defined, and it doesn't seem to be inherited here: Public ...

Detect and Prevent Overlapping Windows in C#

Anyone know of an efficient way of detecting movement of any windows currently open on a windows system? I need to detect a window's movement, determine if it collides with my applications Form, and bump it out from underneath if necessary. I know I can scan through an enumerated list and check each window -- but that is way to intensi...

WPF-XAML window in Winforms Application

Hi All, I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done. Kind Regards John ...

C# WinForms - picture / image box selection - like MS Paint

I'm working on a small project that involves me loading an image into a picture box within a windows form. I then need to be able to select and area of this image, and "crop" to that size - kind of like you can do in MS Paint. I was just wondering if anyone knew of any sample code available to help me start this? ...

Binding to commands in WinForms

How can a button be bound to a command in a view model like in WPF with MVVM? ...

Textbox autocomplete Property in .net 2.0

I have a question regarding Textbox autocomplete propert. I have set textbox autocompleteMode to "Suggest" and have set AutoCompleteSource to CustomerSource. I have a AutoCompleteCustomSource collection : "A" "A" "AA" "AAA" When i type "A" in textbox, suggest displays only one "A".Why is this ? And how to display both characters "A" ...

Close Windows Form while it is initializing

I have a winforms app that checks user credentials as it starts. If autharization fails I want to close the app. So I have been using the following Public Sub New() _CurrentUser.GetuserDetails If _CurrentUser.IsAuthorized then 'Let the app start Else 'Shut it down Me.Close() End IF End Sub However this produces a "Cannot ...

DataGridView paging

Hi, I have applications(WinForm) that gets some objects from webservice. After receiving array I transform array to DataTable and show data in DataGridView. Problem is when there are too many records. Of course I can change WS to send information in packages containing for example 100 objects but I'm not sure how to change DataGridView. ...