Hi guys,
I am beginner in MS VC++. I have a 2D array (10 rows and 4 columns) like :
x1 y1 x2 y2
------------
1 1 3 4
2 3 2 5
. . . .
. . . .
3 2 1 4
I want to use the windows form application and draw all the lines for each row of my array which connect x1,y1 to x2,y2
How can I do this ?
Last edited on
Like this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
#define ROW 10
#define COLUMN 4
int main ()
{
int ten4 [ROW][COLUMN];
int x1, y1, x2, y2, a, b, c, d;
//fill array with ZERO's
for (a = 0; a < ROW; a++)
{
for (b = 0; b < COLUMN; b++)
{
ten4[a][b] = 0;
}
}
std::cout << "First point" <<
std::endl << "X: ";
std::cin >> x1;
std::cout << "Y: ";
std::cin >> y1;
std::cout << "Second point" <<
std::endl << "X: ";
std::cin >> x2;
std::cout << "Y: ";
std::cin >> y2;
c = 0;
d = 0;
if(x1 != x2 && y1 != y2)
{
std::cout << "Not possible yet" << std::endl;
c = 1;
}
if(x1 != x2 && y1 == y2)
{
std::cout << "Not possible yet" << std::endl;
c = 1;
}
if(x1 == x2 && y1 == y2)
{
ten4[y1][x1] = 1;
c = 1;
}
if(c != 1)
{
while(d != 1)
{
for(a = y1; a <= y2; a++)
{
ten4[a][x1] = 1;
}
d = 1;
}
}
//#here
for (a = 0; a < ROW; a++)
{
for (b = 0; b < COLUMN; b++)
{
std::cout << ten4[a][b];
}
std::cout << std::endl;
}
}
|
I helped you here, change the code a little and it propably will work for you. This was using g++
Last edited on
Actually as I said I wanna draw the lines in the windows application form, not in the console ! So, any idea?
There is Windows' GDI LineTo
function:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd145029%28v=vs.85%29.aspx
It is a bit retro, but it works with API programs. I don't have a clue if it would work with the Windows Form framework.
Last edited on