471,325 Members | 1,203 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Overriding a ComboBox

RSH


I tried an implementation of overriding a ComboBox control. I am simply
trying to avoid it repainting, but I can't seem to get it to work. What am I
doing 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");

}

}

}

}







Jan 13 '06 #1
4 3551
RSH,

If you keep it from repainting, then it will not display properly. Why
do you want to prevent it from repainting?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"RSH" <wa*************@yahoo.com> wrote in message
news:u0**************@TK2MSFTNGP11.phx.gbl...


I tried an implementation of overriding a ComboBox control. I am simply
trying to avoid it repainting, but I can't seem to get it to work. What am
I doing 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");

}

}

}

}







Jan 13 '06 #2
comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
comboBox1.DrawMode = DrawMode.OwnerDrawVariable;

You must handle the Draw Item event.

"RSH" <wa*************@yahoo.com> wrote in message
news:u0**************@TK2MSFTNGP11.phx.gbl...


I tried an implementation of overriding a ComboBox control. I am simply
trying to avoid it repainting, but I can't seem to get it to work. What am
I doing 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");

}

}

}

}







Jan 13 '06 #3
RSH

Well its all part of an elaborate plot...you see if you set the Enabled
property of a combobox to false it automatically sets the background to the
standard Windows color without the possibility of setting it to anything
else. And I have a form that uses a gradient background from deep grey to
light grey and the controls look like crap with their beige color when they
are disabled so I am trying to figure out a way to prevent it from
happening. it was suggested the I override the paint method of the control.

My problem is that nothing is happening. The messageboxes are never being
triggered. If I put a contructor in place with a message box the object is
definitately getting created because the messagebox shows when the
contructor is called...but still either of the paint methods are being
called.

Thanks,
Ron
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uy**************@TK2MSFTNGP14.phx.gbl...
RSH,

If you keep it from repainting, then it will not display properly. Why
do you want to prevent it from repainting?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"RSH" <wa*************@yahoo.com> wrote in message
news:u0**************@TK2MSFTNGP11.phx.gbl...


I tried an implementation of overriding a ComboBox control. I am simply
trying to avoid it repainting, but I can't seem to get it to work. What
am I doing 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");

}

}

}

}








Jan 13 '06 #4
RSH

This only effects the list items that are listed, not the colors when the
control is set to Enabled = False.
"Rocky" <no*****@nowhere.com> wrote in message
news:O7**************@TK2MSFTNGP12.phx.gbl...
comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
comboBox1.DrawMode = DrawMode.OwnerDrawVariable;

You must handle the Draw Item event.

"RSH" <wa*************@yahoo.com> wrote in message
news:u0**************@TK2MSFTNGP11.phx.gbl...


I tried an implementation of overriding a ComboBox control. I am simply
trying to avoid it repainting, but I can't seem to get it to work. What
am I doing 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");

}

}

}

}








Jan 13 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by TT (Tom Tempelaere) | last post: by
6 posts views Thread by Joe | last post: by
3 posts views Thread by Amin Sobati | 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.