Inserting Code ina subclassed control


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
I have setup a  Base Calss library and included a few of the SF controls, got them into a DLL and got them onto the toolbox...so far so good. I now want to put a bit of code into two of them specifically. I realise this is more of a .net thing rather than SF ,but any help would be appreciated. If I can get one or two examples to start me off it would be a great help.

On the DateBox, I want to set the default local to British (or whatever does a DD/MM/YYYY rather than MM/DD/YYYY)

On a textBox, I want to set a BackGround Colour when the control gets focus. This we have on VFP and it is very useful, particulalrly on a form with many controls, to give the user a visual clue as to where they are at.

(I am of the impression that there is now 'Visual' way to change a property in .net but maybe someone could confirm this)

public class DateBox : MicroFour.StrataFrame.UI.Windows.Forms.DateBox
{//  Code here to change  Date format to british }


public class Textbox : MicroFour.StrataFrame.UI.Windows.Forms.Textbox
{// VFP equivalent --> when enabled this.BackGroundColour = Rgb(255,0,0)}


Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Give this a try:



public class DateBox : MicroFour.StrataFrame.UI.Windows.Forms.DateBox

{

  public DateBox : base()

  {

    //-- Set local...no idea how to do this, but I'd do here in constructor :-(

  }

}





public class Textbox : MicroFour.StrataFrame.UI.Windows.Forms.Textbox

{

  public Textbox : base()

  {

    //-- Save away background color

    this.DefaultBackgroundColor = this.BackColor;

  }



  //-- Define the background color when the control

  //   has focus. Static so you can set it for all textboxes in one go.

  //   I'd use a property in real life...

  public static Color FocusColor = Rgb(255,0,0);



  //-- Cache default background color. Use property in real life.

  public Color DefaultBackgroundColor;



  protected override void OnEnter(EventArgs e)

  {

    //-- Set Back color to indicate the control has focus

    this.BackColor = Textbox.FocusColor

  }



  protected override void OnLeave(EventArgs e)

  {

    //-- Reset back color to the default

    this.BackColor = this.DefaultBackgroundColor;

}

Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Greg. Many thanks for your reply which I have found very useful. I have now got Subclass funtionality working which chhnges the Background colour of the text Box in Focus. I include the code below ,and would welcomew any comments on either how this can be improved upon, or in case it will cause any other problems with Windows Text Box or SF Textbox controls

There is one thing I could not do. Is there a VFP equivalent to RGB(). I have used the Color.AColour in this instance

public class Textbox : MicroFour.StrataFrame.UI.Windows.Forms.Textbox
{
private System.Drawing.Color originalBackgroudColour;

protected override void OnEnter(EventArgs e)
{

//-- Run Base Class Code
base.OnEnter(e);

//-- Save away original background color
this.originalBackgroudColour = this.BackColor;

//-- Define the background color for the control.. maybe extend this to use a property later
this.BackColor = Color.Aqua;
}

protected override void OnLeave(EventArgs e)
{

//-- Run the Base Code for the textbox
base.OnLeave(e);

//-- Reset back color to the default
this.BackColor = this.originalBackgroudColour;
}
} // End textBox


Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Is there a VFP equivalent to RGB()




Yes. You will use the Color.FromArgb(A, R, G, B). This allows you to specify an alpha channel as well (opacity). But you can omit it if you need to and just supply the RGB values:



//-- This will be red and will assume full opacity

Color myColor = Color.FromArgb(255,0,0);



//-- This will be red and will set the opacity to roughly half

Color myColor = Color.FromArgb(128, 255,0,0);

Dustin Taylor
Dustin Taylor
StrataFrame Team Member (652 reputation)
Group: StrataFrame Users
Posts: 364, Visits: 771
For the DateBox, you don't have to inherit anything, we already have a static method that will handle the date format for you Smile.

MicroFour.StrataFrame.UI.Windows.Forms.DateBox.DateFormatOverride = MicroFour.StrataFrame.UI.Windows.Forms.DateFormats.MonthDayYear;

Put that in your Program.cs and it will affect the DateFormat of any StrataFrame DateBox that does not have the property explictely set.

For the TextBox, you'll want to inherit our textbox in your own, and override the OnEnter and OnLeave methods:

using System;
using System.Collections.Generic;
using System.Text;

namespace WindowsApplication1
{
    public class MyTextBox : MicroFour.StrataFrame.UI.Windows.Forms.Textbox
   
{
        protected override void OnEnter( EventArgs e )
        {
            this.BackColor = System.Drawing.Color.Gray;

            base.OnEnter( e );
        }

        protected override void OnLeave( EventArgs e )
        {
            this.BackColor = System.Drawing.Color.White;

            base.OnLeave( e );
        }
    }
}

Then if you use your own overriden control rather than our standard one, it will reflect your added functionality.

Dustin Taylor
Dustin Taylor
StrataFrame Team Member (652 reputation)
Group: StrataFrame Users
Posts: 364, Visits: 771
Woah, weird. I must've had this post up from a couple of days ago and not realised it. Sorry for the redundancy, but glad I got the same answer as everyone else though! w00t
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