Portfolio

Sunday, September 27, 2015

How to Shutdown and Restart your Computer Using C#?






Making an application to shutdown your computer was fairly easy to my surprise. 
Here's the source code





How To Shutdown and Restart Your Computer Using C#



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.Diagnostics;

namespace ShutdownAp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("Shutdown", "/s /t 0");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("Restart", "/r /t 0");
        }
    }
}

How to Connect to a Web Page Using C#























This is another update on how to connect to a web page using Visual Studio C#.
It's a very simple Windows form application using a few lines of code. 

Here's what you need to do:

  • Start new project in Visual Studio
  • Select Windows Form Application
  • Rename as Web Form Page
 


Next drag and drop a form, 3 labels, and 3 buttons just like use see in my project
Then in the main code screen type in source code
I added the logos to make it look more awesome.  Have fun!

Source 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;

namespace WinWebForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://www.google.com");

        }

        private void button3_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://www.bing.com/");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("www.youtube.com");
        }
    }
}