473,396 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Create a helper control to modify existing forms controls.

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!

Jul 5 '06 #1
4 2480
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
Jul 5 '06 #2
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
Jul 5 '06 #3
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
Jul 5 '06 #4
Thank you for your timely reply, and i will try to incorporate it into
my product. Check out the blog for this suite at cleanux.blogger.com; i
will periodically post screenshots and graphics here.

Thanx!

Tom Spink wrote:
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
Jul 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
6
by: SamIAm | last post by:
Hi am creating a email application that needs to mail out a very large amount of emails. I have created a multithreaded c# application that using message queuing. I have created a threadpool of 5...
2
by: Mevar81 | last post by:
Hi to everybody.I have a problem with the PropertyGrid control.I want to display not all the properties of a generic Control(Button,TextBox,ComboBox,ecc.).In general I don't want to display only...
0
by: Duncan Mole | last post by:
Hi, I have created a control which draws a title bar and provides a drop down menu for a Smart Device Application. It seemed to work fine until I came to add an event handler to act on Paint...
1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
11
by: Özden Irmak | last post by:
Hello, In my VB.Net application I create a new instance of my form like : NewForm = new MyNewForm() But with this line, this new form is automatically shown. I want it to be hidden at the...
3
by: Charles Law | last post by:
Sorry for reposting this question, but I did not get a single answer last time, and I'm sure you guys must have some thoughts on the matter. I have a user control which can be dragged and dropped...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.