471,319 Members | 1,625 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Overriding a Control's OnPaint Method

RSH

How do I go about overriding a Control's OnPaint Method?

I would like to prevent a control's color from changing when it is disabled.

I have overridden the Form's OnPaint Method but I need to do it at the
control level.

Thanks,
Ron
Jan 11 '06 #1
4 4498
Hi,

You define a new class that derive from it , ilke

class ButtonEX: Button
{
}

Advise, take a look at a very good article in opennetcf.org about
ownedDrawList a very good example
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"RSH" <wa*************@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...

How do I go about overriding a Control's OnPaint Method?

I would like to prevent a control's color from changing when it is
disabled.

I have overridden the Form's OnPaint Method but I need to do it at the
control level.

Thanks,
Ron

Jan 11 '06 #2
On Wed, 11 Jan 2006 12:26:53 -0500, "RSH" <wa*************@yahoo.com>
wrote:

-->
--> How do I go about overriding a Control's OnPaint Method?
-->
--> I would like to prevent a control's color from changing when it
is disabled.
-->
--> I have overridden the Form's OnPaint Method but I need to do it
at the
--> control level.
-->
--> Thanks,
--> Ron
-->

class MyCustomControl : Control
{

protected override void OnPaint(PaintEventArgs e)
{
// ...
}

protected override void OnPaintBackground(PaintEventArgs e)
{
// .. I suspect you may be more interested in
// .. override its background painting.
}

}
Jan 12 '06 #3
RSH


I tried an implementation of this idea but it never fires. Am I correctly
implementing this? Or are the overrides wrong?

Please help.

Thanks,
Ron



using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Text.RegularExpressions;

using System.Collections;

using System.Drawing.Drawing2D;

namespace GeneralTesting

{

public partial class frmMain : Form

{

MyCustomComboBox TB1 = new MyCustomComboBox();
public frmMain()

{

InitializeComponent();

TB1.FormattingEnabled = true;

TB1.Location = new System.Drawing.Point(13, 214);

TB1.Name = "TB1";

TB1.Size = new System.Drawing.Size(385, 21);

TB1.TabIndex = 1;

TB1.SelectedIndexChanged += new
System.EventHandler(this.TB1_SelectedIndexChanged_ 1);

this.Controls.Add(TB1);

DataClass DC = new

}

private void TB1_SelectedIndexChanged_1(object sender, EventArgs e)

{

richTextBox1.Text += ((Employee)TB1.SelectedItem).ToString() + "\n";

TB1.Items.Remove((Employee)TB1.SelectedItem);

}

private void button1_Click(object sender, EventArgs e)

{

if (TB1.Enabled == true)

{

TB1.Enabled = false;

}

else

{

TB1.Enabled = true;

}

}

class MyCustomComboBox : ComboBox

{

protected override void OnPaint(PaintEventArgs e)

{

// ...

MessageBox.Show("TRIGGERED OnPaint");

}

protected override void OnPaintBackground(PaintEventArgs e)

{

// .. I suspect you may be more interested in

// .. override its background painting.

MessageBox.Show("TRIGGERED OnPaintBackground");

}

}

}

}









"Michael H" <gf*****@gmail.com> wrote in message
news:iu********************************@4ax.com...
On Wed, 11 Jan 2006 12:26:53 -0500, "RSH" <wa*************@yahoo.com>
wrote:

-->
--> How do I go about overriding a Control's OnPaint Method?
-->
--> I would like to prevent a control's color from changing when it
is disabled.
-->
--> I have overridden the Form's OnPaint Method but I need to do it
at the
--> control level.
-->
--> Thanks,
--> Ron
-->

class MyCustomControl : Control
{

protected override void OnPaint(PaintEventArgs e)
{
// ...
}

protected override void OnPaintBackground(PaintEventArgs e)
{
// .. I suspect you may be more interested in
// .. override its background painting.
}

}

Jan 13 '06 #4
Did you ever figure this out?

I was engulfed by obsessive work demands the last two weeks.


Feb 4 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Sagaert Johan | last post: by
4 posts views Thread by RSH | last post: by
reply views Thread by rosydwin | last post: by

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.