CodeLeon wrote:
Thank you, but i already did that. What i need to do is get the parent
form of my componenet. Any ideas?
Tom Spink wrote:
>CodeLeon wrote:
I am designing an enhanced GUI suite, and i need to know how to:
* Make a user control a "helper" control, ie, one that sits at the
bottom (like timer or process)
* Make this control modify the behavior of the painted controls
already on the form. (ie, make my control handle the painting of the
controls on the page)
* Make the TextBox contol have it's background painted by me. This
seems to be a hassle.
Any help would be deeply appreciated as at the moment i am coding solo
for an open source program.
Thank You!
Hi CodeLeon,
WRT your first point, you need to create a component, not a user-control,
if you want the type of behaviour you see with Timers and etc.
--
Hope this helps,
Tom Spink
Hi CodeLeon,
I'm afraid it's not that simple. I've taken the liberty of whipping up a
bit of code, that may get you started. It's a component that you add to
your form, and extends your form by adding a property called
HandlePainting. Then, it'll paint all buttons Red and everything else
Green. It doesn't contain any code that will detach the paint event, if
the property was set to false. I also haven't included the
InitializeComponent() method, because you should be able to put the
relevant code into your own component class.
///
[ProvideProperty( "HandlePainting", typeof( Control ) )]
public partial class PaintModifier : Component, IExtenderProvider
{
// A map of our handles.
private Dictionary<Control, bool_handleMap;
public PaintModifier ( )
{
// Initialise the handle map.
_handleMap = new Dictionary<Control, bool>();
InitializeComponent();
}
public PaintModifier ( IContainer container )
{
// Initialise the handle map.
_handleMap = new Dictionary<Control, bool>();
container.Add( this );
InitializeComponent();
}
public bool CanExtend ( object extendee )
{
// Extend only controls.
return extendee is Control;
}
public void SetHandlePainting ( Control c, bool value )
{
if ( !_handleMap.ContainsKey( c ) )
{
_handleMap.Add( c, value );
if ( value )
AttachToControl( c );
}
else
_handleMap[c] = value;
}
public bool GetHandlePainting ( Control c )
{
if ( _handleMap.ContainsKey( c ) )
return _handleMap[c];
else
return false;
}
private void AttachToControl ( Control c )
{
c.Paint += new PaintEventHandler( OnHandlePaintEvent );
}
private void OnHandlePaintEvent ( object sender, PaintEventArgs e )
{
if ( sender is Button )
e.Graphics.Clear( System.Drawing.Color.Red );
else
e.Graphics.Clear( System.Drawing.Color.Green );
}
}
///
Maybe it will be of some use.
--
Hope this helps,
Tom Spink