|
The delegate has no implementation so it is already an abstraction. The handler methods can be abstract though...
public abstract class AbstractBase
{
public event EventHandler DoXxx;
protected abstract void OnDoXxx(EventArgs e);
}
public class Concrete1 : AbstractBase
{
protected override void OnDoXxx(EventArgs e)
{
}
}
public class Concrete2 : AbstractBase
{
protected override void OnDoXxx(EventArgs e)
{
}
}
|
|
|
|
|
thanks for the answer...
and if i want to do it next way :
{
public delegate void delgateX(object sender, EventArgs e);
abstarct class A:
{
public event delgateX xxx;
}
}
class B : A
{
}
class C : A
{
}
i get next error :
The event 'xxx' can only appear on the left hand side of += or -= (except when used from within the type 'A')
Thanks for help
|
|
|
|
|
Ah, I see your problem.
The delegate itself can't be abstract but an instance of it (including an event) can. See the sample and test code below.
using System;
class Program
{
static void Main(string[] args)
{
new Test().Run();
Console.ReadKey();
}
}
class Test
{
public void Run()
{
B b = new B();
b.Xxx += new DelegateXxx(b_Xxx);
C c = new C();
c.Xxx += new DelegateXxx(c_Xxx);
A ab = b as A;
ab.Xxx += new DelegateXxx(ab_Xxx);
A ac = c as A;
ac.Xxx += new DelegateXxx(ac_Xxx);
b.DoXxx();
Console.WriteLine();
ab.DoXxx();
Console.WriteLine();
c.DoXxx();
Console.WriteLine();
ac.DoXxx();
Console.WriteLine();
}
private void b_Xxx(object sender, EventArgs e)
{
Console.WriteLine("b_Xxx Raised");
}
private void c_Xxx(object sender, EventArgs e)
{
Console.WriteLine("c_Xxx Raised");
}
private void ab_Xxx(object sender, EventArgs e)
{
Console.WriteLine("ab_Xxx Raised");
}
private void ac_Xxx(object sender, EventArgs e)
{
Console.WriteLine("ac_Xxx Raised");
}
}
public delegate void DelegateXxx(object sender, EventArgs e);
public abstract class A
{
public abstract event DelegateXxx Xxx;
public abstract void DoXxx();
protected abstract void OnXxx(EventArgs e);
}
public class B : A
{
public override event DelegateXxx Xxx;
public override void DoXxx()
{
OnXxx(EventArgs.Empty);
}
protected override void OnXxx(EventArgs e)
{
Console.WriteLine("Raising from B");
DelegateXxx delegateXxx = Xxx;
if (delegateXxx != null)
delegateXxx(this, e);
}
}
public class C : A
{
public override event DelegateXxx Xxx;
public override void DoXxx()
{
OnXxx(EventArgs.Empty);
}
protected override void OnXxx(EventArgs e)
{
Console.WriteLine("Raising from C");
DelegateXxx delegateXxx = Xxx;
if (delegateXxx != null)
delegateXxx(this, e);
}
}
|
|
|
|
|
Thank you
|
|
|
|
|
Hello,
In a Application i used Microsoft.office reffernce. Then .Docx file Converts in .PNG.
But Now i have need without installed Microsoft Office Converts the File .DOCX to .PNG. I am using DocumentFormat.OpenXml.dll, but i am unable to convert .docx to .PNG.
So please Suggest me How i can convert .docx to .PNG without having Microsoft Office
Regards
Raushan Kumar
|
|
|
|
|
|
|
Hello Eddy Vluggen,
Thanks a lot for your good reply.
but by using this article we can just manipulate .docx file,
I have need to convert in Image File like(PNG\JPEG), still i have not get any idea for convert .docx to .PNG.
I have done by using the Microsoft word reference, but i need to run without Microsoft word installed.
Process which i have done:-
open document in word application then just split page wise in document after that copyaspicture.
I have called user32.dll native API for clipboard manipulation and then transfer file in MetaFile using intptr and then save the file in(PNG\JPEG)
So please give some idea how can i copy picture in clipboard ya any otherway without office reference.
Thanks
Raushan Kumar
|
|
|
|
|
raushan_9 wrote: So please give some idea how can i copy picture in clipboard ya any otherway without office reference.
Convert it to Html[^], and render the Html as a picture
I are Troll
|
|
|
|
|
How can I check if the value if null so that I do bnot get the error:
"object reference not set to an instance of an object" ?
This still gives the error:
if !((byte[])Message.GetField("FieldName", 0).Value == null
{
}
Thanks
|
|
|
|
|
Several variables could be null. By the way, what's the type of "Message"?
Try something like:
byte[] byteArray = null;
if (Message != null)
{
Field myField = Message.GetField("FieldName", 0);
if (Field != null)
{
object fieldValue = Field.Value;
if (fieldValue != null)
{
byteArray = (byte[])fieldValue;
}
}
}
|
|
|
|
|
Hi,
This will not work because message is not empty...
It has several fields such as field1, field2, field3...
It fails when I check for if field3 is null
Any thoughts please?
|
|
|
|
|
You also never specified what type Field is or Value. If these are integer types (not Nullable integer), then they can never be null and the compile will fail.
|
|
|
|
|
You will need to break your statement down into smaller parts and test a each level, starting with Message , then the result of Message.GetField("FieldName", 0) and so on.
I must get a clever new signature for 2011.
|
|
|
|
|
I agree but when I do if Message.GetField("FieldName", 0) == null then it gives error.
|
|
|
|
|
That's not what he meant. He meant to check something like this:
var msg = Message;
if (msg == null)
{
}
var field = msg.GetField("FieldName", 0);
if (field == null)
{
}
var value = field.Value;
|
|
|
|
|
|
Bernhard already gave you the answer here[^].
I must get a clever new signature for 2011.
|
|
|
|
|
Hello everybody,
The GetWindowText Function is not working fine if my selected application title is
मेरी थकन or Something like that.
If you can think then I Can.
|
|
|
|
|
How have you defined GetWindowText? What does your import look like?
|
|
|
|
|
Dear Sir,
Actually GetWindowText is a Native Api
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
If you can think then I Can.
|
|
|
|
|
You should be using the Unicode version GetWindowTextW() .
I must get a clever new signature for 2011.
|
|
|
|
|
Dear Sir,
Thanks for reply and Answer.
But i don't know how to use GetWindowTextW in C#.
Can u please describe me how to Use GetWindowTextW in the place of GetWindowText.
If you can think then I Can.
|
|
|
|
|
eg_Anubhava wrote: Can u please describe me how to Use GetWindowTextW in the place of GetWindowText.
They are exactly the same, except that GetWindowTextW() returns its data in Unicode, so it works for C#. See here[^] for the formal specification.
I must get a clever new signature for 2011.
|
|
|
|
|
I know it is. I needed to see the function definition, which you for some reason have provided in VB. Specifically I wanted to see what your CharSet was set to.
|
|
|
|