|
Hi, sorry for the delay in getting back. I'm having a busy day at work
It seems AussieLew has guided you through. If you need any more help feel free to post back and I will have a look tonight (UK) if you are stuck or unsure.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
He has helped but I still need a little guidance as it all seems to be forward and not backward passing.
Thanks Glenn
|
|
|
|
|
glennPattonWork wrote: all seems to be forward and not backward passing
No. Have a look at this exmple that does exactly what you want. Anything you don't understand, just ask!
using System;
public delegate void ThreeIntsEventHandler(object sender, ThreeIntsEventArgs e);
public class ThreeIntsEventArgs : EventArgs
{
private int x;
private int y;
private int z;
public ThreeIntsEventArgs(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
public int X
{
get { return x; }
}
public int Y
{
get { return y; }
}
public int Z
{
get { return z; }
}
}
using System.Drawing;
using System.Windows.Forms;
public partial class FormChild : Form
{
public event ThreeIntsEventHandler ThreeInts;
private NumericUpDown numericUpDownX;
private NumericUpDown numericUpDownY;
private NumericUpDown numericUpDownZ;
private Button buttonOK;
public FormChild()
{
InitializeComponent();
numericUpDownX = new NumericUpDown();
numericUpDownX.Location = new Point(12, 12);
numericUpDownY = new NumericUpDown();
numericUpDownY.Location = new Point(12, 36);
numericUpDownZ = new NumericUpDown();
numericUpDownZ.Location = new Point(12, 60);
buttonOK = new Button();
buttonOK.Text = "OK";
buttonOK.Location = new Point(12, 84);
buttonOK.Click += new System.EventHandler(buttonOK_Click);
Controls.AddRange(new Control[] { numericUpDownX, numericUpDownY, numericUpDownZ, buttonOK });
AcceptButton = buttonOK;
}
private void buttonOK_Click(object sender, System.EventArgs e)
{
OnThreeInts(new ThreeIntsEventArgs((int)numericUpDownX.Value, (int)numericUpDownY.Value, (int)numericUpDownZ.Value));
}
protected virtual void OnThreeInts(ThreeIntsEventArgs e)
{
ThreeIntsEventHandler eh = ThreeInts;
if (eh != null)
eh(this, e);
}
}
using System.Windows.Forms;
public partial class FormParent : Form
{
public FormParent()
{
InitializeComponent();
Click += new System.EventHandler(FormParent_Click);
}
private void FormParent_Click(object sender, System.EventArgs e)
{
FormChild formChild = new FormChild();
formChild.ThreeInts += new ThreeIntsEventHandler(formChild_ThreeInts);
formChild.Show();
}
private void formChild_ThreeInts(object sender, ThreeIntsEventArgs e)
{
MessageBox.Show(string.Format("X: {0}, Y: {1}, Z:{2}", e.X, e.Y, e.Z));
}
}
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi,
I have had a fiddle it seems a little over compliated at the moment. I have a simpler method using the Panel component with three text boxe sand a button click to make the panel visible, once the variables are entered the panel is made invisible the values can be recorded. What the opinion of that? I have tried in a demo App does look too bad.
Glenn
|
|
|
|
|
If it works for you then cool
I don't see how that helps you get values from one form to another though
I'm planning another article that will be a bit more light hearted so more accessible on various OOP techniques/patterns including events/delegates (Observer Pattern). I'll post here when it's published, which will probably be a couple of weeks, as you may find it useful.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
So you (and others) can see how simple events really are to create, I have posted a simple tip here[^].
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
I have 3 classes
class A{
public virtual void M(){
Console.WriteLine( "A" );
}
}
class B:A{
public virtual void M(){
Console.WriteLine( "B" );
}
}
class C:B{
public virtual void M(){
Console.WriteLine( "C" );
}
}
Now i want to call from C:M() the method of A -
How can i do it ?
|
|
|
|
|
Cast C as A :
((A)C).M();
|
|
|
|
|
In case that my type declaration is
A a = new A();
A b = new B();
A c = new C();
Your solution will not work.
You can check it if you want.
|
|
|
|
|
I checked : if you declare your 3 variables as A (as you wrote it), then the three following lines
a.M();
b.M();
c.M();
return these lines :
A
A
A
Then if you try these commands :
((A)a).M();
((B)b).M();
((C)c).M();
you get the following :
A
B
C
Anyway, as told by other members, it is really a poor design, and maybe you should consider changing the way you deal with your requirements.
Edit: this is true only if you declare M methods as virtual rather than override.
modified on Thursday, September 2, 2010 10:46 AM
|
|
|
|
|
Assuming those are actually overridden (You missed the 'override' keyword), you can't. That's the point of overriding a method.
Even if you cast it as the base class, it'll still call the overriding one on the child class.
If you NEED to call the base class, then you'll have to change your design.
EDIT: Actually, there may be a way to hack around it with reflection, but that would be REALLY bad practice.
|
|
|
|
|
Sorry, i forgat to add the ''override' keyword.
But the virtual table contain an pointer to all the base classes method - so why i cant ?
|
|
|
|
|
yes, but where does it point when you do an override?
|
|
|
|
|
Because it leads to unpredictable behaviour. As each override is a specialisation of the method it derives from, it makes on sense to do this; which base would you be interested in, the class it derives from, the one that derives from, how about object?
|
|
|
|
|
You can't or you shouldn't, however you can:
public class C : B{
public void BaseM(){
base.M();
}
public override void M(){
}
}
Also:
public interface ISillyInterface1{
void M();
}
public interface ISillyInterface2{
void M();
}
public class A : ISillyInterface1, ISillyInterface2{
void ISillyInterface1.M(){
}
void ISillyInterface2.M(){
}
}
|
|
|
|
|
Your question is not clear.. What you want to do? Your code just replaces the base-class methods without using the "new" keyword...
When your method M is an override of Method M in class B and C: what you want, is not possible without changing the design. But if you want to "replace" the method you can through casting: Look at the following example.
using System;
namespace CallBaseClass
{
class Program
{
static void Main(string[] args)
{
A a = new A();
A b = new B();
A c = new C();
a.M();
b.M();
c.M();
((A)a).M();
((B)b).M();
((C)c).M();
Console.ReadKey();
}
}
class A
{
public virtual void M()
{
Console.WriteLine("A");
}
}
class B : A
{
public new void M()
{
Console.WriteLine("B");
}
}
class C : B
{
public new void M()
{
Console.WriteLine("C");
}
}
}
|
|
|
|
|
That would be a poor design and is not allowed in C#.
|
|
|
|
|
class A {
public virtual void M(bool pDoBaseCall) {}
}
class B : A {
public override void M(bool pDoBaseCall) {
if (pDoBaseCall) {
base.M(pDoBaseCall);
} else {
}
}
}
class C : A {
public override void M(bool pDoBaseCall) {
if (pDoBaseCall) {
base.M(pDoBaseCall);
} else {
}
}
}
C c = new C();
c.M(true);
c.M(false);
You can achieve a finer level of control with an enum instead of a bool, or even dynamic code which determines depth of inheritance on run time... But this design hurts many good practices and principles, I recommend going back to drawing board and try again...
|
|
|
|
|
I have an aspx page. In that page I am displaying div when click on link. Div contains iframe and i am assigning url to the frame like below.
<asp:linkbutton id="lkbtn" text="Create" onclientclick="return ShowDiv(this)" runat="server">
<asp:label text="Create" runat="server" forecolor="Chocolate" font-bold="true">
| X
|
|
// Function to Show the Div //
function ShowDiv(CtrlName)
{
document.getElementById('divUserCtrl').style.display = 'inline';
frames['ifrm'].window.location = "CreateProject.aspx?ProjCat=G";
return false;
}
when click on linkbutton can able to display div and redircting to CreateProject page. But in CreateProject when click on a button i need to close this div. How can I do this in c#. I tried like Page.RegisterStartupScript("Reload", "window.close();"); But no luck
|
|
|
|
|
You may get an answer here but you will be more likely to succeed here[^]. If you decide to post there, link to your question above so you don't get flamed for cross posting!
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
dear all
how to scale or zoomx and zoomy for one image size? for example, my image size is 1624, 1224, but my pictureBox is 680,580, how to scale and zoomx and zoomy, make sure all image will be centered and display in the pictureBox. thanks
|
|
|
|
|
Try google search[^].
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
Hi,
You should look at the SizeMode property of the PictureBox class.
This is really a simple issue, you should look for properties of objects you're using before posting on this forum. If you give yourself a little effort, people here will be more likely to help you.
Regards.
|
|
|
|
|
Could someone tell me please, what is the difference between the following two blocks of code? When would you assign an initial value for a field in the field definition and when would you do it in a constructor?
public class MyClass
{
private int myField;
public MyClass()
{
myField = 123;
}
}
public class MyClass
{
private int myField = 123;
public MyClass()
{
}
}
Thanks in advance
|
|
|
|
|
Hi Dewald,
It's more a matter of design choice, since there's no real functional difference between both your propositions.
Personnaly I'd rather use the first one. I only assign values to constants at declaration. I find this way much clearer (maybe because I always do this way). Moreover, it allows consistence of design if you want to set up the following :
public class MyClass
{
private int myField;
public MyClass() : this(123) {}
public MyClass(int field)
{
myField = field;
}
}
Perhaps you can try both ways, compile, and see what is the difference in the generated IL Code (with the IL disassembler). I never did such a test myself.
Hope this helps. Regards.
|
|
|
|