|
|
Check the properties of your mainform and make sure that topmost is set to false.
|
|
|
|
|
|
I am trying to customize a commercial component.
I found I could write something like that:
public class MyHackClass : StupidCommercialClass
{
protected override void OnAnEvent()
{
if(!someCondition)
{
base.OnAnEvent();
return;
}
....
}
}
The problem is, I still want to raise the event 'AnEvent' but I do not want to call the base class's OnAnEvent() method.
Is there a way to achieve that with reflection?
As shown in the sample I already look (without much luck) into TypeDescriptor class..
|
|
|
|
|
Does this work?
if (this.AnEvent != null)
this.AnEvent(this, new EventArgs());
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Nope, only the declaring class could fire the event.
What I need is a way to get at the underlying storing delegate.
|
|
|
|
|
TypeDescriptor is for Design-Time support of components and not for Reflection purposes.
Use typeof(StupidCommercialClass).GetField(...).GetValue(..) to get the field storing the delegate - it should be a private field having exactly the same name as the event.
|
|
|
|
|
|
How to parse generic numeric string, irrespective of whether the enter value is small int (int16) or big int (int32) or more than that. I want to parse the string as numeric (number) not as int16 or int32?
Thanks in advance
kumar
|
|
|
|
|
Hello,
I think the TryParse Method of double should do it.
You have to use "System.Globalization.NumberStyles.Number",
<br />
double d;<br />
string yourestring = ???;<br />
if(double.TryParse(yourestring,System.Globalization.NumberStyles.Number, CultureInfo.CurrentCulture, out d))<br />
{<br />
}<br />
Hope that helps you!
All the best,
Martin
|
|
|
|
|
How to Add and Remove registry key for Office 2007 (Word) Add-in dynamically during runtime (using C#). After completing installation of my Addin I wanted to remove the registry key and write (add) again when I start Office 2007 (Word) from my Program. And Word 2007 should read the registry of mine.
|
|
|
|
|
Hi Members...
I am developing a project in which i need to read the value of one default key. I wrote a code but it is showing "". Is there any way to read them? Please share your ideas with me...
thanks in advance
Pradeep
|
|
|
|
|
Hello,
following the Composite design pattern I want to create hierarchical structures of objects exploiting the following design. All possible classes inherit from an abstract base class. The base class provides an abstract method which can be used to add elements to the structure. The Add() method has to be overridden in subclasses.
Let's assume something like that:
<br />
public abstract class BaseClass<br />
{<br />
public abstract void Add(BaseClass BaseElement); <br />
}<br />
<br />
public class Element_1 : BaseClass<br />
{<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
}<br />
}<br />
<br />
public class Element_2 : BaseClass<br />
{<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
}<br />
}<br />
<br />
...<br />
<br />
<br />
public class Element_n : BaseClass<br />
{<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
}<br />
}<br />
The problem is as follows: Theoretically any object derived from BaseClass can be added to any other object derived from BaseClass. Not too bad, the design is utterly flexible. But somehow I want to control which objects can be added to other objects. The idea is to perform runtime checking when objects are about to be added within the Add() method. The runtime checking shall be as uniform as possible to obtain a good design which is easy to maintain and extensible.
I have come up with the following idea. That's where the interfaces come into play.
Let's assume that objects of class Element_2 and Element_3 can be added to objects of class Element_1. I could introduce the following interface:
interface IElement_1<br />
{<br />
}
and change the accordant classes as follows:
<br />
public class Element_2 : BaseClass, IElement_1<br />
{<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
}<br />
}<br />
<br />
public class Element_3 : BaseClass, IElement_1<br />
{<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
}<br />
}
Now the Add() method of class Element_1 might look like that:
<br />
public override void Add(BaseClass BaseElement)<br />
{<br />
IElement_1 element_1 = BaseElement as IElement_1; <br />
<br />
if (element_1 != null)<br />
{<br />
}<br />
}<br />
Thereby I could avoid code that checks whether BaseElement is of type Element_2 or Element_3... BaseElement has just to implement the interface IElement_1 to make sure it can be added to an object of type Element_1.
The crucial question is: May I use these pseudo interfaces for the sake of distinction in the Add() method? Is it an elegant solution or a stupid approach? Following my idea one would create a pseudo interface for each class that can accomodate other objects. The meaning of interface IElement_i would be: The class implementing interface IElement_i can be added to objects of type Element_i.
The reason why I have come up with this idea is, that in the structures I build (I'm working on a chart library) there is a manifold variety of classes (Axis, AxisLabels, AxisTitles, Legends, Series, Grid, ChartTitle...) which can be combined in various ways. To ensure a good design I'm striving for a simple runtime checking approach in the Add() methods. Otherwise the runtime checking might turn out to be annoying.
I'm grateful for any comments on my pseudo interfaces
Thanks,
Goebel
|
|
|
|
|
IMO if you want to restrict only certain objects to be added to the Add() function, then you should actually create different overloads of the function that accepts only the child classes you want.
If you have a function that accepts objects from base class then by logic it is correct for objects from inheriting child classes to be passed to the function. To use interface only to prevent this sort of things is - to me - a wrong thing to do. Is there any reason you don't want to create multiple overloads instead? (These functions can in turn call your private Add() function).
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
Edbert,
thanks for your helping reply. There is no apparent reason NOT to use overloads. I am not that experienced so didn't consider them in the first place.
A few quick questions anyway:
- Would you regard using the overloads as proper design? Say there are 5 different elements I can add to another element. I might end up with 5 overloads.
- What does happen with the former abstract Add() method? It has to be overridden in the inheriting child classes but isn't of much help. Instead the overloads bear the brunt. Just do nothing?
<br />
public class Element1 : BaseClass<br />
{<br />
public override void Add(BaseClass element)<br />
{<br />
}<br />
}<br />
- What do you mean by "These functions can in turn call your private Add() function"? Who is public, who is private?
Your reply was much appreciated!
Goebel
|
|
|
|
|
Yes, overloads are proper design. Heck, it is part of what Object Oriented Programming is about.
Since you're not going to use the Add(BaseClass element) you do not need to declare it in the base class.
You can only override functions with the same signature (i.e. takes same arguments and returns same type).
Even if you leave it in the base class you do not have to override it on child classes that do not need it.
If you do not override it in the child class the function with the particular signature will simply become unavailable for the child class.
Oh, and one more thing, what I meant by calling the private Add() is if your overloads actually do the same thing (has the same code), then you can create a private function that can be called by the overloads and receive the base class instead.
|
|
|
|
|
MailMessage mailMsg = new MailMessage();
mailMsg .From = "from@fromServer.com";
mailMsg .To = "to@toServer.com";
mailMsg .Cc = "cc@ccServer.com"";
mailMsg .Bcc = "bcc@bccServer.com";
mailMsg .Subject = "SubjectOfTheMailString";
mailMsg .Body = "BodyOfTheMailString";
SmtpMail.Send(mailMsg );
How can we know the mail is sent successfully.
Can you show me more methods to know the mail is delivered right. Or we can keep track of process sending mail.
Thx
ngh
|
|
|
|
|
Maybe this:
http://www.levelextreme.net/wconnect/wc.dll?10,7,10,45
can helps
regards
|
|
|
|
|
Hello,
I want to pass over all the opened forms of my application and set the visible property to false, if the form was shown.
How can I do that?
Thanks.
|
|
|
|
|
Whenever you open a form, store the reference to it in some central collection (don't forget to remove after closing the form). Now, if you want to hide all forms, iterate over the collection and assign false to the Visible property.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Can you provide me with some code, please?
|
|
|
|
|
It's almost impossible without knowing your code.
Declare the central form collection where it csn be accessed whenever a fom is opened (either in the main form that opens all other forms or as a static property or class which is always accesssible). If you're using .NEt 2.0 use a generic List as collection otherwise an ArrayList or a custom, typoesafe class derived from CollectionBase .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
a quick and dirty way:
<br />
using System;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Forms;<br />
<br />
public class GetFormsCollection {<br />
<br />
private delegate bool WndEnumProc(System.IntPtr hWnd , int lParam);<br />
<br />
[DllImport("user32.dll", CharSet=CharSet.Auto)]<br />
private static extern bool EnumWindows (WndEnumProc lpEnumFunc, int lParam);<br />
<br />
public readonly System.Collections.ArrayList Forms;<br />
<br />
public GetFormsCollection() {<br />
Forms = new System.Collections.ArrayList();<br />
EnumWindows(new WndEnumProc(EnumCallback), 0);<br />
}<br />
<br />
private bool EnumCallback(System.IntPtr hWnd, int lParam) {<br />
<br />
Control hForm = System.Windows.Forms.Control.FromHandle(hWnd);<br />
if (hForm != null) this.Forms.Add(hForm);<br />
return true;<br />
}<br />
<br />
public static void SetVisiblity(bool fVisible) {<br />
<br />
foreach (System.Windows.Forms.Form objForm in new GetFormsCollection().Forms) {<br />
objForm.Visible = fVisible;<br />
}<br />
}<br />
}<br />
Martin
|
|
|
|
|
Thanks a lot, but I got an error:
Unable to cast object of type 'System.Windows.Forms.ToolStripDropDownMenu' to type 'System.Windows.Forms.Form'.
On this line:
foreach (System.Windows.Forms.Form objForm in new GetFormsCollection().Forms)
I'm using .NET 2.0
What wrong?
Thanks.
|
|
|
|
|
oops, I'm using VS 2003 so I can't check that... As I said, it's a quick & dirty way;).
Creating a Forms.Control object from a handle seems to work for some other UI controls (i.e. ToolStripDropDownMenu) that respond to EnumWindows().
However, try to replace the line
Control hForm = System.Windows.Forms.Control.FromHandle(hWnd);
with this one:
System.Windows.Forms.Form hForm = System.Windows.Forms.Control.FromHandle(hWnd) as System.Windows.Forms.Form;
in order to get forms only.
hope that helps
Martin
|
|
|
|