In Windows Forms, I would like to show relationships using lines to show a connection between two forms inside an MDI parent similar to MS Access' relationship diagram.
What are my options for drawing lines underneath the children (or on parent background)?
If you are going to use MDI then what you would need to do is handle the Paint event of the MdiClient control that hosts the child forms. It's not actually exposed directly but you can access is via the Controls collection of the parent form. It will be the only child control of that type and, in most cases, the only child control. You can then use GDI+ to draw lines between the appropriate pairs of forms.
Related
I want to understand its logic and to modify. This library is refactored based on the open source library. I'm not very familiar with customization. Of course, I'll study hard.
How is it created automatically?
How is it grouped with controls, and where are properties controlled?
The Library: https://github.com/kelicto/KeLi.TreeListViewKit
How to Test: create a new form and add a TreeListView control.
Not sure i fully understand the question but:
WindowsForms comes with a UI design via Visual Studio. Users drag controls from the designer onto the target form. Each component on the form is clickable, and there is an associated Properties window; this is where values for the properties can be altered. The code in InitializeComponent, whether it be a form, or a custom control is automatically generated by the forms designer. e.g.: when you first start up there is a blank small form with no components.
Drag a textbox control from the left hand side and place it on the form. The form now contains a textbox. Click on the textbox and you can alter the properties of the textbox (name, value, width, even event handlers). Each change will alter how InitializeComponent works.
So if you wanted this custom component on your form you will need to compile the assembly it belongs and add the assembly so it can be referenced by the forms designer. Once this is done your TreeView component will be available to be dragged & dropped onto the form. Do this and you will also be able to set its properties.
Even custom components come with a designer piece; so if you were designing a component from scratch you could still drag / drop components onto that custom control and same as a form the implementation of InitializeComponent will change according to the components dropped, and the properties you set (and their location, anchoring etc which can be done on the main forms designer). I wouldn't recommend building a WindowsForms app without the designer, not that it cannot be done; ultimately it's code at the end of the day. But it's a lot more awkward to do without the visual designer component.
I have a series of forms that are inheriting control from a parent form. To manage space, I am trying to manoeuvre the controls around to make it a better layout on the child forms, however, certain controls appear to be "locked", indicated by a small lock symbol when the control is selected:
I am not sure what is causing this, as it only appears (in this case) to be happening to the labels, but not the text boxes. This is preventing me from editing any of the controls properties, (all of the properties window options have been disabled) meaning that I cannot change their locations. However this is not the case for the text boxes, or the groupboxes they came in.
How can I change this so that I can move them around?
Turns out that this is caused by the modifiers being set to "Private". Setting them to "Public" allows you to move them around on the child form freely.
I am new to Windows Forms. I have a menu in a form. When a user selects a menu option I want to display some elements like a grid, treeview or a grouped UI elements.
What is the UI design pattern for displaying the view for the selected option? Load a user control dynamically in a pane? Show a form and hide a previous form? I am not using tab control. Content is displayed in a pane in the form. It's not a separate window.
I have searched high and low for sample applications and I couldn't find any which has a menu. Any ideas?
Constructing your form as needed in designer and then hiding and showing sounds like a reasonable approach.
I definitely would avoid dynamic content loading. In WinForms you are most likely relying on events to handle UI interaction. If loading/unloading controls dynamically you would have to take care of hooking/unhooking event handlers. It's easy to keep track of that when you have 3 controls each with single event. But if you have more controls and each controls has to take care of many events the loading/unloading and hooking/unhooking events is going to be error prone. Also unhooked event handlers will result in memory leaks. Other problem is that your complex controls will have many properties. All of them will have to be set up in code. You will end up with dozens of lines listing controls' properties and assigning values to them.
Hiding/showing doesn't expose you to these issues. You design your layout once in the designer. So your main code is not clattered with pure UI construction. Also, you do not create a new instance of a control when you show it so you can subscribe event handlers to events at design time and you do not have to worry about unhooking the handlers when hiding. You create one instance of a control and rely on this instance throughout application lifetime.
I'm working on a C# application's UI that has the following structure:
Main Form (MDI Parent)
Tree View
Multiple MDI Childdren, each containing:
Custom User Control
I'd like to separate the form's canvas space allocated for the Tree View from that where the MDI Children are allowed to move in. To that extent, I tried a SplitContainer and setting the MDI Child's TopLevel field to 'false', but, besides the fact that newly created MDI Children were created behind the old ones, I also had issues with them not being cleared properly from the screen and other weird issues.
As I don't have lots of experience with UIs in C#, is the path I am taking correct? Would it be easier to change the above structure so that it doesn't use MDI anymore, or is there a simpler way of dividing the canvas between the tree view and the MDIs, other than the SplitContainer?
Cheers,
Alex
UPDATE: Actually, the solution seems to work quite nicely, thanks! I'll probably be able to stop the widgets from moving in the wrong place by placing a simple check.
Besides that, is there any way in which I could make the TreeView resizable without involving a SplitContainer (because of the reasons mentioned in the post)?
Add a Panel to your Main Form and Dock it to the Left. Now add your TreeView to the Panel. Resize the Panel as necessary. Now your MdiChildren will take up the empty space to the right of the Panel...
*You can actually simply Dock the TreeView itself to the Left side of the Form, but the Panel approach would allow you to place other controls in that left side area as well. Just depends on your UI layout.
I am trying to change the color of static controls that are child of a tab control. Now the thing is that, when I try to change it using WM_CTLCOLORSTATIC, it does not work.
When I define the main window as static's parent, it works fine. But how can I change the color while they are child of tab?
As David Heffernan says, when Visual Styles (themes) are enabled, the tab control has a fancy gradient-filled background. Since this only works when the child controls of the tab page have the same background, controls parented by tab controls actually have their backgrounds drawn by the parent.
Yep, it does not work with Themes. How do I make it work?
You don't, that's the whole point of Visual Styles. If you want this kind of fine-grained control over appearance, you should disable visual styles for your particular controls.
You can use the SetWindowTheme function to do this. Pass a handle to your control window as the first parameter and an empty string for the last two parameters:
SetWindowTheme(hwndCtrl, L" ", L" ");
Of course, you'll have to include uxtheme.h in order to call this function, and link to uxtheme.lib.
If you want your application to continue working on versions of Windows prior to XP (when the theming APIs were introduced), then you'll need to either use delay-loading or LoadLibrary and GetProcAddress to call the function dynamically.
You could also try calling the EnableThemeDialogTexture function and specifying the ETDT_DISABLE flag to disable the background texturing applied to tab dialogs.
Child controls send WM_CTLCOLORSTATIC to their parent. If you want the tab control to be parent of the static control, you need to subclass the tab control and handle WM_CTLCOLORSTATIC in there