Skip to content

Commit

Permalink
The servers menu has been removed and all servers have been added to …
Browse files Browse the repository at this point in the history
…the main menu.
  • Loading branch information
LordArma committed May 3, 2024
1 parent 0ba5d52 commit 4f048c0
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 79 deletions.
2 changes: 1 addition & 1 deletion DNS on Tray/DNS on Tray.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Version>0.4.0</Version>
<Version>0.5.0</Version>
<RootNamespace>DNS_on_Tray</RootNamespace>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
Expand Down
47 changes: 1 addition & 46 deletions DNS on Tray/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 75 additions & 31 deletions DNS on Tray/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Win32;
using System.Net;
using System.Runtime.InteropServices;
using static DNS_on_Tray.Helper;

Expand Down Expand Up @@ -33,11 +34,6 @@ private void ShowMainWindow()
}
}

private void btnClear_Click(object sender, EventArgs e)
{
ClearDNS();
}

private void SetupFormStartPosition()
{
Rectangle workingArea = Screen.GetWorkingArea(this);
Expand All @@ -47,42 +43,98 @@ private void SetupFormStartPosition()
this.Opacity = 0;
}

private void frmMain_Load(object sender, EventArgs e)
private void MakeMenuItems()
{
SetupFormStartPosition();

EnableAddButton();
notifyMenu.Items.Clear();
lstDNS.Items.Clear();

if (CanRunAsStartup())
{
optStartup.Checked = true;
}
else
{
optStartup.Checked = false;
}
lstDNS.Items.Add("Clear");

ToolStripMenuItem item = new ToolStripMenuItem();

foreach (var dns in DNS.All())
{
lstDNS.Items.Add(dns.Name());

ToolStripMenuItem item = new ToolStripMenuItem();
item = new ToolStripMenuItem();
item.Name = "dns" + Convert.ToString(new Random().Next(1, 99999));
item.Text = dns.Name();
item.Click += new EventHandler(MenuItemClickHandler);

Check warning on line 63 in DNS on Tray/Form1.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'sender' of 'void frmMain.MenuItemClickHandler(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).

btnServers.DropDownItems.Add(item);
notifyMenu.Items.Add(item);

}


notifyMenu.Items.Add("-");

string strMenuItemName = "Clear";
item = new ToolStripMenuItem();
item.Name = strMenuItemName;
item.Text = strMenuItemName;
item.Click += new EventHandler(MenuItemClickHandler);

Check warning on line 76 in DNS on Tray/Form1.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'sender' of 'void frmMain.MenuItemClickHandler(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).
notifyMenu.Items.Add(item);

notifyMenu.Items.Add("-");

strMenuItemName = "Settings";
item = new ToolStripMenuItem();
item.Name = strMenuItemName;
item.Text = strMenuItemName;
item.Click += new EventHandler(MenuItemClickHandler);

Check warning on line 85 in DNS on Tray/Form1.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'sender' of 'void frmMain.MenuItemClickHandler(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).
notifyMenu.Items.Add(item);

notifyMenu.Items.Add("-");

strMenuItemName = "Exit";
item = new ToolStripMenuItem();
item.Name = strMenuItemName;
item.Text = strMenuItemName;
item.Click += new EventHandler(MenuItemClickHandler);

Check warning on line 94 in DNS on Tray/Form1.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'sender' of 'void frmMain.MenuItemClickHandler(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).
notifyMenu.Items.Add(item);
}

private void frmMain_Load(object sender, EventArgs e)
{
SetupFormStartPosition();

EnableAddButton();

if (CanRunAsStartup())
{
optStartup.Checked = true;
}
else
{
optStartup.Checked = false;
}

MakeMenuItems();
}

private void MenuItemClickHandler(object sender, EventArgs e)
{
ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
string dnsName = clickedItem.Text;
DNS dns = new DNS(dnsName);
AddDNS(dns.DNS1(), dns.DNS2());
string strItem = clickedItem.Text;

Check warning on line 119 in DNS on Tray/Form1.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
DNS dns = new DNS(strItem);

if (strItem != "Exit" & strItem != "Settings" & strItem != "Clear")
{
AddDNS(dns.DNS1(), dns.DNS2());
}
else if (strItem.ToString() == "Exit")
{
System.Windows.Forms.Application.Exit();
}
else if (strItem.ToString() == "Settings")
{
ShowMainWindow();
}
else if (strItem.ToString() == "Clear")
{
ClearDNS();
}
}

private void EnableAddButton()
Expand All @@ -109,6 +161,7 @@ private void btnDNSRemove_Click(object sender, EventArgs e)
lstDNS.Items.Remove(strSlelectedItem);
DNS dns = new(strSlelectedItem);
dns.Remove();
MakeMenuItems();
}

}
Expand Down Expand Up @@ -145,6 +198,7 @@ private void btnDNSAdd_Click(object sender, EventArgs e)
dns.Save();

ClearForm();
MakeMenuItems();
}

private void txtDNSName_TextChanged(object sender, EventArgs e)
Expand All @@ -162,16 +216,6 @@ private void txtDNS2_TextChanged(object sender, EventArgs e)
EnableAddButton();
}

private void btnExit_Click(object sender, EventArgs e)
{
System.Windows.Forms.Application.Exit();
}

private void btnSettings_Click(object sender, EventArgs e)
{
ShowMainWindow();
}

private void frmMain_Activated(object sender, EventArgs e)
{
if (!IsAdministrator)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A simple program to easily add, remove or change current DNS of the Windows. Thi
- This program is currently unsigned. You can download its codes or use unsigned releases.

## Screenshot
![Screenshot of DNS on Try program on the system tray.](screenshot.jpg "Screenshot of DNS on Try Program")
![Screenshot of DNS on Try program on the system tray.](screenshot1.jpg "Screenshot of DNS on Try Program") ![Another screenshot of DNS on Try program on the system tray.](screenshot2.jpg "Another screenshot of DNS on Try Program")

## Supported DNS Servers by Default
- Cloudflare
Expand Down
Binary file removed screenshot.jpg
Binary file not shown.
Binary file added screenshot1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4f048c0

Please sign in to comment.