473,809 Members | 2,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons.Generic;

using System.Componen tModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows. Forms;

using System.Text.Reg ularExpressions ;

using System.Collecti ons;

using System.Drawing. Drawing2D;

namespace GeneralTesting

{

public partial class frmMain : Form

{

MyCustomComboBo x TB1 = new MyCustomComboBo x();
public frmMain()

{

InitializeCompo nent();

TB1.FormattingE nabled = true;

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

TB1.Name = "TB1";

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

TB1.TabIndex = 1;

TB1.SelectedInd exChanged += new
System.EventHan dler(this.TB1_S electedIndexCha nged_1);

this.Controls.A dd(TB1);

DataClass DC = new

}

private void TB1_SelectedInd exChanged_1(obj ect sender, EventArgs e)

{

richTextBox1.Te xt += ((Employee)TB1. SelectedItem).T oString() + "\n";

TB1.Items.Remov e((Employee)TB1 .SelectedItem);

}

private void button1_Click(o bject sender, EventArgs e)

{

if (TB1.Enabled == true)

{

TB1.Enabled = false;

}

else

{

TB1.Enabled = true;

}

}

class MyCustomComboBo x : ComboBox

{

protected override void OnPaint(PaintEv entArgs e)

{

// ...

MessageBox.Show ("TRIGGERED OnPaint");

}

protected override void OnPaintBackgrou nd(PaintEventAr gs e)

{

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

// .. override its background painting.

MessageBox.Show ("TRIGGERED OnPaintBackgrou nd");

}

}

}

}







Jan 13 '06 #1
4 3724
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.co m

"RSH" <wa************ *@yahoo.com> wrote in message
news:u0******** ******@TK2MSFTN GP11.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.Collecti ons.Generic;

using System.Componen tModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows. Forms;

using System.Text.Reg ularExpressions ;

using System.Collecti ons;

using System.Drawing. Drawing2D;

namespace GeneralTesting

{

public partial class frmMain : Form

{

MyCustomComboBo x TB1 = new MyCustomComboBo x();
public frmMain()

{

InitializeCompo nent();

TB1.FormattingE nabled = true;

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

TB1.Name = "TB1";

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

TB1.TabIndex = 1;

TB1.SelectedInd exChanged += new
System.EventHan dler(this.TB1_S electedIndexCha nged_1);

this.Controls.A dd(TB1);

DataClass DC = new

}

private void TB1_SelectedInd exChanged_1(obj ect sender, EventArgs e)

{

richTextBox1.Te xt += ((Employee)TB1. SelectedItem).T oString() + "\n";

TB1.Items.Remov e((Employee)TB1 .SelectedItem);

}

private void button1_Click(o bject sender, EventArgs e)

{

if (TB1.Enabled == true)

{

TB1.Enabled = false;

}

else

{

TB1.Enabled = true;

}

}

class MyCustomComboBo x : ComboBox

{

protected override void OnPaint(PaintEv entArgs e)

{

// ...

MessageBox.Show ("TRIGGERED OnPaint");

}

protected override void OnPaintBackgrou nd(PaintEventAr gs e)

{

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

// .. override its background painting.

MessageBox.Show ("TRIGGERED OnPaintBackgrou nd");

}

}

}

}







Jan 13 '06 #2
comboBox1.DrawM ode = DrawMode.OwnerD rawFixed;
comboBox1.DrawM ode = DrawMode.OwnerD rawVariable;

You must handle the Draw Item event.

"RSH" <wa************ *@yahoo.com> wrote in message
news:u0******** ******@TK2MSFTN GP11.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.Collecti ons.Generic;

using System.Componen tModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows. Forms;

using System.Text.Reg ularExpressions ;

using System.Collecti ons;

using System.Drawing. Drawing2D;

namespace GeneralTesting

{

public partial class frmMain : Form

{

MyCustomComboBo x TB1 = new MyCustomComboBo x();
public frmMain()

{

InitializeCompo nent();

TB1.FormattingE nabled = true;

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

TB1.Name = "TB1";

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

TB1.TabIndex = 1;

TB1.SelectedInd exChanged += new
System.EventHan dler(this.TB1_S electedIndexCha nged_1);

this.Controls.A dd(TB1);

DataClass DC = new

}

private void TB1_SelectedInd exChanged_1(obj ect sender, EventArgs e)

{

richTextBox1.Te xt += ((Employee)TB1. SelectedItem).T oString() + "\n";

TB1.Items.Remov e((Employee)TB1 .SelectedItem);

}

private void button1_Click(o bject sender, EventArgs e)

{

if (TB1.Enabled == true)

{

TB1.Enabled = false;

}

else

{

TB1.Enabled = true;

}

}

class MyCustomComboBo x : ComboBox

{

protected override void OnPaint(PaintEv entArgs e)

{

// ...

MessageBox.Show ("TRIGGERED OnPaint");

}

protected override void OnPaintBackgrou nd(PaintEventAr gs e)

{

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

// .. override its background painting.

MessageBox.Show ("TRIGGERED OnPaintBackgrou nd");

}

}

}

}







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.c om> wrote in
message news:uy******** ******@TK2MSFTN GP14.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.co m

"RSH" <wa************ *@yahoo.com> wrote in message
news:u0******** ******@TK2MSFTN GP11.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.Collecti ons.Generic;

using System.Componen tModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows. Forms;

using System.Text.Reg ularExpressions ;

using System.Collecti ons;

using System.Drawing. Drawing2D;

