• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

C# Visual Studio Translate to MonoDevelop

Joined
Nov 8, 2013
Messages
12
I have written a program in C# that takes in integers from a text file and displays then on a form_paint as dots, basically what i am doing is a GUI which shows an area with three access points and wireless devices what i want to do is:

1) Translate the code that i have written from Visual Studio to MonoDevelop
2) When i hover my mouse on top of one of those device, i need it to show me details about that device, like:
i. mac address
ii. device name

A general guidance on how i can do this would be very much appreciated thank you :)

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;


namespace WindowsFormsApplication3
{

    public partial class Form1 : Form
    {
        int[] x = new int[12]; //Creating x array with size 12
        int[] y = new int[12]; //Creating y array
        int counter=0;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            
            int counter = 0;
            System.Drawing.Graphics graphicsObj;

            graphicsObj = this.CreateGraphics();

            //Building
            Pen myPen = new Pen(System.Drawing.Color.DarkViolet, 2);
            Rectangle Building = new Rectangle(5, 20, 250, 200);

            //Garden
            Pen myPen_Garden = new Pen(System.Drawing.Color.DarkViolet, 2);
            Rectangle Garden = new Rectangle(45, 210, 250, 200);

            //Green Dot, Access Point 1
            Pen Dot_One = new Pen(System.Drawing.Color.Green, 8);
            Rectangle AccessPnt_One = new Rectangle(20, 50, 5, 5); //Rectangle(x, y, width, height)
            //creates a text next to each access point in order to give it a designated name, ex. its ip address
            //Font myFont = new System.Drawing.Font("Helvetica", 8, FontStyle.Italic);
            //Brush myBrush = new SolidBrush(System.Drawing.Color.Red);
            //graphicsObj.DrawString("IP: 168.192.10.5", myFont, myBrush, 20, 50);
           
            //Red Dot, Access Point 2
            Pen Dot_Two = new Pen(System.Drawing.Color.DarkRed, 8);
            Rectangle AccessPnt_Two = new Rectangle(200, 110, 5, 5);
            //Font myFont2 = new System.Drawing.Font("Helvetica", 8, FontStyle.Italic);
            //Brush myBrush2 = new SolidBrush(System.Drawing.Color.Red);
            //graphicsObj.DrawString("IP: 168.192.10.5", myFont2, myBrush2, 200, 110);
           
            //Blue Dot, Access Point 3
            Pen Dot_Three = new Pen(System.Drawing.Color.DarkSlateBlue, 8);
            Rectangle AccessPnt_Three = new Rectangle(40, 190, 5, 5);
            //Font myFont3 = new System.Drawing.Font("Helvetica", 8, FontStyle.Italic);
            //Brush myBrush3 = new SolidBrush(System.Drawing.Color.Red);
            //graphicsObj.DrawString("IP: 168.192.10.5", myFont3, myBrush3, 40, 190);
           
            //Calling ReadFromFile Funtion and sending the two Arrays
            readFromFile();
            
            graphicsObj.DrawEllipse(Dot_One, AccessPnt_One);
            graphicsObj.DrawEllipse(Dot_Two, AccessPnt_Two);
            graphicsObj.DrawEllipse(Dot_Three, AccessPnt_Three);
            graphicsObj.DrawRectangle(myPen, Building);
            graphicsObj.DrawRectangle(myPen_Garden, Garden);
           
        }

        //Function for reading from a file
        void readFromFile()
        {

            int counter = 0;
            string line;

           // Read the file and display it line by line.
            System.IO.StreamReader file = new System.IO.StreamReader(@"C:\Users\pstep_000\Documents\x.txt"); //Creating a variable with type StreamReader

            while (!file.EndOfStream) //while file is not at the end
            { 
                line = file.ReadLine(); //variable line gets a line from the file
                x[counter] = Convert.ToInt32(line); // converting to integet the value of variable line because is of type string. Then save the value to array possition counter 
                counter++; //counter= counter + 1
            }
            file.Close(); //closing the file

            counter = 0;

            // Read the file and display it line by line.
            System.IO.StreamReader file2 = new System.IO.StreamReader(@"C:\Users\pstep_000\Documents\y.txt");

            while (!file2.EndOfStream)
            {
                line = file2.ReadLine();
                y[counter] = Convert.ToInt32(line);
                counter++;
            }

            file2.Close();
 
        }

        void DeviceCreation()
        {
            counter++;
            //file has only 12 values inside. So when counter is 11 that means it is done reading from the file so we stop the timer
            if (counter == 11){
                tmr.Enabled = false;
            }    
            System.Drawing.Graphics graphicsObj;

            graphicsObj = this.CreateGraphics();

            //Device
            Pen Device = new Pen(System.Drawing.Color.Black, 2);
            Rectangle Device_Pnt = new Rectangle(x[counter], y[counter], 5, 5);

            graphicsObj.DrawEllipse(Device, Device_Pnt);
            
        }


        private void tmr_Tick(object sender, EventArgs e)
        {
           
            DeviceCreation();
            
        }
    }
}
 
What happens when you try to run it in Mono? As far as I know, Mono supports forms without issue.

Just some general code guidelines, StreamReader realizes IDisposable, so you should use it in a using block. At the very least, you should use it in a try/catch/finally block to ensure the file is closed:

Code:
using (var file = new System.IO.StreamReader(...))
{
... // no call to Close() needed
}

or like the example here.

I'm not sure how you're generating your x,y coordinates, but it seems they should be in a single file, not in two separate. In fact, you probably want to use a Tuple or similar (KeyValuePair, struct, a data holding class, etc) for your x,y coordinates.

Rather than using a magic number for when the counter is done, you should check the length of x or y. Otherwise, if you want to increase the size of the array in the future, you have to find the magic numbers you used and update them everywhere. In fact, you probably want const ints to define the size, so that you can't have x > y or y > x.

There's more, but that should be enough to get you started.
 
Back
Top