Phylum Posted May 16, 2005 Posted May 16, 2005 I have created a control designer to restrict the programmer using my control from altering the controls height. Here is the code: internal class FixedHeightControlDesigner : System.Windows.Forms.Design.ControlDesigner { public override SelectionRules SelectionRules { get { return SelectionRules.Moveable | SelectionRules.LeftSizeable | SelectionRules.RightSizeable | SelectionRules.Visible; } } } Then you just declare your control with the Designer attribute, as follows: [Designer(typeof(FixedHeightControlDesigner))] public class ControlClassName : System.Windows.Forms.UserControl The problem I have is my usercontrol is made up of a button and a textbox, and like the windows textbox control I want to make the fixedheight conditional upon wether or not the multiline property is set to TRUE. The Control Designer dosen't contain a reference to the control and therefore can't read the property. Does anybody know how to do this? Quote
AlexCode Posted May 16, 2005 Posted May 16, 2005 This is just me thinking... Why don't you simply handle the resize event and block (or not) the control height change? Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Phylum Posted May 17, 2005 Author Posted May 17, 2005 This is just me thinking... Why don't you simply handle the resize event and block (or not) the control height change? Alex :p It dosen't look as professional. With the way i did it the grab handle son the control are greyed out indicating that you can't resize it vertically. I may have to resort with what you said... :( Quote
AlexCode Posted May 17, 2005 Posted May 17, 2005 The fastest way I can see is to you do declare a static variable, that both control and designer can access, that will hold the selections rules. Set this variable on the set of the Multiline Property, one selection rule for True, another for False. Force the redraw of the control... Tho I didn't tryed this, I believe it should work... Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Leaders snarfblam Posted May 17, 2005 Leaders Posted May 17, 2005 (edited) The fastest way I can see is to you do declare a static variable, that both control and designer can access, that will hold the selections rules. Set this variable on the set of the Multiline Property, one selection rule for True, another for False. This variable would also have to be declared publicly, allowing other programmers to access it and cause potential problems. Also, This might work of you have only a single instance of the control. If you have many, that would have to turn into a static array or collection that would have to be indexable by the reference of the controls. The designer does have a reference to the control it is designing... the ControlDesigner.Control property. internal class FixedHeightControlDesigner : System.Windows.Forms.Design.ControlDesigner { public override SelectionRules SelectionRules { get { MyControl control = (MyControl) this.Control; if (Control.Multiline) return SelectionRules.Moveable | SelectionRules.LeftSizeable | SelectionRules.RightSizeable | SelectionRules.Visible; else return SelectionRules.Moveable | SelectionRules.LeftSizeable | SelectionRules.TopSizeable | SelectionRules.BottomSizeable | SelectionRules.RightSizeable | SelectionRules.Visible; } } } I got this to work fine in VB, but I don't know much C#, so I don't know if the syntax is right. Also, this won't prevent the programmer from changing the control size at run time. You might want to implement some size checking in the resize event. [Edit]Fixed a typo in the code[/Edit] Edited May 17, 2005 by snarfblam Quote [sIGPIC]e[/sIGPIC]
AlexCode Posted May 17, 2005 Posted May 17, 2005 I had the idea that it has a control reference... just didn't had the time to go and make shure... Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.