|
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.
|
|
|
|
|
Okay, declaring arrays is fairly simple… Just like declaring any other variable with the exception of the square brackets.
Initializing one-dimensional arrays also seems fairly simple enough… Initializing two-dimensional arrays is a bit more complicated but still semi-sort of simple if you pay attention to what you're doing.
Jagged arrays, like two-dimensional arrays… Can be a little tricky if you're not paying attention.
I get and understand the declaration and initialization of the jagged arrays, and that you can change the value of any element by re-declaring your array variable…
I'll use the example from the book I'm reading:
(never mind some of the missing closing curly brackets, before I add any more code I want to understand and learn this part first)
using System;
class JaggedClass
{
static void Main ()
{
int[][] myJaggedArray = { new int[] {2, 3, 4}, new int[] {5, 6, 7, 8, 9} };
myJaggedArray[0][0] = 11;
myJaggedArray[1][2] = 22;
Okay, you old pros… Here is the drill/exercise I was supposed to work on:
Drill 4-3
Display the contents of the two-dimensional array called “grades”
that was discussed in this section. Make sure you get the following
result:
Grade=Pass Score=55%
Grade=Good Score=65%
Grade=VeryGood Score=75%
Grade=Distinct Score=85%
The book was showing us three different ways to declare and initialize a two-dimensional arrays.
This is the first way it showed us:
string[,] grades = new string[2, 4] { {"Pass"," Good", "VeryGood", "Distinct"}, {"55%", "65%", "75%", "85%"} };
this is the second way:
string[,] grades = new string[,] { {"Pass", "Good", "VeryGood", "Distinct"}, {"55%", "65%", "75%", "85%"} };
third and final way:
string [,] grades = { {"Pass", "Good", "VeryGood", "Distinct"}, {"55%", "65%", "75%", "85%"} };
I know I probably could have achieved the same result with a "for loop, or a for each loop, maybe even the while loop", but… I couldn't quite figure it out, I beat my head against the wall for almost half an hour trying to figure the loop out… So, I went a different route… The long and hard way…
It took me about 15 min., maybe even 20 min. to even figure that out… My ah-ha moment came when I accidentally printed to the screen the word "Good"… Don't laugh… I said don't laugh at!
I wrote it and I achieved the way it looks in the book, you'll have to compile it in debug it yourself to see what it looks like… I haven't figured out how to format things here in the forum yet.
using System;
using System.Text;
namespace Two_Dimensional_Array
{
class Program
{
static void Main(string[] args)
{
string[,] grades = { { "Pass", "Good", "VeryGood", "Distinct" }, { "55%", "65%", "75%", "85%" } };
string[] gradeScore = {"Grade=", "Score="};
Console.WriteLine(gradeScore[0] + grades[0, 0] + " " + gradeScore[1] + grades[1, 0]);
Console.WriteLine(gradeScore[0] + grades[0, 1] + " " + gradeScore[1] + grades[1, 1]);
Console.WriteLine(gradeScore[0] + grades[0, 2] + " " + gradeScore[1] + grades[1, 2]);
Console.WriteLine(gradeScore[0] + grades[0, 3] + " " + gradeScore[1] + grades[1, 3]);
Console.Read();
}
}
}
modified 22-May-13 21:06pm.
|
|
|
|
|
WidmarkRob wrote: myJaggedArray[0][0] = 11; myJaggedArray[1][2] = 22;
Not quite. A jagged array is essentially an array of arrays. In your sample code, the myJaggedArray variable is an array containing two elements: an array of three integers, and an array of five integers.
myJaggedArray[0] returns the first element, so myJaggedArray[0][0] = 11 is updating the first element of the array stored in the first element of myJaggedArray , and myJaggedArray[1][2] = 22 is updating the third element of the array stored in the second element of myJaggedArray .
http://msdn.microsoft.com/en-us/library/2s05feca.aspx[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
WidmarkRob wrote: the first set of brackets closest to the variable is telling me to access the first element in the jagged array? Then the set of brackets furthest away from the variable is telling me to access the first element, inside of the first element of the jagged array?
Yes, that's correct.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In addition to Richard Deeming's comments, a 2 dimensional array is just like a square (or oblong) containing N rows, and M columns. So element[0][0] is row 0, column 0, and element[1][2] is row 1 column 2. Try the following for a better illustration:
int[][] myJaggedArray = { new int[] { 2, 3, 4 }, new int[] { 5, 6, 7, 8, 9 } };
for (int N = 0; N < myJaggedArray.GetLength(0); ++N)
{
for (int M = 0; M < myJaggedArray[N].GetLength(0); ++M)
{
Console.WriteLine("element[{0}, {1}] = {2}", N, M, myJaggedArray[N][M]);
}
}
Use the best guess
|
|
|
|
|