I have FormBase and MainForm : FormBase.
FormBase Contains a DataGridView dgv. in designer view of FormBase dgv font sizes are fine but in designer view and runtime in MainForm they are default values. why and what should I do??!
The designer for DVG doesn't support designing the control in an inherited form, a limitation of many designers of controls that were added in .NET 2.0. The Font property is an 'ambient' property, it gets the same value as the parent unless you've explicitly selected one (shown in bold in the Properties window). So either set the form's Font property to also change the DGV font or change the Font property of the DGV in the base form.
To clarify my comment: putting UI (together with DataGridView) from BaseForm in custom user control and using it separately on previously inheriting forms will surely fix the font problem.
If your base form is only "container" for commonly used controls (so you don't have to put 3 buttons, datagrid and label on every window) or defines some basic layout - go with custom user control.
Here's decent starting point if you want to explore this topic - Custom User Controls.
Have you tried this approach: http://dotnetengineer.wordpress.com/2008/06/27/visual-inheritance-using-datagridview/
Related
I have a base windows form containing a DataGridView. The DataGridView has the modifier set to Protected.
When creating a descendant form the DataGridView properties cannot be changed. They are greyed out. The events are also not editable through the Properties panel. This would all be in the Designview.
You can however add an event handler to, for example, DoubleClick from inseide the code editor.
Why can this not be done from inside the designer?
I have other controls on the base form also set to Protected which can be altered from Design view in the child form.
To modify a control from baseform in inherited forms or usercontrols we should change controls acces modifier property to 'Protected' or 'Public'.
MSDN - https://social.msdn.microsoft.com/Forums/vstudio/en-US/3246a701-cc50-4109-b981-3eea04dacdeb/question-inherited-form-with-control?forum=csharpgeneral
DevExpress - https://www.devexpress.com/Support/Center/Question/Details/A679
I want a Form to be resized proportionaly to it's content, so I have set AutoSize property to true in GrowAndShrink mode.
I have a base Form that contains a panel in which there is two bttons:
And another Form that inherits from it:
The problem is that panel containing the two buttons in BaseServiceWindow seems not to be taken in account when using the Autosize property. The result is as you can see: I cannot use the buttons from BaseServiceWindow. Any advice would be appreciated.
In your BaseServiceWindow form, create a second panel that fills the area above the panel with the two buttons. You will use this new panel to contain a UserControl.
Then, instead of creating forms that inherit from BaseServiceWindow, make them UserControls instead. Create an base UserControl class for your UserControls to inherit from and include virtual methods for the common behavior.
Finally, inject the UserControl into BaseServiceWindow. You could have the BaseServiceWindow constructor accept the BaseUserControl type each of your UserControls inherits.
I have a custom control, MyControl, that inherits from UserControl.
If i change MyControl graphic proprerties(like ForeColor, backgroundImage, etc) i aspect this will be applied to all my instances of MyControl, but is not.
Why?
EDIT
I think the problem is that image are stored inside resx file of Control that contains MyControl (example a Form).
When this line is called, the old image is applied.
resources.ApplyResources(this.myControl1, "myControl1");
So when i make changes in MyControl designer class, this are not applied to myControl1 instance.
Unfortunately this line was autogenerated in designer of Form.
Thanks
You should make your settings (eg. change background image and stuff) in a constructor of MyControl or in the designer of the control, not Form.
Well of course it doesn't.
When you add the control to a form, it grabs the properties and adds code in form.designer.cs, setting them. Change them in the form designer, those chamges get persisted in .designer.cs
If you then change the control itself, to pick up those changes you'd have to remove and add it again.
The only way round that is for the properties not to be configurable in the designer.
I have a WinForms user control Host with a custom UI Editor.
Through that editor, a child control (Child) can be added to Host.
(The UI Editor creates Child and sets Child.Parent = Host)
Child is handled through a Holder<Child> helper class, which is set as Tag property of e.g. a ListViewItem.
The respective code - some of it, at least - gets added to the form: Holder is created, and set as Tag, which is enough to be created at runtime, too.
However, Child is not visible to the designer - it is displayed, but it can't be selected, nor does it occur in the drop down list with controls for the parent form.
I would like to:
see the Child control in the designer, so that I can modify properties
get notified if the control is removed
Is this possible?
[edit] Thanks all for your input. I've decided to skip the designer - I hoped to throw together something quickly, but apparently it requires more planning than I should allow myself to spend on it right now.
Usethis.Controls.Add(/*Instance of the child*/); on the host class. Then for the notification add event handler for the host's ControlRemoved event (this.ControlRemoved += new ControlEventHandler(Host_ControlRemoved);).
I can't say I fully understand exactly what you are trying to do.
If you are dealing with the problem of how a "child" Control of a UserControl placed on a Form at Design-Time can be made to function as a container onto which you can drag-and-drop other controls from the Toolbox : this CodeProject article by Henry Minute may be helpful : Designing Nested Controls. For example : you have a UserControl with a Panel inside it : an instance of the UserControl is placed on a Form : in the Design-time view of the Form : you want to be able to drag-drop controls onto the Panel in the UserControl and have them become child controls of the Panel : Henry's article will show you how to do that.
This from Microsoft : How to make a UserControl object acts as a control container design-time by using Visual C#
Perhaps might also be useful, although it seems like you already have this step accomplished.
I have a base form with two buttons (e.g. OK and Cancel). I want to use a TableLayoutPanel and have the two buttons in it. Child forms should be able to add more controls to the table as well as modify its layout itself via the designer.
So far I can't get this to work. I have tried the following:
Adding the TableLayoutPanel to the child form. Designer refuses to add the two buttons to the panel.
Adding the TableLayoutPanel in the base form. Can't add controls to the panel from the child form.
In the base form you have to set the property Modifiers = Protected for the TableLayoutPanel and any other control you want to change in the child forms.
The reason why you cant edit your TableLayoutPanel in the derived class is because you are attempting to use a feature of WinForms called 'visual inheritance'. Unfortunately, the TableLayoutPanel does not support visual inheritance:
http://msdn.microsoft.com/en-us/library/ms171689.aspx (read at the bottom of the page)
http://msdn.microsoft.com/en-us/library/1z3efhd2.aspx
This is why it appears blocked in the inherited controls. I am not sure why they do not support this feature, but I have recently come across the same problem and ended up having to solve the problem another way.
Since this hasn't received an answer since almost over a year and WindowsForms is slowly losing against WPF, the answer seems to be "just don't do it".