Can't inherit from Brush class. Help.

aewarnick

Well-known member
Joined
Jan 29, 2003
Messages
1,031
C#:
class BackgrdBrsh : Brush
{
	Color color1= SystemColors.Control;
	Color color2= SystemColors.Control;
	int degree=20;

	public Color Color1
	{
		get{return color1;}
		set{color1 = value;}
	}

	public Color Color2
	{
		get{return color2;}
		set{color2 = value;}
	}

	public int Degree
	{
		get{return degree;}
		set{degree = value;}
	}
}

BackgrdBrsh does not implement inherited abstract member System.Drawing.Brush.Clone()

I am not trying to clone the brush, just inherit from it to make my own custom Brush object. Just like the LinearGradientBrush did, apparently.
 
I am guessing that it is impossible so I am just creating my own new class without inheritance.

The problem is that I cannot get the properties of the class to show up in the designer like Sizes properties - Width and Height. And Font has a whole bunch of properties in the designer.

How would I go about doing that?
 
Brushes dont show up in the designer, their code classes. I think the Brush class is marked as uninheritable.
You just declare a public property, no idea how in C#
 
To display the font sub settings just have a Font Get/Set, the designer will place a drop+ next to it automatically

Public Properties will appear in the designer even if you dont want them to(unless theres a DoNotShowInDesigner Attribute) just Inherit Windows.Forms.Control to use it as a control
 
I dont want the Font properties. They are there. This is my class:

public class aBrush
{
Color color1= SystemColors.Control;
Color color2= SystemColors.Control;
int rotation=20;
//-----------------------------
public aBrush(Color c1, Color c2, int rot)
{
Color1= c1;
Color2= c2;
Rotation= rot;
}

public aBrush(Color c1)
{
Color1= c1;
}

public aBrush()
{

}
//-----------------------------
public Color Color1
{
get{return color1;}
set{color1=value;}
}
//-----------------------------
public Color Color2
{
get{return color2;}
set{color2=value;}
}
//-----------------------------
public int Rotation
{
get{return rotation;}
set{rotation=value;}
}
} //end class aBrush

That class is inside another class that shows up in the designer along with its properties. But the above class only displays in the designer as the class name. There is no "+ node" there to set the properties of this class.

That is what I need.
 
You need to specify a typeconverter for that class using the TypeConverter attribute. Make a very simple typeconverter class that just inherits from ExpandableObjectConverter. I gave someone an example of doing what youre trying to do before, try searching the forum for ExpandableObjectConverter.
 
Last edited by a moderator:
No because I dont understand what the first class is for that creates an instance of the second class and then returns it.
Public Class ClassWithProperty
Private _Expandy As ExpandyClass

Public Sub New()
_Expandy = New ExpandyClass()
End Sub

Public Property Expandy() As ExpandyClass
Get
Return _Expandy
End Get
Set(ByVal Value As ExpandyClass)
_Expandy = Value
End Set
End Property
End Class

Here is my code
C#:
public class FormBrushClass
				{
					FormBrush FB=new FormBrush();

					public FormBrush FormBr
					{
						get{return FB;}
						set{FB=value;}
					}
				}
				/// <summary>
				/// Colors the BackGround of the Form.
				/// </summary>
				[ TypeConverter(typeof(ExpandableObjectConverter)) ]
				public class FormBrush
				{
					Color c1= SystemColors.Control;
					Color c2= SystemColors.Control;
					Rectangle fiStartEndArea=new Rectangle(0,0,100,100);
					int rot=20;
//-----------------------------
					public FormBrush(Color color1, Color color2, Rectangle fillStartEndArea, int rotation)
					{
						Color1= color1;
						Color2= color2;
						FillStartEndArea= fillStartEndArea;
						Rotation= rotation;
					}

					public FormBrush(Color color1)
					{
						Color1= color1;
					}

					public FormBrush()
					{
						
					}
//-----------------------------
					public Color Color1
					{
						get{return c1;}
						set{c1=value;}
					}
//-----------------------------
					public Color Color2
					{
						get{return c2;}
						set{c2=value;}
					}
//-----------------------------
					public Rectangle FillStartEndArea
					{
						get{return fiStartEndArea;}
						set{fiStartEndArea=value;}
					}
//-----------------------------
					public int Rotation
					{
						get{return rot;}
						set{rot=value;}
					}
				} //end class FormBrush
//----------------------------

				FormBrush backgrdBrush=null;
				
				/// <summary>
				/// A brush to paint the background any color you want. Will always be behind the image.
				/// </summary>
				public FormBrush BackgrdBrush
				{
					get{return backgrdBrush;}
					set{backgrdBrush=value; this.Invalidate();}
				}
 
I dont understand why I need that first class: FormBrushClass.
Can you explain why I need it and how to point the property grid to that class?
 
You said you wanted to make your class exandable in the propertygrid, which indicates its going to be exposed as a member of another class.
 
Ok I understand that. It is exposed as a MEMBER of another class.

Now how can I point the compiler to the first class when my code uses the second class and not the first at all?
 
Back
Top