Hi,
I have a problem with hidden fields. Is there a possibility to hide fields from the Designer, which have the Property visible=false
I have dialogs, which have a lot of hidden fields, so that the designing of these dialogsis very difficult.
Thanks for your help
Thorsten |
| Thorsten H Wednesday, February 08, 2006 12:37 PM |
hmmm. . .
do you ever show these hidden controls? or are they just holders for data???
if you answer no to the former and yes to the latter, I suggest you are probably looking at things completely backwards. You shouldn't be using controls as a data structure to hold your data. The controls are the presentation layer - they present data in an underlying Data Structure- usually via data binding.
Create classes/structures for your data. In your form declare and intialize data structures for your data that you want the form to interface. Place controls on your form for only the data you do want to see. Bind the controls to the fields of your datastructures to display the data. If you dont want to see a piece of data, dont place a control on the form.
If you do things this way, the amount of code you have to write will decrease by 75%. You don't have to alot of data validation ( a text box bound to an integer will only accept an integer) or data loading/unloading (controls bound to a field automatically load the data into themselves and push the data out onfocus change)
In the rare case that you want a control to be hidden (in .Net 1.1 this was sometimes necessary in order totrigger some data modificationevents), make your form a little larger than desired, place the control in the extra margin, and then resize the form to hide the control. But, this is rarely necessary.
Again, controls are the presentation layer, not the data/business object layer. If they aren'tpresenting data, what purpose are they serving? |
| Blair Allen Stark Wednesday, February 08, 2006 2:32 PM |
thx, but thats clear. The application is a result of Porting Tool. There are many fields for holding data temporarly and some fields, which are shown in some cases. The Problem is, that the apllication works fine, but the layout of the dialogs was destroyed by the Porting Tool. So I have to redesign the dialogs and want to hide all hidden Fields from the VS-Designer. Is this possible?
Thorsten
|
| Thorsten H Wednesday, February 08, 2006 2:40 PM |
I am not exactly sure what you are doing but I will take aassume that you have temporary copies of initial data with a need to compare over time to the changes that are made.
the controls shouldnt hold data, even temporarily. hold the data in temporary objects.
bind your presentation to theinital data objects (implement IClonable on the objects)
clone the bound objects to temporary copy objects - to reset, clone back out of the temp copies objects to the bound objects.
|
| Blair Allen Stark Wednesday, February 08, 2006 4:15 PM |
oh I understand!!!
give me a moment |
| Blair Allen Stark Wednesday, February 08, 2006 4:26 PM |
I think the best thing would be to make the form larger. . . select all the controls, move them to the right/down. resize to hide the controls.
redesign the form properly, then delete the controls.
sorry about the misunderstanding |
| Blair Allen Stark Wednesday, February 08, 2006 4:28 PM |
thx, but there is problem. I need all fields, I only want to hide the fields in the Designer, which have the Property visible = false. Is this possible. Exist a feature in Visual Studio to hide "hidden" fields from the Designer?
Thorsten
|
| Thorsten H Wednesday, February 08, 2006 5:15 PM |
design time visibility is a function of the internals of the control.
I am wondering if you can inherit from the controls in question and override OnPaint for the affected controls in your own library to draw a rectangle of its parent's color over the control if designmode is true and visible is false.
generate your code and grep the code to change to your custom control library before opening the code in vs. |
| Blair Allen Stark Wednesday, February 08, 2006 7:15 PM |
This would be a nice feature for the VS designer, but unfortunately it does not exist. I dont think you are going to find a way around this, and if you do, it will be hack that requires significantly more work than you want to put in for your scenario. |
| CommonGenius.com Wednesday, February 08, 2006 9:04 PM |
I was on the right track. . . you will need to apply my approach of inheriting from each control that you want to be designtime invisible.
define a ControlDesigner implementationto paint the rectangle, imlpement OnPaintAdornment to paint the rectangle and apply this designerto a redefined Visible property for each of your overridden controls.
it shouldn'tthat hard to do once you understand the concept. shout at me this weekend if you get stuck. |
| Blair Allen Stark Thursday, February 09, 2006 12:47 AM |
Thank you, I have to find a way to solve the problem.
Thorsten
|
| Thorsten H Thursday, February 09, 2006 7:39 AM |
what framework version 1.1 ? 2.0? |
| Blair Allen Stark Friday, February 10, 2006 4:03 AM |
ok. . . are you ready? I couldn't get it to do exactly what you want, but I think it will work.
It always draws the control in the background of its parent independent of its visible property. to get it completely invisible - set its border to [none]
create a class library project, call it "HiddenControls", delete the default class that is added.
Add references to System.Design and System.Drawing.
Add a new class, call it HiddenControlDesigner.
put this code in it
using System; using System.Collections.Generic; using System.Text;
using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.Design;
namespace HiddenControls { class HiddenControlDesigner : System.Windows.Forms.Design.ControlDesigner { protected override void OnPaintAdornments(PaintEventArgs pe) { Brush brush = new SolidBrush(this.Control.Parent.BackColor); pe.Graphics.FillRectangle(brush, pe.ClipRectangle); } } }
|
|
add a new class module, put this code in it
using System; using System.ComponentModel; using System.Windows.Forms;
namespace HiddenControls { [Designer(typeof(HiddenControlDesigner))] public class TextBox : System.Windows.Forms.TextBox { } } |
|
build the project.
open the ported project in question, add a reference to HiddenControls.dll.
do a replace on desired instances of System.Windows.Forms.TextBox with HiddenControls.TextBox.
is that good enough?
if so, add additional control overrides to HiddenControls and replace those in the ported project.
Let me know how it works. |
| Blair Allen Stark Friday, February 10, 2006 6:34 AM |
just wondering how this worked for you. . . |
| Blair Allen Stark Tuesday, February 14, 2006 6:26 PM |