Subclassing DevEx.TextEdit


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I played around with my code a little more. I could not get the properties to behave in the constructor. The BusinessObject is always null at that point. So, I tweaked things and found a better method to perform the rituals. Here is the refined code:





using System;

using System.Data;

using System.Drawing;

using System.Windows.Forms;



namespace Aspire.SubclassedControls.DevEx

{

public partial class TextEdit : MicroFour.StrataFrame.UI.Windows.Forms.DevEx.TextEdit

{

public TextEdit()

{

InitializeComponent();

}



private void TextEdit_BindingContextChanged(object sender, EventArgs e)

{

if ((BusinessObject != null) && (BindingField != String.Empty))

{

Properties.AppearanceDisabled.BackColor = Color.FromName("Info");

Properties.AppearanceDisabled.ForeColor = Color.FromName("InfoText");

Properties.AppearanceReadOnly.BackColor = Color.FromName("Info");

Properties.AppearanceReadOnly.ForeColor = Color.FromName("InfoText");

if (((MicroFour.StrataFrame.Business.BusinessLayer)BusinessObject).FieldDbTypes[BindingField] == DbType.AnsiString)

Properties.MaxLength = ((MicroFour.StrataFrame.Business.BusinessLayer)BusinessObject).FieldLengths[BindingField];

}

}

}

}





It is just a tad cleaner and places the changes at a point where it is better handled...someday my code may be changing the binding (doubt it, but one never knows). Doing it this way I won't have to think about the sub-classed TextEdit control.
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
...the DevX control is messing with stuff after the control is constructed...




Yup...I think it has to do with the support for application themes.
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I just made a minor change to the class...the properties for the back and fore colors were not showing up in the designer, so I did replaced the TextEdit_Layout method with this:



protected override void OnLayout(LayoutEventArgs levent)

{

base.OnLayout(levent);

if ((BusinessObject != null) && (BindingField != String.Empty))

{

Properties.AppearanceDisabled.BackColor = Color.FromName("Info");

Properties.AppearanceDisabled.ForeColor = Color.FromName("InfoText");

Properties.AppearanceReadOnly.BackColor = Color.FromName("Info");

Properties.AppearanceReadOnly.ForeColor = Color.FromName("InfoText");

}

}




That works nicely.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Yeah, I'd call the base class constructor in most cases.



BTW, this does work when I try it with a SF textbox (I set backcolor, Text and IgnoreManageReadonlyState). There was some issues with some properties not immediately showing up, but they were there. Now, where this could get exiting is if the DevX control is messing with stuff after the control is constructed, which it sounds like it is, hence the need to figure out where you can finally manipulate properties without DevX stomping on those changes.



Anyway, it sounds like in this case, you have to use the layout event. Ermm
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I use trial and error a lot--and the KISS method. I did try placing the property settings in the constructor, but it did not work. Of course, I may have been doing something wrong. It does work in the layout method (a method called during the GUI rendering phase). I get a little pragmatic when it comes to some of this stuff. I kind of wonder what shadowing or interfacing or even overriding would do that my approach does not do. I am open to the possibilities.



Here is the entire class that includes the code posted earlier:



using System;

using System.Data;

using System.Drawing;

using System.Windows.Forms;



namespace Aspire.SubclassedControls.DevEx

{

public partial class TextEdit : MicroFour.StrataFrame.UI.Windows.Forms.DevEx.TextEdit

{

public TextEdit()

{

InitializeComponent();

}



private void TextEdit_Layout(object sender, LayoutEventArgs e)

{

if ((BusinessObject != null) && (BindingField!=String.Empty))

{

Properties.AppearanceDisabled.BackColor = Color.FromName("Info");

Properties.AppearanceDisabled.ForeColor = Color.FromName("InfoText");

Properties.AppearanceReadOnly.BackColor = Color.FromName("Info");

Properties.AppearanceReadOnly.ForeColor = Color.FromName("InfoText");

}

}



private void TextEdit_Enter(object sender, EventArgs e)

{

if (((MicroFour.StrataFrame.Business.BusinessLayer)BusinessObject).FieldDbTypes[BindingField] == DbType.String)

{

Properties.MaxLength = ((MicroFour.StrataFrame.Business.BusinessLayer)BusinessObject).FieldLengths[BindingField];

}

}

}

}


Charles R Hankey
Charles R Hankey
StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)
Group: Forum Members
Posts: 524, Visits: 30K
If you do that in a subclass New() do you need to call the baseclass constructor first ?

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I'm not entirely following this thread (I haven't chewed on the code much) and I don't use DevX controls, but a couple of thoughts.



First if all you want to do is set some defaults, I believe I'd just try setting them in the constructor of the sub classed control. This might not work, but I think it will. If it didn't I'd likely try overriding the create control method. Any properties you set on designer would then override them.



Second, if that didn't work or wasn't what you wanted, then I'd use shadowing to replace certain properties with my own. This can get tricky when dealing with inheritance and interfaces, but is definitely doable.



Here's some sample code for the first method (just typed in):



Public Class dxTxtC

Inherits MicroFour.StrataFrame.UI.Windows.Forms.DevEx.TextEdit



  Public Sub New()

    '-- Set any defaults

    Me.BackColor = Color.Black

    Me.Mask = "9999.99"

  End Sub



End Class




That should be the entire class! Of course I might be missing what the issue is or some other issue your having but this sort of thing is pretty easy.
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Yup...it's in there...



public partial class TextEdit : MicroFour.StrataFrame.UI.Windows.Forms.DevEx.TextEdit



Enjoy!
Charles R Hankey
Charles R Hankey
StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Thanks, Bill.



I'll need to chew this over. I'm assuming this is code inside the inherited class, so I'll approach it that way and see what happens.



Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Hi Charles,



I've extended a TextEdit control. I did not like the gray coloring for disabled and readonly controls (difficult to read). Also, I wanted the control to reflect any binding length limits. So here is what I did:



private void TextEdit_Layout(object sender, LayoutEventArgs e)

{

if ((BusinessObject != null) && (BindingField!=String.Empty))

{

Properties.AppearanceDisabled.BackColor = Color.FromName("Info");

Properties.AppearanceDisabled.ForeColor = Color.FromName("InfoText");

Properties.AppearanceReadOnly.BackColor = Color.FromName("Info");

Properties.AppearanceReadOnly.ForeColor = Color.FromName("InfoText");

}

}



private void TextEdit_Enter(object sender, EventArgs e)

{

if (((MicroFour.StrataFrame.Business.BusinessLayer)BusinessObject).FieldDbTypes[BindingField] == DbType.String)

{

Properties.MaxLength = ((MicroFour.StrataFrame.Business.BusinessLayer)BusinessObject).FieldLengths[BindingField];

}

}




I am pretty sure that I started with an empty component. I have seen that fProperties issue. It's been a while since I designed this control, so I do not remember what I did to work around it.



Have a great day!

Bill

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search