Re: Overriding a Control's OnPaint Method

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance





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" <gfemail@xxxxxxxxx> wrote in message
news:iubbs1lcfrpsm6v4jm49ijefqasv11nr14@xxxxxxxxxx
> On Wed, 11 Jan 2006 12:26:53 -0500, "RSH" <way_beyond_oops@xxxxxxxxx>
> 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.
> }
>
> }


.


Quantcast