|
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)
|
|
|
|
|
Sure... When you call typeof(T) , it returns a Type object, which has plenty of useful methods like GetInterface(), FindInterface(), etc.
Just don't use IsSubclassOf(), as that won't work for interfaces.
|
|
|
|
|
Reflection is probably the best way to go, but here is another technique which may be faster, though is not as flexible (i.e., you must know in advance if the type is a class or a struct, and it requires the class have a default constructor):
public bool IsClassAnimal<T>()
where T:new()
{
T t = new T();
return t is IAnimal;
}
public bool IsStructAnimal<T>()
{
T t = default(T);
if (t == null)
{
throw new InvalidOperationException("The type was a class.");
}
else
{
return t is IAnimal;
}
}
Sample interface/struct/class:
public interface IAnimal
{
}
public class Dog : IAnimal
{
}
struct Cat : IAnimal
{
}
Sample usage:
if (IsClassAnimal<Dog>())
{
MessageBox.Show("A dog is an animal!");
}
if (IsStructAnimal<Cat>())
{
MessageBox.Show("A cat is an animal!");
}
You could simplify that by just passing an instance of the class/struct, but that doesn't seem like what you're after. Also, if your class/struct is large (e.g., with lots of member variables), this could be a very expensive operation; not to mention it could have some weird side-effects. But, hey, thought I'd throw the technique out there anyway in case somebody can make use of it.
|
|
|
|
|
What about :
T myObj;
if (myObj is ICollectable)
variance = 1.2;
?
|
|
|
|
|
Hi,
I am currently doing my school project , which is about robot fish.
So the robot fish is used to detect the temperature inside the water.
2 types of devices I am using :
- Access device : this is usb-based, to connect to the pc, and also measure the temperature around it
- end device : this will measure the temperature somewhere else and transmit the wireless data to access device.
Both devices has been downloaded with some programs inside.
I have successfully displayed the data to the pc, using the software called sensor monitor visualizer( texas instrument ).
The problem is that I have to display the data using C# code programming , instead of that software from texas.
So I may need to find out the code to access or display or read the data from the usb device, and display the data again to the pc using some circles or whatever.
The detail is in http://focus.ti.com/lit/ug/slau227e/slau227e.pdf , including the screenshot of the display.
Please help me if you have any idea about this, as I am very poor in programming languages.
Thank you all.
|
|
|
|
|
depressedguy wrote: as I am very poor in programming languages.
I'll write something for you for $50 per hour.
|
|
|
|
|
As you know I am still a student, so I dont have so much money to pay
|
|
|
|
|
Hi,
For a project I am using System.IO.Ports.SerialPort for serial port communication. The serialport class can detect the status of DSR (serialPort.DsrHolding), CTS (serialPort.CtsHolding) and CD (serialPort.CDHolding), but it isn't possible to determine the status of the ring indicator (only RI change can be detected).
I made a work around, so you can still keep using the normal SerialPort functions, but you can also detect the RI status. I have only tested it on Vista x86 and VS2010.
Kind regards,
Mark
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using System.Reflection;
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern Boolean GetCommModemStatus(SafeFileHandle hFile, ref UInt32 Status);
const UInt32 MS_CTS_ON = 0x0010;
const UInt32 MS_DSR_ON = 0x0020;
const UInt32 MS_RING_ON = 0x0040;
const UInt32 MS_RLSD_ON = 0x0080;
private void ShowPinStates(System.IO.Ports.SerialPort serialPort)
{
UInt32 Status = 0;
Boolean CTS = false;
Boolean DSR = false;
Boolean DCD = false;
Boolean RI = false;
if (serialPort == null) return;
if (serialPort.IsOpen)
{
object baseStream = serialPort.BaseStream;
Type baseStreamType = baseStream.GetType();
SafeFileHandle portFileHandle = (SafeFileHandle)baseStreamType.GetField("_handle", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(baseStream);
if (GetCommModemStatus(portFileHandle, ref Status))
{
CTS = ((Status & MS_CTS_ON) == MS_CTS_ON);
DSR = ((Status & MS_DSR_ON) == MS_DSR_ON));
DCD = ((Status & MS_RLSD_ON) == MS_RLSD_ON));
RI = ((Status & MS_RING_ON) == MS_RING_ON));
}
}
}
|
|
|
|
|
Hi,
if you don't have a question, and just want to share your solution to compensate for the absence of a SerialPort.RingIndicator property, maybe you should post your approach as a tip. See here[^].
|
|
|
|
|
Hello,
I'm developing a application which sends and receives tons of data over UDP. I know the problem of UDP to loss udp-datagrams between sending and receiving. So i created a stack and a timer, where the datagrams to send are stored and sended. (All datagrams get a counting ID, so i'm able to recognize if something is missing)
With the interval of the timer i'm able to control the transfer-rate. My problem is now, how to calculate the correct interval of the transfer? Is there any logic to do this? I would work with the messages i get from the connection-partner how many datagrams are lost, but what is the best way to calculate this?
|
|
|
|
|
If delivery is important, why are you even using UDP?
UDP does not guarantee delivery, and considerbly less known, does not guarantee that the packets will arrive in the correct order.
This sounds very kludgy because you cannot guarantee that the interval will be constant, depending on network traffic and load on the client end, the server end, and everything in between. Remember, it's not just your app putting data on the wire and it's a shared medium being used by machines that have nothing to do with your app.
softwarejaeger wrote: My problem is now, how to calculate the correct interval of the transfer?
What defines what the correct interval should be? Just because a packet was lost is not a valid indicator that the transfer should slow down. The NIC will only send out packets when it can, not at the rate your app can send them.
|
|
|
|
|
Hi, Everybody
i am writing ANN code with c#
i wrote a class which has folowing structure;
<br />
<br />
class neuron<br />
{<br />
public double [] dentw = new double[nron];<br />
public double bias,hata,delta ;<br />
<br />
public double[] input = new double[nron ];<br />
public double output ;<br />
public int[] sbaglanti = new int[nron];<br />
public int[] sbagk = new int[nron];<br />
public int[] obaglanti = new int[nron];<br />
public int numara;<br />
public int dents;
public int oid,sid;<br />
<br />
~neuron() { }<br />
<br />
}<br />
class layer {<br />
public neuron[] noron = new neuron[nron];<br />
<br />
public layer()<br />
{<br />
for (int index = 0; index < noron.Length; index++)<br />
{<br />
noron[index] = new neuron();<br />
}<br />
<br />
}<br />
<br />
~layer(){}<br />
<br />
}<br />
class net {<br />
<br />
public int ban, hen;<br />
public layer[] layers = new layer[lay];<br />
public net()<br />
{<br />
for (int index = 0; index < layers.Length; index++)<br />
{<br />
layers[index] = new layer();<br />
<br />
}<br />
<br />
}<br />
<br />
~net(){}<br />
<br />
}<br />
<br />
net networks;<br />
<br />
in here, i want to change neuron count of layers and so how can i do it ?
can you help me ?
thanks
|
|
|
|
|
Just change the value of nron.
|
|
|
|
|
i want to difference neuron in diffrence layers it means firs layer which has 4 neurons and second layer 7 neurons ...
|
|
|
|
|
Make a Layer constructor with an int parameter giving the Layer's length. Then in class net, pass the length you want when you make a new Layer.
Take the initialization of noron out of class Layer, and allocate this array in the Layer constructor with the proper length.
|
|
|
|
|
You also need to make some changes to class neuron so that the arrays of weights to the previous and following layers have matching lengths.
|
|
|
|
|
Firstly I hope that your knowledge of Neural Networks is greater than your knowledge of programming, otherwise I fear that this particular project is going to be beyond your capabilities.
Still, let's get on with a little help:
The first thing that I would do is to change your net class, something like this
class net {
public int ban, hen;
public layer[] layers;
public net()
{
layers = new layer[lay];
for (int index = 0; index < layers.Length; index++)
{
layers[index] = new layer();
}
}
public net(int lays)
{
layers = new layer[lays];
for (int index = 0; index < layers.Length; index++)
{
layers[index] = new layer();
}
}
~net(){}
}
You will see that I suggest moving the instantiation of your layer[] to within the constructor. I have also added a constructor that takes an int as a parameter. With the class defined in this way:
net networks = new net(); gets you a network with the standard number of layers (whatever you have set your lay member to)
net networks = new net(25); gets you a network with 25 layers.
For your actual question I would suggest that one method would be to add yet another constructor to the net class and one in the layer class.
Firstly, layer gets the same treatment as above, for the same reason.
public neuron[] noron;
public layer()
{
noron = new neuron[nron];
for (int index = 0; index < noron.Length; index++)
{
noron[index] = new neuron();
}
}
public layer(int neurons)
{
noron = new neuron[neurons];
for (int index = 0; index < noron.Length; index++)
{
noron[index] = new neuron();
}
}
I have just listed the new constructors.
In the net class the new constructor would look something like:
public net(int lays, int[] neuronMap)
{
if (neurons.Length != lays)
{
throw new ArgumentException("neurons");
}
layers = new layer[lays];
for (int index = 0; index < layers.Length; index++)
{
layers[index] = new layer(neuronMap[index]);
}
}
~net(){}
}
Using the suggestions above you could then do something like:
int[] neuronMap = new int[] { 6, 7, 8, 9, 10 };
net networks = new net(5, neuronMap);
This creates a net with 5 layers . The first layer will have 6 neurons, the second 7 and so on.
I hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|