|
This happened to me once. After some frantic hacking, I eventually discovered that I had eliminated the call to InitializeComponent() in the class' constructor.
|
|
|
|
|
Sorry to post again so soon.
My following overriden ondraw function draws a graph
protected override void OnPaint(PaintEventArgs e)
{
if (machineStatusON)
{
for (int i = 0; i < ECGArray.Length; i++)
{
if (x > this.Width) x = 0;
x += 1;
px = x;
p = 60 - (ECGArray[i] / 3 + 50);
e.Graphics.DrawLine(yelgpen, px, pp + 30, x, p + 30);
e.Graphics.DrawLine(blackpen, x + 1, 0, x + 1, this.Height - 1);
pp = p;
pq = q;
pr = r;
}
}
}
As you can see, it uses ECGArray, but, I have a number of different arrays representing different graphs.
How can I setup my OnDraw() to display a different graph, based on what info is passed into my ecg object at runtime?
Thank you
Steve
|
|
|
|
|
You have been getting a lot of help here but honestly ask yourself, is this project beyond you?
If you are creating an application to draw seperate graphs then each graph should be seperate from any other graph. As you have been advised, creating a control or user control is the best (and only) solution. This control should get the information it needs to render itself independently of any other instance. In which case you would need to pass to it the graphics context, if necessry, and any data necessary to render.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
stephen.darling wrote: How can I setup my OnDraw() to display a different graph, based on what info is passed into my ecg object at runtime?
A simple solution.
you need to create Property
example:
public enum Graphs {Graph1, Graph2, Graph3);
private Graphs graphs;
public Graphs GraphType
{
get
{
return graphs;
}
set
{
if (graphs==value)
return;
graphs = value;
this.Invalidate();
}
}
after that use in a if or case statment inside OnPaint to select correct graph. But graphs are fairly complicated thing, so i suggest add sevreal methods for each graph and pass parameter Graphics.
And you can use for GDI a DoubleBuffer in orther to avoid some flickers. For better look you can applay antialiasing with a performance cost.
Also Mark makes good point
|
|
|
|
|
Hi.
I have a number of different sounds associated with defferent objects.
e.g.
ECGMachine objeect - beep1.wab, beep2.wav
Patient - breathNormal.wav, breathFast.wav, shout.wav
etc
Should I add the file path and relevent code of the sounds in each class, or create a soundPlay object?
If I do create a seperate object to play all sounds, what is the best way for all my objects to interact with it?
Thank you
Steve
|
|
|
|
|
I guess the classes you created that work together (with the possible exception of the application itself) are going to end up in one separate namespace and DLL file? If so, the sounds they use should all be resources, embedded in that same DLL (unless they logically belong to your app, and not those classes).
|
|
|
|
|
Thank you again, Luc.
Regards,
Steve
|
|
|
|
|
I've read this article Nested Set Model Treebuilder[^] and run into an issue. I can't figure out how to use proposed Nested Set algorythm to process not only a binary tree? How can I extend the current implementation to support building a tree with any structure?
|
|
|
|
|
I'd start by thoroughly understanding the node numbering algorithms of the binary tree version (see Trees in SQL - nested set model
[^] as referenced in the Nested Set Model Treebuilder[^] article.
Then, I'd devise and test (on paper) an algorithm with 3, 10, 100, or whatever, nodes at each level. This is about understanding the data model: it is not about implementing anything in code.
Only when I thoroughly understood how to number nodes, and how to move, insert and remove nodes (and adjust the node numberings accordingly) would I start to design an implementation of classes that build a tree in my application.
Also, if you are thinking of having a variable number of child nodes on a node, the move/insert/remove logic may become exceedingly complex.
You may find that you can 'simply' replace the left and right delegates with a selector delegate - which must now be a Func<T, int, V> , where the int identifies the child node of interest. I think you'll also have to supply a comparator delegate to aid with sorting nodes - but sorting nodes may now have to account for 'sibling position' which is a concept new to the Nested Set Model as implemented in the article.
To reiterate - I strongly recommend studying the theory of the data models you're wanting to implement before attempting to write any code.
Have fun and let us know how it turns out!
Chris
|
|
|
|
|
Thanks for your reply! I'm not going to implement moving/insert, but could you please show an example of recursion through Nested Set for the multi-child case? I just need to convert Nested Set table flat structure to multi-dimensional array. Thanks in advance!
|
|
|
|
|
I'm sure I could show an example of how to do so, but: "Give a man a fish - feed him for a day. Teach a man to fish - feed him for life" ... so I'm not going to.
There is much more value for you in attempting to think about the problem than having us spoon feed you with the solution.
If you share with us the thoughts you've had about how to adapt the binary tree problem to an n-ary problem you'll get some useful feedback. If you just ask us to do your job for you, you're unlikely to get any support.
|
|
|
|
|
Hi all, I have a server/client application. Program Works fine but I think I miss one little point. I put down a basic example. The question is; If I put a second strReadLine to server code and nothing comes from client, it gives error. Because it tries to read. So what can I do to prevent this?
string string1FromClient = strReader.ReadLine();
strWriter.WriteLine("client sent: "+ string1FromClient);
strWriter.Flush();
string string2FromClient = strReader.ReadLine();
strWriter.WriteLine("message");
strWriter.Flush();
string stringFromServer = strReader.ReadLine();
strWriter.WriteLine("message");
strWriter.Flush();
|
|
|
|
|
teknolog123 wrote: So what can I do to prevent this?
Don't read when you're not expecting a message - you can't read something that's not there. The client could tell the server how many "readlines" it should do to get the complete message across. That way you're still flexible in the amount of lines that you want to send, and the server won't be reading anything that's not there.
You might want to research the "handshaking" principle.
I are Troll
|
|
|
|
|
Thank you very much Eddy for the answer and for the reference also.
|
|
|
|
|
You're welcome
|
|
|
|
|
Hi everyone, I am wondering if any can help me how add on interface for user
to add or set color on application. User wants to choose color for themself.
All I need to do is have the custom color blend table available.
thanks.
|
|
|
|
|
If you search the articles on this site for Color Picker I'm sure you'll find some. If you want to use the .NET color picker you can use a class like this:
public class ColorPicker
{
public event EventHandler ColorChanged;
private Color color;
public ColorPicker()
{
color = Control.DefaultBackColor;
}
public Color Color
{
get { return color; }
set
{
if (color != value)
{
color = value;
OnColorChanged(EventArgs.Empty);
}
}
}
protected virtual void OnColorChanged(EventArgs e)
{
EventHandler eh = ColorChanged;
if (eh != null)
eh(this, e);
}
}
... and drop a PropertyGrid onto your form so you can do something like this:
public partial class FormMain : Form
{
private ColorPicker colorPicker;
public FormMain()
{
InitializeComponent();
colorPicker = new ColorPicker();
colorPicker.ColorChanged += new EventHandler(colorPicker_ColorChanged);
propertyGrid.SelectedObject = colorPicker;
}
private void colorPicker_ColorChanged(object sender, EventArgs e)
{
BackColor = colorPicker.Color;
}
}
|
|
|
|
|
I work with Visual Studio 2008 and programming in C #. I want to debug my code, but debug mode (F5) does not work (light gray, not active). How can I enable debug mode? Sincerely, A.
|
|
|
|
|
Most likely, you do not have a project or solution loaded.
This can happen if you double click a .CS file - the editor window shows the source code of your program, but the environment doesn't know what EXE the source belongs to.
Use File | Open | Project/Solution... to open a project (.CSPROJ) or solution (.SLN) file. Then Debug | Start Debugging will be enabled.
|
|
|
|
|
Hello.
OK, So I have managed to create my own control, derived from a panal class.
This control is an ECG display, required to draw and update itsself.
I have overided the ondraw() and added a timer to triger every 500ms, and added the code to draw a standard ecg graph using standard draw functions.
Now, I add the control to my form and set its name.
BUT, how do I refer to the control in the code WITHIN the control.
For example, my ondraw code requires to get the width of itsself.
I tried replacing the original variables (this control was on a form) with "this" but it does not work...
I then tried the following...
panal ecg = new panal();
constructor_function(panal ecg)
{
display = ecg;
}
But that seems to have no effect either.
Obviosly I can refer to the control from within my form very easy with its member, but because I have derived the class, I need to refer to my control in a number of function within the class.
My Idea was to create an ECG display class to handle its own drawing, and will eventualy get and set a range of ECG graphs, I didnt want all this functionality in the GUI.
Also, this object is representing the actual ECG machine and will soon have other functions such as Reset(), SwitchOn() etc, to be trigered from the main form and other objects.
Thank you in advance for any help...
Steve
|
|
|
|
|
You don't have to refer to it. this does that.
This is going to get a bit complex without digrams, but here goes...
Within your control class (or any class) this refers to the specific instance of your control (ignore static classes for the moment - you will meet them another day.)
It's as if you have a car class.
You can define a Color field, and a StartEngine method.
Within your class you can say
Console.WriteLine(this.Color); or just
Console.WriteLine(Color); because the this is implied.
When you execute the method containing the code, you will print the color (Americanisms! hah!) of your car. Not my car, or his car, your car.
If your form code had
Car mine = new Car(Blue);
Car yours = new Car(Red);
Car his = new Car(Green);
mine.PrintColor(); You would expect (and get) "Blue" printed.
his.PrintColor(); would give you Green.
Within your class, you don't need to know which instance of a Car it is - this takes care of it for you.
Equally, you would expect
yours.StartEngine(); to only start the Red cars engine - and it would.
Does that make sense?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OK yes I got it, and my code is working thank you.
One more thing.
Am I on the right track with my class structure.
form - my main form with controls including an ecg display, sats (oxygen, temp, pulse etc) display
engine - a simulation object that looks after everything, loads data from the form, and interacts with the following objects...
ECGDisplay the panal derived class to display an ecg, draw itsself, get ecg data, swithon, off etc
patient - the class to hold details about the patient and there current state (e.g is he conscience?)
form runs, and has a static member of the simulator class and calls its timer event to run the simulation.
the simulation object has members of all other objects to update the state of the patient, calculate stats, start the displays, update stuff etc!
Have I got this right or am I way off, it is confusing what objewct should pass what to what object, and what should communicate with what.
(Gosh! its even complecated to simply exaplin ha)
Thank you again
Steve
|
|
|
|
|
stephen.darling wrote: (Gosh! its even complecated to simply exaplin ha)
Ain't that the truth!
Without actually seeing it, from your description it sounds ok. Not sure you need the simulation object to be static, but if there is only ever going to one of it, then fine. If you ever need to expand this to two patients it could be a problem though.
Otherwise, looks OK to me
Good luck!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I have a class,
public class Collection<T>
and I was wondering if there was a way to determine if the data type used implements an interface.
I have used this code.
if (typeof(T) == typeof(ICollectable))
variance = 1.2;
but it never gets into this if block, regardless if the class I use implements ICollectable.
Any ideas?
|
|
|
|
|
I've come up with this, which will work for now. I am unsure of it's efficency though, I assume it uses Reflection
if (typeof(T).GetInterface("ICollectable") != null)
|
|
|
|
|