Migracja z console na windows form

0

Hej, mam problem. Pomoże ktoś przerobić kod z konsolowej wersji na windows form ?

     using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System;
    using System.Net;
    using System.IO;
class MiniCrawler
{
    // Find a link in a content string.
    static string FindLink(string htmlstr,
    ref int startloc)
    {
        int i;
        int start, end;
        string uri = null;
        string lowcasestr = htmlstr.ToLower();
        i = lowcasestr.IndexOf("href=\"http", startloc);
        if (i != -1)
        {
            start = htmlstr.IndexOf('"', i) + 1;
            end = htmlstr.IndexOf('"', start);
            uri = htmlstr.Substring(start, end - start);
            startloc = end;
        }
        return uri;
    }
    static void Main(string[] args)
    {
        string link = null;
        string str;

        int curloc; // holds current location in response
   
        string uristr; // holds current URI
        Console.WriteLine("Please enter a URI:");

        uristr = Console.ReadLine();

      
        
            try
            {
                
                    do
                    {
                        Console.WriteLine("Linking to " + uristr);
                        // Create a WebRequest to the specified URI.
                        HttpWebRequest req = (HttpWebRequest)
                        WebRequest.Create(uristr);
                        uristr = null; // disallow further use of this URI
                        // Send that request and return the response.
                        HttpWebResponse resp = (HttpWebResponse)
                        req.GetResponse();
                        // From the response, obtain an input stream.
                        Stream istrm = resp.GetResponseStream();
                        // Wrap the input stream in a StreamReader.
                        StreamReader rdr = new StreamReader(istrm);
                        // Read in the entire page.
                        str = rdr.ReadToEnd();
                        curloc = 0;

                        do
                        {
                            // Find the next URI to link to.
                            link = FindLink(str, ref curloc);
                            if (link != null)
                            {
                                Console.WriteLine("Link found: " + link);
                            }
                            else if (link == null)
                            {
                                Console.ReadLine();
                            }
                            else
                            {
                                Console.WriteLine("Nie znaleziono");
                            }


                        } while (link.Length > 0);
                        // Close the response.

                        resp.Close();

                    }


                    while (uristr != null);

                
            }


            catch (WebException exc)
            {
                Console.WriteLine("Network Error: " + exc.Message +
                "\nStatus code: " + exc.Status);
            }
            catch (ProtocolViolationException exc)
            {
                Console.WriteLine("Protocol Error: " + exc.Message);
            }
            catch (UriFormatException exc)
            {
                Console.WriteLine("URI Format Error: " + exc.Message);
            }
            catch (NotSupportedException exc)
            {
                Console.WriteLine("Unknown Protocol: " + exc.Message);
            }
            catch (IOException exc)
            {
                Console.WriteLine("I/O Error: " + exc.Message);
            }
            Console.WriteLine("Terminating MiniCrawler.");
            Console.ReadLine();
        }
    }

0

ale w czym jest problem?

zmień nazwę metody z Main na cośTamInnego, wywal wszystkie Console.ReadLine i Console.WriteLine — zastanów się jak inaczej pobrać dane wejściowe i jak zwrócić wynik…

1 użytkowników online, w tym zalogowanych: 0, gości: 1