Subclassing DevEx.TextEdit


Author
Message
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
I would like to subclass the Microfour.Strataframe.UI.Windows.Forms.DevEx.TextEdit so I don't have to set all the properties each time to get currency box behavior when I drop one on a form (this form will have > 30 ) I will be using this to bind to character fields as well.



I am still a little uncertain as to how masking works in .NET.



I am trying to add a new component, and set the inherits, then set the properties I want in the properties sheet. I get a warning that fProperties has a the exact property in the base class and should be marked Shadows but I'm out of my depth on exactly how to set this up.



I'd be open to any alternative suggestions as to how to create the textbox that will behave right to left, 2 decimals, show with normal backcolor when disabled or readonly etc. The DevEx.TextEdit ( part of the DevExpress freebie in the XtraEditors ) might be the easiest to adapt for my purposes but if anyone has built something else they'd like to share I'd certainly like to see it.



Assume others have been down this path before so I'll look forward to suggestions.



TIA
Trent Taylor
Trent Taylor
StrataFrame Developer (9.8K reputation)StrataFrame Developer (9.8K reputation)StrataFrame Developer (9.8K reputation)StrataFrame Developer (9.8K reputation)StrataFrame Developer (9.8K reputation)StrataFrame Developer (9.8K reputation)StrataFrame Developer (9.8K reputation)StrataFrame Developer (9.8K reputation)StrataFrame Developer (9.8K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
You have two options.  Implement the Shadows property and create your own internal privates to set the values on the parent class or create totally new properties that you set and in turn sets the parents base properties.

Private _MyText As String = String.Empty
Public Shadows Property Text As String
    Get
         '-- Make sure that the base property is set when being evaluated
         If Not MyBase.Text.Equals(_MyText) Then MyBase.Text = _MyText
       
         Return _MyText
    End get
    Set(Byval value As String)
          _MyText = value
          MyBase.Text = _MyText
    End Set
End Property

The second option is basically the same, but is slightly harder to implement dynamically as the base class will not automatically evaluate the property, thus requiring you to set each property regardless of the serialized state.

Hope this helps Smile  Also, the above code was quick and dirty and not tested, but it will be close. Wink

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
First, in case I didn't say so before, I created this by using a component class.



I think I get what you're saying but the fProperties seems to encompass all the dx specific properties of TextEdit, storing them in the repository.



The component library builds, but when I drop the component on a form all the props I set in the subclassed component are ignored, then there is a problem reopening the component in the designer.



The warning I get is this :



WithEvents variable 'fProperties' implicitly defines '_fProperties', which conflicts with a member of the same name in class 'dxTxtC'.






I tried this ( both the commented and uncommented version ) with exactly the same result



Public Class dxTxtC

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



'Private _myfProperties As DevExpress.XtraEditors.Repository.RepositoryItemTextEdit



'Public Shadows Property myfProperties() As DevExpress.XtraEditors.Repository.RepositoryItemTextEdit



' Get

' '-- Make sure that the base property is set when being evaluated

' If Not MyBase.fProperties.Equals(_myfProperties) Then MyBase.fProperties = _myfProperties

' Return _myfProperties

' End Get

' Set(ByVal value As DevExpress.XtraEditors.Repository.RepositoryItemTextEdit)

' _myfProperties = value

' MyBase.fProperties = Me._myfProperties

' End Set

'End Property



End Class





Also tried this naming the props _fProperties and fProperties()



In all cases the designer part of the control looks like this :



_

Private Sub InitializeComponent()

Me.fProperties = New DevExpress.XtraEditors.Repository.RepositoryItemTextEdit

CType(Me.fProperties, System.ComponentModel.ISupportInitialize).BeginInit()

Me.SuspendLayout()

'

'fProperties

'

Me.fProperties.Appearance.Options.UseTextOptions = True

Me.fProperties.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far

Me.fProperties.AppearanceDisabled.BackColor = System.Drawing.Color.White

Me.fProperties.AppearanceDisabled.ForeColor = System.Drawing.Color.Black

Me.fProperties.AppearanceDisabled.Options.UseBackColor = True

Me.fProperties.AppearanceDisabled.Options.UseForeColor = True

Me.fProperties.AppearanceDisabled.Options.UseTextOptions = True

Me.fProperties.AppearanceDisabled.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far

Me.fProperties.AppearanceFocused.Options.UseTextOptions = True

Me.fProperties.AppearanceFocused.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far

Me.fProperties.AppearanceReadOnly.BackColor = System.Drawing.Color.FromArgb(CType(CType(224, Byte), Integer), CType(CType(224, Byte), Integer), CType(CType(224, Byte), Integer))

Me.fProperties.AppearanceReadOnly.ForeColor = System.Drawing.Color.Black

Me.fProperties.AppearanceReadOnly.Options.UseBackColor = True

Me.fProperties.AppearanceReadOnly.Options.UseForeColor = True

Me.fProperties.AppearanceReadOnly.Options.UseTextOptions = True

Me.fProperties.AppearanceReadOnly.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far

Me.fProperties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric

Me.fProperties.EditFormat.FormatType = DevExpress.Utils.FormatType.Numeric

Me.fProperties.Name = "fProperties"

'

'dxTextEdit

'

Me.BusinessObjectEvaluated = True

CType(Me.fProperties, System.ComponentModel.ISupportInitialize).EndInit()

Me.ResumeLayout(False)




I'm obviously missing a basic concept here. Should I be just using a the SF wrapper as a model and creating my own wrapper to remove one layer of abstraction?



Since this involves the SF wrapper for the DevEx control, I'd really appreciate it if you could just tell me specifically, for subclassing this particular SF control, what the best approach to take is.



Since DevEx just released all these controls for free, this might be really useful for a lot of us who haven't been using the DevEx stuff up til now.



TIA











Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Okay, I tried stealing the code from the SF source code for the TextEdit wrapper, discovering it is just a class, not a component, so it may well be that my fProperties problem was mostly because I was using a component so there was a design file.



But now there is the question of how to change defaults for properties in my subclass (the whole purpose of doing the subclass to start with )



While my rip-off of the SF wrapper fine - subclassing directly from the DevEx control just as the framework does - builds fine and works as part of my own UI dll , I have discovered that the property sheet allows you to set properties but they do not persist into the built class. Same with subclassing the MaskedTextbox.



Looks like the properties must be over ridden ( shadowed ? ) in the code itself to get new defaults.



Interesting.



Also guessing I'm going to find the DevEx control is going to work differently from the SF MaskedTextbox, since the devEx control uses a repository which seems to be basically a data dictionary approach.



Surely a whole lot of other folks have already dealt with this??? Suggestions ?





Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K 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

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 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.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K 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!
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K 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.
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 reputation)Advanced StrataFrame User (892 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 ?

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K 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];

}

}

}

}


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