Textbox padding

As you have most likely discovered, Winforms Textboxes do not have a padding property. Since Panels do expose a Padding property, one technique would be to: Create a Panel Set its border to match a Textbox (e.g., Fixed3D) Set its background color to match a Textbox (e.g., White or Window) Set its padding to your … Read more

Change default icon

Run it not through Visual Studio – then the icon should look just fine. I believe it is because when you debug, Visual Studio runs <yourapp>.vshost.exe and not your application. The .vshost.exe file doesn’t use your icon. Ultimately, what you have done is correct. Go to the Project properties under Application tab change the default … Read more

Showing a Context Menu for an item in a ListView

private void listView1_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { var focusedItem = listView1.FocusedItem; if (focusedItem != null && focusedItem.Bounds.Contains(e.Location)) { contextMenuStrip1.Show(Cursor.Position); } } } You can put connected client information in the contextMenuStrip1. and when you right click on a item, you can show the information from that contextMenuStrip1.

What is the difference between the Control.Enter and Control.GotFocus events?

The GotFocus/LostFocus events are generated by Windows messages, WM_SETFOCUS and WM_KILLFOCUS respectively. They are a bit troublesome, especially WM_KILLFOCUS which is prone to deadlock. The logic inside Windows Forms that handles the validation logic (Validating event for example) can override focus changes. In other words, the focus actually changed but then the validation code moved … Read more

Cross-thread operation not valid [duplicate]

You can’t. UI operations must be performed on the owning thread. Period. What you could do, is create all those items on a child thread, then call Control.Invoke and do your databinding there. Or use a BackgroundWorker BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, e) => { /* create items */ }; bw.RunWorkerCompleted += … Read more

Pass-through mouse events to parent control

Yes. After a lot of searching, I found the article “Floating Controls, tooltip-style”, which uses WndProc to change the message from WM_NCHITTEST to HTTRANSPARENT, making the Control transparent to mouse events. To achieve that, create a control inherited from Label and simply add the following code. protected override void WndProc(ref Message m) { const int … Read more