Witam, uczę się programowania obiektowego w C# juz ze 2-3 miesiące. Zrobilem prostą przeglądarkę stron internetowych, która oprócz zapisywania zakladek, dodawania nowych kart, posiada również funkcje szybkiego szukania i timer. Proszę o ocenę. Link do prezentacji jest tutaj: https://youtu.be/sCJ3dKEL054
Kod:
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.Timers;
using System.IO;
namespace Przeglądarka
{
public partial class Form1 : Form
{
public int timer_int = 0;
public int timer_int1 = 0;
public int timer_int2 = 0;
public int click_count = 0;
public int timer3 = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label1.BringToFront();
string path_button = Environment.CurrentDirectory + "/" + "button_settings";
INIFile button_settings = new INIFile(path_button);
if (button_settings.Read("Button1","Text").Length >0)
{
string button1 = button_settings.Read("Button1", "Text");
string button2 = button_settings.Read("Button2", "Text");
string button3 = button_settings.Read("Button3", "Text");
string button4 = button_settings.Read("Button4", "Text");
string button5 = button_settings.Read("Button5", "Text");
string locationX1 = button_settings.Read("Location1", "LocX");
string locationY1 = button_settings.Read("Location1", "LocY");
int locX1 = int.Parse(locationX1);
int locY1 = int.Parse(locationY1);
string locationX2 = button_settings.Read("Location2", "LocX");
string locationY2 = button_settings.Read("Location2", "LocY");
int locX2 = int.Parse(locationX2);
int locY2 = int.Parse(locationY2);
string locationX3 = button_settings.Read("Location3", "LocX");
string locationY3 = button_settings.Read("Location3", "LocY");
int locX3 = int.Parse(locationX3);
int locY3 = int.Parse(locationY3);
string locationX4 = button_settings.Read("Location4", "LocX");
string locationY4 = button_settings.Read("Location4", "LocY");
int locX4 = int.Parse(locationX4);
int locY4 = int.Parse(locationY4);
string locationX5 = button_settings.Read("Location5", "LocX");
string locationY5 = button_settings.Read("Location5", "LocY");
int locX5 = int.Parse(locationX5);
int locY5 = int.Parse(locationY5);
for (int i = 0; i <= 5; i++)
{
add_bookmark.Location = new Point(locX1, locY1);
add_bookmark1.Location = new Point(locX2, locY2);
add_bookmark2.Location = new Point(locX3, locY3);
add_bookmark3.Location = new Point(locX4, locY4);
add_bookmark4.Location = new Point(locX5, locY5);
add_bookmark.Text = button1;
add_bookmark1.Text = button2;
add_bookmark2.Text = button3;
add_bookmark3.Text = button4;
add_bookmark4.Text = button5;
}
Controls.Add(add_bookmark);
Controls.Add(add_bookmark1);
Controls.Add(add_bookmark2);
Controls.Add(add_bookmark3);
Controls.Add(add_bookmark4);
}
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 1000;
timer.Elapsed += OnTimedEvent;
timer.Enabled = true;
}
private void OnTimedEvent(object sender,ElapsedEventArgs e)
{
timer_int++;
label1.Text =timer_int2.ToString()+":"+timer_int1.ToString() + ":" + timer_int.ToString();
if (timer_int==59)
{
timer_int = 0;
timer_int1++;
}
if(timer_int1 ==59 && timer_int==59)
{
timer_int1 = 0;
timer_int2++;
}
}
private void add_bookmark_Click(object sender, EventArgs e)
{
string path_button = Environment.CurrentDirectory + "/" + "URL_settings";
INIFile web_settings = new INIFile(path_button);
string web = web_settings.Read("URL1", "Text");
webBrowser1.Url = new System.Uri(web, System.UriKind.Absolute);
}
private void add_bookmark1_Click(object sender, EventArgs e)
{
string path_button = Environment.CurrentDirectory + "/" + "URL_settings";
INIFile web_settings = new INIFile(path_button);
string web = web_settings.Read("URL2", "Text");
webBrowser1.Url = new System.Uri(web, System.UriKind.Absolute);
}
private void add_bookmark2_Click(object sender, EventArgs e)
{
string path_button = Environment.CurrentDirectory + "/" + "URL_settings";
INIFile web_settings = new INIFile(path_button);
string web = web_settings.Read("URL3", "Text");
webBrowser1.Url = new System.Uri(web, System.UriKind.Absolute);
}
private void add_bookmark3_Click(object sender, EventArgs e)
{
string path_button = Environment.CurrentDirectory + "/" + "URL_settings";
INIFile web_settings = new INIFile(path_button);
string web = web_settings.Read("URL4", "Text");
webBrowser1.Url = new System.Uri(web, System.UriKind.Absolute);
}
private void add_bookmark4_Click(object sender, EventArgs e)
{
string path_button = Environment.CurrentDirectory + "/" + "URL_settings";
INIFile web_settings = new INIFile(path_button);
string web = web_settings.Read("URL5", "Text");
webBrowser1.Url = new System.Uri(web, System.UriKind.Absolute);
}
private void button_undo_Click(object sender, EventArgs e)
{
WebBrowser web = tabControl1.SelectedTab.Controls[0] as WebBrowser;
if(web != null)
{
if(web.CanGoBack)
{
web.GoBack();
}
}
}
private void button_redo_Click(object sender, EventArgs e)
{
WebBrowser web = tabControl1.SelectedTab.Controls[0] as WebBrowser;
if (web != null)
{
if (web.CanGoForward)
{
web.GoForward();
}
}
}
private void addToolStripMenuItem1_Click(object sender, EventArgs e)
{
click_count++;
string path_URL = Environment.CurrentDirectory + "/" + "URL_settings";
string path_button = Environment.CurrentDirectory + "/" + "button_settings";
INIFile web_settings = new INIFile(path_URL);
INIFile button_settings = new INIFile(path_button);
switch (click_count)
{
case 1:
add_bookmark.Text = toolStripTextBox1.Text;
web_settings.Write("URL" + click_count.ToString(), "Text", toolStripTextBox2.Text);
button_settings.Write("Button" + click_count.ToString(), "Text", toolStripTextBox1.Text);
button_settings.Write("Location" + click_count.ToString(), "LocX", add_bookmark.Location.X.ToString());
button_settings.Write("Location" + click_count.ToString(), "LocY", add_bookmark.Location.Y.ToString());
Controls.Add(add_bookmark);
toolStripTextBox1.Text = "";
break;
case 2:
add_bookmark1.Location = new Point(add_bookmark.Location.X + add_bookmark.Width+3 , 23);
add_bookmark1.Text = toolStripTextBox1.Text;
web_settings.Write("URL" + click_count.ToString(), "Text", toolStripTextBox2.Text);
button_settings.Write("Button" + click_count.ToString(), "Text", toolStripTextBox1.Text);
button_settings.Write("Location" + click_count.ToString(), "LocX", add_bookmark1.Location.X.ToString());
button_settings.Write("Location" + click_count.ToString(), "LocY", add_bookmark1.Location.Y.ToString());
Controls.Add(add_bookmark1);
toolStripTextBox1.Text = "";
break;
case 3:
add_bookmark2.Location = new Point(add_bookmark1.Location.X+add_bookmark1.Width + 3, 23);
add_bookmark2.Text = toolStripTextBox1.Text;
web_settings.Write("URL" + click_count.ToString(), "Text", toolStripTextBox2.Text);
button_settings.Write("Button" + click_count.ToString(), "Text", toolStripTextBox1.Text);
button_settings.Write("Location" + click_count.ToString(), "LocX", add_bookmark2.Location.X.ToString());
button_settings.Write("Location" + click_count.ToString(), "LocY", add_bookmark2.Location.Y.ToString());
Controls.Add(add_bookmark2);
toolStripTextBox1.Text = "";
break;
case 4:
add_bookmark3.Location = new Point(add_bookmark2.Location.X+ add_bookmark2.Width + 3, 23);
add_bookmark3.Text = toolStripTextBox1.Text;
web_settings.Write("URL" + click_count.ToString(), "Text", toolStripTextBox2.Text);
button_settings.Write("Button" + click_count.ToString(), "Text", toolStripTextBox1.Text);
button_settings.Write("Location" + click_count.ToString(), "LocX", add_bookmark3.Location.X.ToString());
button_settings.Write("Location" + click_count.ToString(), "LocY", add_bookmark3.Location.Y.ToString());
Controls.Add(add_bookmark3);
toolStripTextBox1.Text = "";
break;
case 5:
add_bookmark4.Location = new Point(add_bookmark3.Location.X + add_bookmark3.Width + 3,23);
add_bookmark4.Text =toolStripTextBox1.Text;
web_settings.Write("URL" + click_count.ToString(), "Text", toolStripTextBox2.Text);
button_settings.Write("Button" + click_count.ToString(), "Text", toolStripTextBox1.Text);
button_settings.Write("Location" + click_count.ToString(), "LocX", add_bookmark4.Location.X.ToString());
button_settings.Write("Location" + click_count.ToString(), "LocY", add_bookmark4.Location.Y.ToString());
Controls.Add(add_bookmark4);
toolStripTextBox1.Text = "";
break;
}
}
private void addToolStripMenuItem_Click(object sender, EventArgs e)
{
toolStripTextBox2.Text = webBrowser1.Url.ToString();
}
private void Google_Click(object sender, EventArgs e)
{
string web = fast_serch_box.Text;
this.webBrowser1.Url = new System.Uri("https://en.wikipedia.org/wiki/"+web, System.UriKind.Absolute);
}
private void YouTube_Click(object sender, EventArgs e)
{
string web = fast_serch_box.Text;
this.webBrowser1.Url = new System.Uri("https://www.youtube.com/" + web, System.UriKind.Absolute);
}
private void button1_Click(object sender, EventArgs e)
{
string web = fast_serch_box.Text;
webBrowser1.Navigate("https://www.google.pl/maps/place/"+web);
}
private void button2_Click(object sender, EventArgs e)
{
string web = fast_serch_box.Text;
webBrowser1.Navigate("https://www.bing.com/search?q=" + web);
}
private void addPageToolStripMenuItem_Click(object sender, EventArgs e)
{
TabPage tab = new TabPage();
tab.Text = "new";
tabControl1.Controls.Add(tab);
tabControl1.SelectTab(tabControl1.TabCount - 1);
webBrowser1 = new WebBrowser { ScriptErrorsSuppressed = true };
webBrowser1.Parent = tab;
webBrowser1.Dock = DockStyle.Fill;
webBrowser1.Navigate("https://www.google.com");
}
private void button3_Click(object sender, EventArgs e)
{
string web = fast_serch_box.Text;
webBrowser1.Navigate("https://www.google.com/search?q=" + web);
}
private void button4_Click(object sender, EventArgs e)
{
string web = fast_serch_box.Text;
webBrowser1.Navigate("https://www.youtube.com/search?q=" + web);
}
private void setToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Timers.Timer timer2 = new System.Timers.Timer();
timer2.Interval = 1000;
timer2.Elapsed += OnTimedEvent2;
timer2.Enabled = true;
}
private void OnTimedEvent2(object sender,ElapsedEventArgs e )
{
timer3++;
string t = toolStripTextBox3.Text;
int time = int.Parse(t);
if (time == timer3)
{
Close();
}
}
private void deleteBookmarksToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void deleteBookmarksToolStripMenuItem_Click_1(object sender, EventArgs e)
{
string path_button = Environment.CurrentDirectory + "/" + "button_settings";
INIFile button_settings = new INIFile(path_button);
File.WriteAllText(path_button, "");
add_bookmark.Hide();
add_bookmark1.Hide();
add_bookmark2.Hide();
add_bookmark3.Hide();
add_bookmark4.Hide();
}
}
}