|
I wrote my first own control, it derives from Windows.Forms.Control, and it's a simple ellipse label. The code for drawing:
<br />
protected override void OnPaint(PaintEventArgs pe) {<br />
Graphics g = pe.Graphics;<br />
Brush foreBrush = new SolidBrush(ForeColor);<br />
Brush backBrush = new SolidBrush(BackColor);<br />
g.FillEllipse(backBrush, ClientRectangle);<br />
<br />
StringFormat fmt = new StringFormat();<br />
fmt.Alignment = StringAlignment.Center;<br />
fmt.LineAlignment = StringAlignment.Center;<br />
g.DrawString(Text, Font, foreBrush, ClientRectangle, fmt);<br />
<br />
base.OnPaint(pe);<br />
}<br />
}<br />
The question - how to implement so that the label wraps text if it is to long to fit in a single line?
|
|
|
|
|
Hi, you can use MeasureString to give you the length of the string in drawing units (pixels) and compare the width of your control - border (or just client width if there is not an NC portion). Then of course, just extend the height of your control by the height of the current font, split, and wrap the line.
You can get the font height with the Font property and call its Height property but make sure you use your graphics object's MeasureString method to get the length of the string in question.
hope that is enough detail for you, if not let me know and i'll try to help further.
|
|
|
|
|
That'll do, thanks a lot man!
|
|
|
|
|
How to i create a website that can send sms`s ???
Thanks in advance !;)
|
|
|
|
|
You could implement a website with a server backend that sends SMS's. Search Codeproject, there are several articles (such as this one[^]) that describe how you can send SMS messages.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
these articles cannot be accessable.
|
|
|
|
|
I'm using a PropertyGrid control, and I want to display only some particular properties. I know I have to implement ICustomTypeDescriptor in my class so the grid can use GetProperties method. And that's the problem - I need only that method, but the interface is quite big, contains many methods. I know I always can write empty method implementation but to me it just doesn't seem the right thing to do. Is there another way? If not, could anyone post some piece of code which implements the GetProperties method?
|
|
|
|
|
Is there another way?
Not that I'm aware of
If not, could anyone post some piece of code which implements the GetProperties method?
public class MyDescriptor : ICustomTypeDescriptor<br />
{<br />
public TypeConverter GetConverter()<br />
{<br />
return TypeDescriptor.GetConverter(this, true);<br />
}<br />
<br />
public EventDescriptorCollection GetEvents(Attribute[] attributes)<br />
{<br />
return TypeDescriptor.GetEvents(this, attributes, true);<br />
}<br />
<br />
EventDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetEvents()<br />
{<br />
return TypeDescriptor.GetEvents(this, true);<br />
}<br />
<br />
public string GetComponentName()<br />
{<br />
return TypeDescriptor.GetComponentName(this, true);<br />
}<br />
<br />
public object GetPropertyOwner(PropertyDescriptor pd)<br />
{<br />
return this;<br />
}<br />
<br />
public AttributeCollection GetAttributes()<br />
{<br />
return TypeDescriptor.GetAttributes(this, true);<br />
}<br />
<br />
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)<br />
{<br />
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(this, attributes, true);<br />
<br />
PropertyDescriptor[] pd = new PropertyDescriptor[x];<br />
<br />
for (int i=0; i<pdc.Count; i++)<br />
{<br />
if (pdc[i].Name.Equals("Property1"))<br />
{<br />
pd[0] = pdc[i];<br />
}<br />
else if (pdc[i].Name.Equals("Property2"))<br />
{<br />
pd[1] = pdc[i];<br />
}<br />
...<br />
}<br />
<br />
return new PropertyDescriptorCollection(pd);<br />
}<br />
<br />
PropertyDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetProperties()<br />
{<br />
return ((ICustomTypeDescriptor) this).GetProperties(new Attribute[0]);<br />
}<br />
<br />
public object GetEditor(Type editorBaseType)<br />
{<br />
return TypeDescriptor.GetEditor(this, editorBaseType, true);<br />
}<br />
<br />
public PropertyDescriptor GetDefaultProperty()<br />
{<br />
return TypeDescriptor.GetDefaultProperty(this, true);<br />
}<br />
<br />
public EventDescriptor GetDefaultEvent()<br />
{<br />
return TypeDescriptor.GetDefaultEvent(this, true);<br />
}<br />
<br />
public string GetClassName()<br />
{<br />
return TypeDescriptor.GetClassName(this, true);<br />
}<br />
}<br />
|
|
|
|
|
Thanks a lot! One more question - the class that implements the ICustomTypeDescriptor is the class I will be forwarding to tge PropertyGrid right? Sorry if this is a supid question...
|
|
|
|
|
the class that implements the ICustomTypeDescriptor is the class I will be forwarding to tge PropertyGrid right?
Yes
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
hi ,
i am trying to fetch the datafrom database into dataet and display it in a richtextbox in rtf format.
it displays a illegal file format.
please throw some light on where i am mistaken
below is the code for your reference
{
string st;
string st1 = "";
st = "select * from TPNeeds";
SqlDataAdapter ad = new SqlDataAdapter(st,con);
ad.Fill(dataset11,0,0,"TPNeeds");
DataTable dt = dataset11.Tables[0];
ArrayList arr = new ArrayList();
//Encoder e1 = Encoding.UTF8.GetEncoder();
Encoding encode = Encoding.Default;
foreach(DataRow row in dt.Rows)
{
st1 += row["NeedText"].ToString();
//richTextBox2.Rtf = encoding.GetString(binaryData,0,binaryData.Length);
}
byte[] rawBytes = Encoding.ASCII.GetBytes( st1 );
using ( MemoryStream ms = new MemoryStream(rawBytes) )
{
richTextBox2.LoadFile( ms, RichTextBoxStreamType.RichText );
}
// System.IO.MemoryStream stream = new System.IO.MemoryStream(StrToByteArray(st1));
// richTextBox2.LoadFile(stream,RichTextBoxStreamType.PlainText);
//richTextBox2.LoadFile(stream,RichTextBoxStreamType.RichText);
//richTextBox2.Rtf = encoding.GetString(bytearr,0,bytearr.Length);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
MessageBox.Show(ex.StackTrace.ToString());
}
}
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
mrlathiwala
|
|
|
|
|
Is the data in the database a string in rich text format? Or is it a string in plain text format?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
it's in plain text format
|
|
|
|
|
Then why are you trying to load it as RichText? Plain text should be set in the RTB as RTB.Text = plainText.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
how to play a movie file stored on hard disk
|
|
|
|
|
|
Download managed DirectX 9 SDK.
Add a reference in your project to Microsoft.DirectX.AudioVideoPlayback.
Video.Play("someFile.mpg");
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
I am making a CustomLabel class which extends Label and abstract class CustomBehaviour. For some reasons the class is not an interface. How do you do this in C#? I can extend only one class at a time
|
|
|
|
|
For some reasons the class is not an interface. How do you do this in C#?
What do you mean ?
|
|
|
|
|
I mean that I have two classes to inherit from, and I don't know hot to best do it. If the CustomBehaviour was an interface there would be no problem, bu it is an abstract class. I can't inherit from two classes, can I? And I wonder how to implement this.
|
|
|
|
|
Why can't you just have your custom behavior code inherit from the label class and then make all your new classes inherit from your custom behavior class? Thats how I do it!
Maybe I'm not understanding the problem though
|
|
|
|
|
|
This is a class I wrote for my program's needs. It adds some methods and fields to Label. However, the case is how to make a class like MyLabel which inherits from Label and my class?
|
|
|
|
|
|
I came up with this:
abstract class AbstractCustomLabel : Label {}
abstract class AbstractBehavioralCustomLabel : CustomBehaviour {}
public class CustomLabel : AbstractBehavioralCustomLabel
{
public CustomLabel code
public override void OnDraw code
}
Is it acceptable?
|
|
|
|