|
I am not a theory guy myself. So I can't give a comprehensive answer. But interfaces allow a sort of OOP way of multiple inheritance.
Plus they are very useful in remoting. Read my article on remoting [too lazy to dig out the link] where I show how interfaces are useful.
Nish
p.s. I hope someone gives you a more thorough answer
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
An interface defines one set of related methods that can be implemented by any class to perfom some task.
Take the IComparable interface as an example. It is very simple but what it does means a lot. In this case IComparable has a single method, CompareTo, which compares the object with one that is passed in and returns an int debending on how it compares. Negative values means the instance is less than the one passed in, 0 means they are equal, and positive means the instance is greater than the one passed in.
The reason this is an interface is simple; it is easy to get an interface vs finding out of a class implements a method; then have to worry about what accessability modifiers (public/private/etc) it has. Some objects don't make sense to have a less-than/equal/greater-than operators so making it a method of Object is useless in those cases (for example, one Point is no less than or greater than another; only equal or not equal).
To find out what the required implementation of IComparable is you refer to the contract, in this case that is the MSDN entry for IComparable.
To get an instance of the interface, either cast to it or use the as keyword.
IComparable ic = (IComparable) myString; or IComparable ic = myString as IComparable .
I show a couple uses of interfaces in my article "Using reflection to extend .NET programs", though it discusses reflection more than interfaces you can see how I use an interface to load classes at runtime without needing to know about the class itself.
James
Simplicity Rules!
|
|
|
|
|
James T. Johnson wrote:
you can see how I use an interface to load classes at runtime without needing to know
Woah!!! Is that what your article was about?????
Blast!
Yesterday I was searching for dynamic loading of DLLs
I never thought that's what an article on reflection would be about, though it should have been obvious
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Check it out, I wrote it to support a plug-in arcitecture in a project; it may or may not be suitable for your purposes though
James
Simplicity Rules!
|
|
|
|
|
Hello all,
I am trying to create thumnails of web images stored in a database(gif, jpeg and png)
I ran into problems with palettes and transparency.
Does anyone have an idea on how to scale an 8 bpp (or other indexed color depth), gif or png, retaining the palette and transparency, using GDI+ and the .NET framework.
I tried the Graphics.DrawImage method and the Bitmap.GetThumbImage method, but they end up loosing the palette and the transparency. (They work fine for JPEG)
Any Graphics image drawing does not work on indexed colors images.
One way to do it would be to access the BitmapData through unsafe code with the LockBitmap method for the source and destination and apply a linear transformation to fill the palette indexes of the destination and copy the palette from the source to the destination. (As in Christian Graus's articles)
Another way would be to make the destination a 36 bits ARGB image, copy/scale the source with a bicubic interpolation and then reduce the color of the destination image using the palette of the source, letting the encoder use the alpha channel info to set the transparency.
None of that seems straight forward to me.
Thanks if anyone can help.
|
|
|
|
|
IIRC palettized images aren't correctly supported in GDI+; including transparent GIFs.
I'll take a look through my e-mail and see if I can find the actual list of what isn't supported.
James
Simplicity Rules!
|
|
|
|
|
Most paint programs convert images up to 24/32bit color prior to doing any type of image manipulation and then convert them back.
Todd Smith
|
|
|
|
|
Hi all,
Can I load and use the libraries (.dll type) written by C# on runtime? That means I have an application that I don't need to add the references (.dll files) at compile-time. Whenever the application is executed, it will load and use all of libraries (.dll files) in current folder. Certaintly, I can already build this application without compile-error. I consider that this issue maybe concern with the reflection technology. But I haven't found out the way to apply this technology yet.
Thank you very much to spend time in helping me.
Vu.
|
|
|
|
|
Hello Vu Truong
After seeing your post, I did some R & D and finally found out it's easy to do this. I wrote an article too
Dynamically loading a DLL - MC++
Nish
p.s. Same window as this is a link within CP
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Does anyone know of a tool that will perform a conversion of a GUI written using C#.Net and Windows Forms to an ASP.Net compatible Web Form. I found one tool trying to do it for VB (WinToWeb) but nothing for C#.
Thanks
|
|
|
|
|
How can I add a file version to my C# application?
I want this verion to be shown in the file properties sheet...
Thanks...
|
|
|
|
|
In one of your files put the following code (you may need to add this to the top; using System.Runtime.CompilerServices; )
<br />
[assembly: AssemblyVersion("1.0.*")]
HTH,
James
Simplicity Rules!
|
|
|
|
|
Yeap that's it!!
Thank you!!
|
|
|
|
|
Hello Friends,
Can anyone know any way of calling default mail client of the PC, if user clicks on contact list from my application.I dont want to send mail from my application.I want to simply call any default mail client and pass on the email address and a message for subject to that mail client.
Mail clinet can be anything like outlook express or any application like outlook express.
Thanks in advance.
Pranoti
|
|
|
|
|
|
MS Toolbar Control in mscomctl.ocx has a HotImageList property where as the .NET ToolBar doesn't. Are there any disadvantages or problems using the MS Toolbar Control, or any other COM Components and distributing the mscomctl.ocx with my .NET application?
Jerzy
|
|
|
|
|
Does anyone know if it is possible to change the colour of the text in a text box?
I have tried textBox1.forecolor = System.drawing.color.red;
and also changing the color in the textbox properties but it doesn't seem to work!
Am I missing something?
Thanks
Paddy
|
|
|
|
|
Hmmm... Your question caught me as setting the ForeColor property in the designer should work, in fact it works on my box . However if you would like to change the color programtically you can do:
<code>
this.textBox1.ForeColor = Color.Aqua;
You should see call kinds of different colors in the intellisence once you type Color. You may also need to prepend this. in front of your textBox1
HTH
Nick Parker
|
|
|
|
|
Thanks for the quick reply Nick.
I don't know why it wont work for me!
Do you need to add Using Systems.color or anything like that at the start of your code?
Paddy
|
|
|
|
|
Try pasting this code in exactly, I just made this up really quickly.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ChangeColor
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.textBox1.ForeColor = System.Drawing.Color.Aqua;
this.textBox1.Location = new System.Drawing.Point(72, 80);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(104, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
this.button1.Location = new System.Drawing.Point(16, 128);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 24);
this.button1.TabIndex = 1;
this.button1.Text = "Change To Red";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button2.Location = new System.Drawing.Point(128, 128);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(104, 24);
this.button2.TabIndex = 2;
this.button2.Text = "Change To Green";
this.button2.Click += new System.EventHandler(this.button2_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(256, 221);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.button1,
this.textBox1});
this.Name = "Form1";
this.Text = "Change textBox1 Color";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
this.textBox1.ForeColor = Color.Red;
}
private void button2_Click(object sender, System.EventArgs e)
{
this.textBox1.ForeColor = Color.DarkGreen;
}
}
}
HTH
Nick Parker
|
|
|
|
|
Thanks for the help.
I'm in poxy work at the moment with no visual studio so I wont get a chance to try adding it to my code till lunch time!
Do you know if the textBox.ForeColor changes all the text in the texbox or can I make different words different colors by changing the forecolor before I append text to the texbox?
Thanks,
Paddy.
|
|
|
|
|
Paddy wrote:
Do you know if the textBox.ForeColor changes all the text in the texbox or can I make different words different colors by changing the forecolor before I append text to the texbox?
If you wish to use different colors for different words you would have to use a control such as the RichTextBox control which supports formatting. The text field is only a single color unless you make your own text control and draw it yourself.
Rocky Moore
|
|
|
|
|
Thanks for the help,
Is it difficult to implement a RichTextBox control?
Paddy
|
|
|
|
|
You just declare a RichTextBox object or you could find it in the Toolbox.
To change the color/font or something you just use SelectionFont/SelectionColor property to change the color/font of selected text.
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C# and C++!
|
|
|
|
|
Thanks Rickard,
I'll give that a try later, doesn't sound to difficult.
Paddy
|
|
|
|