|
Thanks a lot Alan, This approach has resolved my issue!
|
|
|
|
|
You can do this:
if (insd.GetType() is Class1<IByte>) {} But, using a temporary variable and the "as" operator is more performant than using "is," and will not throw an error:
Class1<IInt> testObject = insd as Class1<IInt>;
if (testObject != null) Console.WriteLine("it's Class1<int>"); Is your goal here to test an "unknown" object's type at run-time, and then take action based on the underlying type? If so, there are other strategies you can use.
yours, Bill
“Humans are amphibians: half spirit, half animal; as spirits they belong to the eternal world; as animals they inhabit time. While their spirit can be directed to an eternal object, their bodies, passions, and imagination are in continual change, for to be in time, means to change. Their nearest approach to constancy is undulation: repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
|
|
|
|
|
Hi All,
I am trying to create a function that passes the cursor's starting and ending x,y coordinates as parameters. For instance I would like to set the cursor's starting x,y coordinate when the user clicks the left mouse button. Then as the user holds down the left mouse button and drags the cursor to a desired location, the ending x,y coordinate is dynamically set and updated. The final ending coordinate is set when the left button is released. I am currently working with the following code:
private void Cursor_Coord(out Cursor C1, out Cursor C2)
{
Cursor C1;
Cursor C2;
if(Mouse.LeftButton == MouseButtonState.Pressed)
{
C1 = new Cursor(Cursor.Current.Handle);
C1.Position = new Point(Cursor.Position.X, Cursor.Position.Y);
}
if(Mouse.LeftButton == MouseButtonState.Released)
{
C2 = new Cursor(Cursor.Current.Handle);
C2.Position = new Point(Cursor.Position.X, Cursor.Position.Y);
}
}
I am planning to send the changing cursor coordinates to the Drawline method to be used as the first and second point. The effect I have in mind is that the line is drawn as the mouse is in motion. The problem is it's not working. Any help will be greatly appreciated, thanks in advance.
modified 21-May-13 4:02am.
|
|
|
|
|
You don't need to use a cursor to do this. As you've rightly noted in your code, the part you are actually interested in is the Position - that's all you need to keep track of.
|
|
|
|
|
Hi, you've replied to my post as I was in the process of making changes to it.
|
|
|
|
|
This is pretty easy to do, but I think you are trying to do it the wrong way. You don't say what your environment is, but I'll assume WinForms.
First off, you probably don't need to use Cursor at all for this, a simple Point is enough.
Try doing this by adding a few class level variables, and handling a few events:
private Point pointStart;
private Point pointEnd;
private bool drawing = false;
private void frmMain_MouseDown(object sender, MouseEventArgs e)
{
pointStart = e.Location;
pointEnd = pointStart;
drawing = true;
Invalidate();
}
private void frmMain_MouseUp(object sender, MouseEventArgs e)
{
drawing = false;
}
private void frmMain_MouseMove(object sender, MouseEventArgs e)
{
if (drawing)
{
pointEnd = e.Location;
Invalidate();
}
}
private void frmMain_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(Pens.Blue, pointStart, pointEnd);
}
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Hi, thanks for your reply. I have used your code but VS2010 is complaining that the Invalidate method does not exist in the current context. I assumed that Invalidate is a built-in function of C# but it doesn't appear to be the case.
modified 21-May-13 22:59pm.
|
|
|
|
|
|
At a guess, you have added the word "static " in there somewhere - static methods cannot access non-static class methods, fields or properties.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Hi, I need the coding for multiple object selection in propertygrid.
Please reply as soon as possible
|
|
|
|
|
vvino2020 wrote: Hi, I need the coding for multiple object selection in propertygrid. We "help" with coding-questions; if you need someone to write code for you, then this is the wrong place.
vvino2020 wrote: Please reply as soon as possible I wouldn't "wait" with the answer just for the fun of it, and this question isn't more important than the other questions.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Have a play with the MultiSelect property on the grid
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Assign an array of objects to PropertyGrid's SelectedObjects[^] property. Note the plural-s.
PropertyGrid will then sort out what properties to display and what values to display for shown properties in the usual way.
Ciao,
luker
|
|
|
|
|
Hi,
I am trying to use Modern UI Charts for my Windows Store app but I am not able to get it working.
A similar issue was logged by another person here along with the code
Can anyone please help??
|
|
|
|
|
Does this third party support WIndows 8? Check if they have documentation that tells you what versions they support.
|
|
|
|
|
Yes it does.. Clearly stated in the documentation
|
|
|
|
|
Raghavendra Reddy C wrote: Can anyone please help??
Given how little information you've given us, no. There's no source for us to view, and there's precious little detail about not being able to get it working in there.
|
|
|
|
|
|
|
|
Raghavendra Reddy C wrote: A similar issue was logged by another person here along with the code And also a link to the solution.
Use the best guess
|
|
|
|
|
hi,
I am trying to write some data to local port to open the cash drawer....
with this simple code
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Open();
serialPort1.PortName = textBox1.Text;
serialPort1.Write("16 20 1 0 1");
serialPort1.Close();
}
However the Port is not recoginized in C# unless it's a COM port...
My printer somehow say it should be a local port with the name USB_BTP-R880NP_1 (as the name of the printer) .. How can i communicate with it without using a COM command from C#...
Second question is
in the reference, it said to send data to the port to open cash drawer by following this format :
ASCII DLE DC4 n m t
HEx 10 14 n m t
Decimal 16 20 n m t
Range n = 1
m =0,1
1<=t <= 6
Is my command above correct?
Thanks
|
|
|
|
|
Surprisingly, the SerialPort class in C# is designed specifically to talk to serial ports... You cannot talk to a USB device through the SerialPort class, no matter what name you give it. It will only work with COM ports.
Most cash drawers are serial though, are you sure that the cash drawer is connected via usb? If thats the case, you will need to get some sort of driver API to communicate with the usb device through a windows driver and hooks, not a very easy task. Sending raw data to a USB port through the WinAPI involves knowing device descriptors and endpoints that are difficult to know unless you have an intimate knowledge of the driver structure.
As far as your second question, thats something only the manufacturer can tell you. Without having more knowledge on our part, like a manual or interface document, we can't tell you if what you typed is right or wrong.
|
|
|
|
|
Hello All
I am trying to implement MVVM and use IDataErrorInfo interface to validate data in the model classes
I base model class implementing IDataErrorInfo interface
public class BaseClass: IDataErrorInfo
{
<Properties and Members of BaseClass>
#region IDataErrorInfo
public string Error
{
get { return String.Empty; }
}
public string this[string PropertyName]
{
get { return this.GetValidationError(PropertyName); }
}
#endregion
}
Now I want drive a class from Base class
public class DrivedClass: BaseClass
{
}
How do I use IDataErrorInfo members in the derived class to carryout validation of the properties in the derived class??
|
|
|
|
|
You can mark them as virtual and override them in the derived class.
|
|
|
|