﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Inserting Code ina subclassed control</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Sun, 13 Sep 2026 17:06:13 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Inserting Code ina subclassed control</title><link>http://forum.strataframe.net/FindPost25184.aspx</link><description>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:</description><pubDate>Thu, 12 Nov 2009 08:47:37 GMT</pubDate><dc:creator>Dustin Taylor</dc:creator></item><item><title>Inserting Code ina subclassed control</title><link>http://forum.strataframe.net/FindPost25158.aspx</link><description>I have setup a&amp;nbsp; 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.&lt;/P&gt;&lt;P&gt;On the DateBox, I&amp;nbsp;want to set the default local to British (or whatever does a DD/MM/YYYY rather than MM/DD/YYYY)&lt;/P&gt;&lt;P&gt;On a textBox, I want to set a BackGround Colour when the control gets&amp;nbsp;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. &lt;/P&gt;&lt;P&gt;(I am of the impression that there is now 'Visual' way to change a property in .net but maybe someone could confirm this)&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&lt;P&gt;public class DateBox : MicroFour.StrataFrame.UI.Windows.Forms.DateBox&lt;BR&gt;{//&amp;nbsp; Code here to change&amp;nbsp; Date format to british }&lt;/P&gt;&lt;P&gt;&lt;BR&gt;public class Textbox : MicroFour.StrataFrame.UI.Windows.Forms.Textbox&lt;BR&gt;{// VFP equivalent --&amp;gt; when enabled this.BackGroundColour = Rgb(255,0,0)}&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;</description><pubDate>Thu, 12 Nov 2009 08:47:37 GMT</pubDate><dc:creator>Ger Cannoll</dc:creator></item><item><title>RE: Inserting Code ina subclassed control</title><link>http://forum.strataframe.net/FindPost25183.aspx</link><description>For the DateBox, you don't have to inherit anything, we already have a static method that will handle the date format for you :). &lt;P&gt;[codesnippet]MicroFour.StrataFrame.UI.Windows.Forms.&lt;FONT color=#2b91af&gt;&lt;FONT color=#2b91af&gt;DateBox&lt;/FONT&gt;&lt;/FONT&gt;.DateFormatOverride = MicroFour.StrataFrame.UI.Windows.Forms.&lt;FONT color=#2b91af&gt;&lt;FONT color=#2b91af&gt;DateFormats&lt;/FONT&gt;&lt;/FONT&gt;.MonthDayYear;[/codesnippet]&lt;/P&gt;&lt;P&gt;Put that in your Program.cs and it will affect the DateFormat of any StrataFrame DateBox that does not have the property explictely set.&lt;/P&gt;&lt;P&gt;For the TextBox, you'll want to inherit our textbox in your own, and override the OnEnter and OnLeave methods:&lt;/P&gt;&lt;P&gt;[codesnippet]&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt; System;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=3&gt;&lt;FONT color=#000000 size=2&gt; System.Collections.Generic;&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;using&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt; System.Text;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;namespace&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt; WindowsApplication1&lt;BR&gt;&lt;/FONT&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;class&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;&lt;FONT color=#2b91af&gt;MyTextBox&lt;/FONT&gt;&lt;/FONT&gt; : MicroFour.StrataFrame.UI.Windows.Forms.&lt;FONT color=#2b91af&gt;&lt;FONT color=#2b91af&gt;Textbox&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;{&lt;BR&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;override&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;void&lt;/FONT&gt;&lt;/FONT&gt; OnEnter( &lt;FONT color=#2b91af&gt;&lt;FONT color=#2b91af&gt;EventArgs&lt;/FONT&gt;&lt;/FONT&gt; e )&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;&lt;/FONT&gt;.BackColor = System.Drawing.&lt;FONT color=#2b91af&gt;&lt;FONT color=#2b91af&gt;Color&lt;/FONT&gt;&lt;/FONT&gt;.Gray;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;base&lt;/FONT&gt;&lt;/FONT&gt;.OnEnter( e );&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;protected&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;override&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;void&lt;/FONT&gt;&lt;/FONT&gt; OnLeave( &lt;FONT color=#2b91af&gt;&lt;FONT color=#2b91af&gt;EventArgs&lt;/FONT&gt;&lt;/FONT&gt; e )&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;&lt;/FONT&gt;.BackColor = System.Drawing.&lt;FONT color=#2b91af&gt;&lt;FONT color=#2b91af&gt;Color&lt;/FONT&gt;&lt;/FONT&gt;.White;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; base&lt;/FONT&gt;&lt;/FONT&gt;.OnLeave( e );&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}[/codesnippet]&lt;/P&gt;&lt;P&gt;Then if you use your own overriden control rather than our standard one, it will&amp;nbsp;reflect your added functionality.</description><pubDate>Thu, 12 Nov 2009 08:45:55 GMT</pubDate><dc:creator>Dustin Taylor</dc:creator></item><item><title>RE: Inserting Code ina subclassed control</title><link>http://forum.strataframe.net/FindPost25167.aspx</link><description>[quote]Is there a VFP equivalent to RGB()[/quote]&lt;br&gt;
&lt;br&gt;
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:&lt;br&gt;
&lt;br&gt;
[codesnippet]//-- This will be red and will assume full opacity&lt;br&gt;
Color myColor = Color.FromArgb(255,0,0);&lt;br&gt;
&lt;br&gt;
//-- This will be red and will set the opacity to roughly half&lt;br&gt;
Color myColor = Color.FromArgb(128, 255,0,0);[/codesnippet]</description><pubDate>Tue, 10 Nov 2009 17:27:28 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Inserting Code ina subclassed control</title><link>http://forum.strataframe.net/FindPost25166.aspx</link><description>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&lt;P&gt;There is one thing I could not do. Is there a VFP equivalent to RGB(). I have used the Color.AColour in this instance&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;[codesnippet]public class Textbox : MicroFour.StrataFrame.UI.Windows.Forms.Textbox&lt;BR&gt;{&lt;BR&gt;private System.Drawing.Color originalBackgroudColour;&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;protected override void OnEnter(EventArgs e)&lt;BR&gt;{&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;//-- Run Base Class Code&lt;BR&gt;base.OnEnter(e);&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;//-- Save away original background color&lt;BR&gt;this.originalBackgroudColour = this.BackColor;&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;//-- Define the background color for the control.. maybe extend this to use a property later&lt;BR&gt;this.BackColor = Color.Aqua;&lt;BR&gt;}&lt;BR&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;protected override void OnLeave(EventArgs e)&lt;BR&gt;{&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;//-- Run the Base Code for the textbox&lt;BR&gt;base.OnLeave(e);&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;//-- Reset back color to the default&lt;BR&gt;this.BackColor = this.originalBackgroudColour;&lt;BR&gt;}&lt;BR&gt;} // End textBox[/codesnippet]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;</description><pubDate>Tue, 10 Nov 2009 15:07:00 GMT</pubDate><dc:creator>Ger Cannoll</dc:creator></item><item><title>RE: Inserting Code ina subclassed control</title><link>http://forum.strataframe.net/FindPost25165.aspx</link><description>Give this a try:&lt;br&gt;
&lt;br&gt;
[codesnippet]public class DateBox : MicroFour.StrataFrame.UI.Windows.Forms.DateBox&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;public DateBox : base()&lt;br&gt;
&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//-- Set local...no idea how to do this, but I'd do here in constructor  :-(&lt;br&gt;
&amp;nbsp;&amp;nbsp;}&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
public class Textbox : MicroFour.StrataFrame.UI.Windows.Forms.Textbox&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;public Textbox : base()&lt;br&gt;
&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//-- Save away background color&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.DefaultBackgroundColor = this.BackColor;&lt;br&gt;
&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;//-- Define the background color when the control&lt;br&gt;
&amp;nbsp;&amp;nbsp;//&amp;nbsp;&amp;nbsp;&amp;nbsp;has focus. Static so you can set it for all textboxes in one go.&lt;br&gt;
&amp;nbsp;&amp;nbsp;//&amp;nbsp;&amp;nbsp;&amp;nbsp;I'd use a property in real life...&lt;br&gt;
&amp;nbsp;&amp;nbsp;public static Color FocusColor = Rgb(255,0,0);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;//-- Cache default background color. Use property in real life.&lt;br&gt;
&amp;nbsp;&amp;nbsp;public Color DefaultBackgroundColor;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;protected override void OnEnter(EventArgs e)&lt;br&gt;
&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//-- Set Back color to indicate the control has focus&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.BackColor = Textbox.FocusColor &lt;br&gt;
&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;protected override void OnLeave(EventArgs e)&lt;br&gt;
&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//-- Reset back color to the default&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.BackColor = this.DefaultBackgroundColor;&lt;br&gt;
}[/codesnippet]</description><pubDate>Tue, 10 Nov 2009 11:34:13 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item></channel></rss>