namespace GeneralTesting

{

public partial class frmMain : Form

{

MyCustomComboBo x TB1 = new MyCustomComboBo x();
public frmMain()

{

InitializeCompo nent();

TB1.FormattingE nabled = true;

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

TB1.Name = "TB1";

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

TB1.TabIndex = 1;

TB1.SelectedInd exChanged += new
System.EventHan dler(this.TB1_S electedIndexCha nged_1);

this.Controls.A dd(TB1);

DataClass DC = new

}

private void TB1_SelectedInd exChanged_1(obj ect sender, EventArgs e)

{

richTextBox1.Te xt += ((Employee)TB1. SelectedItem).T oString() + "\n";

TB1.Items.Remov e((Employee)TB1 .SelectedItem);

}

private void button1_Click(o bject sender, EventArgs e)

{

if (TB1.Enabled == true)

{

TB1.Enabled = false;

}

else

{

TB1.Enabled = true;

}

}

class MyCustomComboBo x : ComboBox

{

protected override void OnPaint(PaintEv entArgs e)

{

// ...

MessageBox.Show ("TRIGGERED OnPaint");

}

protected override void OnPaintBackgrou nd(PaintEventAr gs e)

{

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

// .. override its background painting.

MessageBox.Show ("TRIGGERED OnPaintBackgrou nd");

}

}

}

}








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*****@nowher e.com> wrote in message
news:O7******** ******@TK2MSFTN GP12.phx.gbl...
comboBox1.DrawM ode = DrawMode.OwnerD rawFixed;
comboBox1.DrawM ode = DrawMode.OwnerD rawVariable;

You must handle the Draw Item event.

"RSH" <wa************ *@yahoo.com> wrote in message
news:u0******** ******@TK2MSFTN GP11.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.Collecti ons.Generic;

using System.Componen tModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows. Forms;

using System.Text.Reg ularExpressions ;

using System.Collecti ons;

using System.Drawing. Drawing2D;

namespace GeneralTesting

{

public partial class frmMain : Form

{

MyCustomComboBo x TB1 = new MyCustomComboBo x();
public frmMain()

{

InitializeCompo nent();

TB1.FormattingE nabled = true;

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

TB1.Name = "TB1";

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

TB1.TabIndex = 1;

TB1.SelectedInd exChanged += new
System.EventHan dler(this.TB1_S electedIndexCha nged_1);

this.Controls.A dd(TB1);

DataClass DC = new

}

private void TB1_SelectedInd exChanged_1(obj ect sender, EventArgs e)

{

richTextBox1.Te xt += ((Employee)TB1. SelectedItem).T oString() + "\n";

TB1.Items.Remov e((Employee)TB1 .SelectedItem);

}

private void button1_Click(o bject sender, EventArgs e)

{

if (TB1.Enabled == true)

{

TB1.Enabled = false;

}

else

{

TB1.Enabled = true;

}

}

class MyCustomComboBo x : ComboBox

{

protected override void OnPaint(PaintEv entArgs e)

{

// ...

MessageBox.Show ("TRIGGERED OnPaint");

}

protected override void OnPaintBackgrou nd(PaintEventAr gs e)

{

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

// .. override its background painting.

MessageBox.Show ("TRIGGERED OnPaintBackgrou nd");

}

}

}

}








Jan 13 '06 #5

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

Similar topics

3
4203
by: Ali Eghtebas | last post by:
Hi, I have 3 questions regarding the code below: 1) Why can't I trap the KEYDOWN while I can trap KEYUP? 2) Is it correct that I use Return True within the IF-Statement? (I've already read the documentation but it is rather hard to understand so please don't refer to it :) 3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m) as the last code line while I have used Return MyBase.ProcessKeyEventArgs(m)
7
8541
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way of doing it. I have a table with products, tblProducts, some of them are Active while others are Inactive. The form shows all the products purchased by a customer, both Active and Inactive in a ComboBox, cbProducts. My client wants to view all...
8
12121
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the combobox. What is the solution? Thank you in advance.
3
6838
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article: http://msdn.microsoft.com/msdnmag/issues/03/08/DataGrids/default.aspx I have a problem when there are two DataGrid's on one form, and when I switch focus from one grid to the other. To be more precise, when I'm editing a combo box column in one grid, and then click in the combo column of...
6
4680
by: Joe | last post by:
Stupid question, but I'm really stuck I have a class that overrides ToString(). When this class is cast back to Object, and ToString() called, Object.ToString() is called instead. I've tried everything: Public Overrides Function ToString() as String, Overrides Function ToString() as String, Overrides Overloads ToString() as string, Shadows ToString() as String,
3
1560
by: Amin Sobati | last post by:
Hi, I have two classes. Class2 inhertis Class1: ----------------------------- Public Class Class1 Public Overridable Sub MySub() End Sub End Class Public Class Class2
4
4681
by: RSH | last post by:
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
0
2184
by: HKSHK | last post by:
Hi guys, I'm currently trying to implement the VB6-ItemsData property into a CombolBox and it works so far, but there is one problem... I can only inherit one class to another class, which is either a) System.Windows.Forms.ComboBox or b) System.Windows.Forms.ComboBox.ObjectCollection. If I add (a) I can't override Items.Add.
10
105210
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that make use of these methods assume that the methods obey these contracts so it is necessary to ensure that if your classes override these methods, they do so correctly. In this article I'll take a look at the equals and hashCode methods. ...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10633
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10375
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9198
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.