|
What do you mean by specialized, Luc?
I checked it and the proper derived class is instanced with the correct overridden method being called.
|
|
|
|
|
a cat is a specialized mammal, which is a specialized animal.
|
|
|
|
|
Oh ok smarty That's what I want anyway.
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">jabbawok wrote:</div>MyBase tmp = (MyBase) Activator.CreateInstance(TypeArray[0]);</blockquote>
I'm stuck again.
How do you use Activator.CreateInstance when the class has a constructor that takes arguements?
|
|
|
|
|
|
aspdotnetdev wrote: ConstructorInfo.Invoke should do the trick.
Geez, now there's another way to confuse me
I found it could be done using the following. Basically I'm trying to build a tree of random expression nodes. FunctionList is an ArrayList holding the types, and ParentNode is the "owner" of the newly instanced "child":
ImageFunction ChildNode = (ImageFunction) Activator.CreateInstance( (Type)FunctionList[RandNum], new ImageFunction[] {ParentNode} );
But this is getting messy very quickly. I'm trying to duplicate what I once did in Delphi and that's probably why I'm having so much trouble. In Delphi you could do something similar to:
ImageFunction( FunctionList[RandNum] ).Create( ParentNode ); Is there surely no simpler way to do this in c#?
|
|
|
|
|
jabbawok wrote: Is there surely no simpler way to do this in c#?
Create some helper methods:
public void SomeMethod()
{
Animal a = Create<Animal, Dragon>(5);
Dragon d = Create<Dragon>(5);
}
public TReturn Create<TReturn, TSpecific>(params object[] parameters)
{
return (TReturn)Activator.CreateInstance(typeof(TSpecific), parameters);
}
public TReturn Create<TReturn>(params object[] parameters)
{
return (TReturn)Activator.CreateInstance(typeof(TReturn), parameters);
}
public class Animal
{
}
public class Dragon : Animal
{
public Dragon(int height)
{
MessageBox.Show(height.ToString());
}
}
|
|
|
|
|
Also, this third overload will probably be more useful to you, since you are storing types in variables.
public void SomeMethod()
{
Animal a2 = CreateInstance<Animal>(typeof(Dragon), 5);
}
public TReturn CreateInstance<TReturn>(Type t, params object[] parameters)
{
return (TReturn)Activator.CreateInstance(t, parameters);
}
|
|
|
|
|
Hi,
actually my question is simple, but still I couldn't find the answer. I searched everywhere.
In my project I have a webBrowser control. Before the webBrowser control navigates from one page to another, I have to intercept the post data, so I can analyze it. If for example I would be on a page with a form, and I click on the button to submit the form, I would have to get somehow the data the webpage wants to send via POST.
I work on solving this problem for a long time, so any help would be greatly appretiated.
And sory for my bad english, I'm not a native speaker.
|
|
|
|
|
|
thx for the answer, but the WebBrowserNavigatingEventArgs contain everything exept the data that will be posted.
I guess the only way I get the post data is to read the values of the form input elements .
|
|
|
|
|
Imho that's the right approach.
/ravi
|
|
|
|
|
As part of the app I am expanding, the user needs to be able to annotate an image. I am going to link images to individual item, like a car or a house, and allow the user to annotate that image by circling something, or free form drawing on the image with a stylus or mouse (Likely a stylus with a tablet PC)
The link cannot be a straight line, it needs to follow the course of the user's pen.
Can someone point me in the right direction? I have a basic handle on the GDI+ class, but don't quite see how to draw a free form line.
Thank you!
--EA
|
|
|
|
|
I'm not sure if this is what you need, but I have a similar case where I need to build a line as the mouse moves while the left button is pressed.
On a MouseDown event, I set a flag and initialize things. In the MouseMove event I check to see if the flag is set, save points, and redraw a line as the mouse moves. The MouseUp event clears the flag, saves the points and does whatever else is needed.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
As Walt said, your free form line will consist of a series of short straight lines, built while you move the mouse. Expect a MouseMove event for every two to three pixels you move, unless you are moving very rapidly.
|
|
|
|
|
Great, thank you to both of you guys, turned out to be easy enough.
Cheer, EA
|
|
|
|
|
I use This CODE fOR my Program
but i have to Two Click To use Button
Whats IS The Problem?
My Code Is Hear
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
Boolean bB2ShouldStop = false;
Boolean bB1ShouldStop = false;
private void button1_Click(object sender, EventArgs e)
{
if (label1.Text == "500")
{
for (int i = 1; (i <= 500) && !bB1ShouldStop; i++)
{
label1.Text = i.ToString();
System.Threading.Thread.Sleep(10);
Application.DoEvents();
if (label2.Text != "500")
{
bB2ShouldStop = true;
label2.Text = (Int16.Parse(label2.Text) + 1).ToString();
}
}
bB1ShouldStop = false;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (label2.Text == "500")
{
for (int i = 1; (i <= 500) && !bB2ShouldStop; i++)
{
label2.Text = i.ToString();
System.Threading.Thread.Sleep(10);
Application.DoEvents();
if (label1.Text != "500")
{
bB1ShouldStop = true;
label1.Text = (Int16.Parse(label1.Text) + 1).ToString();
}
}
bB2ShouldStop = false;
}
}
}
}
modified on Tuesday, April 20, 2010 3:48 PM
|
|
|
|
|
I haven't read all that as it isn't formatted properly; you should use PRE tags instead of CODE tags (you could still edit the message).
Anyway, Application.DoEvents() seldom is the solution, it often causes just more problems. And you should not write event handlers that last longer than a few dozen milliseconds, so Thread.Sleep() is not acceptable there at all.
|
|
|
|
|
The only thing that could prevent the loop executing is the shouldstop variable. I can see that bb1ShouldStop will be true when the button2_Click handler returns. In your code it is reset to false by running the button1 handler.
Alan.
|
|
|
|
|
|
we don't have a problem, you do. So you should tell us what the intent is and what you are getting that you don't like, so someone could explain the difference.
FYI: this is a terrible abuse of Application.DoEvents() as it makes both handlers reentrant, i.e. you could click a button and execute its handler while the same or the other button's handler is still running.
|
|
|
|
|
I've posted this before but I wasn't clear so this time I've drawn a picture to show you what I exactly want to implement in my c# win app.
my previous message:
Hey guys,
I'm working on an windows application for an institute, let me elaborate a bit,
It gets the hours for classes (7-8:30, 9-10:30 ...) and also number of classrooms ( 1, 2, ....) then using these two collection of data I want to create a schedule like Sunbird, I have hours and classrooms therefore there is a vertical column (classrooms) and horizontal columns (hours).
what I have in mind is to create a 2*2 matrix and each cell will have id and that way I can check the status of it, but how can i display it visually ? I can't use datagridview, and this is dynamic so I can't pre-define the cells.
what do you suggest for this ?
I'm open to new suggestions, maybe you've got a better idea than I do.
see we have the hours (which is taken form one table) and class rooms ( which is taken from another table)
so I dunno how many I'm going to have, I guess I have to get these values from the user then dynamically create a new table with these info.
regards,
K1
here's a picture : http://img28.imageshack.us/img28/6143/classschedule.jpg[^]
modified on Wednesday, April 21, 2010 12:46 AM
|
|
|
|
|
Your picture just shows as a blank square, but anyway, there are several controls commercial and free that can help you do what you want, creating your own one will take some time.
I want to die like my grandfather- asleep, not like the passengers in his car, screaming!
|
|
|
|
|
|
There seem to be... naughty adverts around the image you are linking to. They're not particularly tasteful either.
I'd like to remind you that this kind of material is not suitable for work and can people into serious trouble. If you could please find a better place to host your images and change / remove that link.
My current favourite word is: Smooth!
-SK Genius
|
|
|
|