Wednesday, May 2, 2012

Graphics


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace WindowsFormsApplication1
{
    public partial class graphics : Form
    {
        public graphics()
        {
            InitializeComponent();
        }

        private void graphics_Load(object sender, EventArgs e)
        {

        }

        private void graphics_Paint(object sender, PaintEventArgs e)
        {
            Graphics g;
            g = this.CreateGraphics();
            Pen p = new Pen(Brushes.Purple, 3);
            g.DrawEllipse(p, 100, 100, 100, 100);
            g.FillEllipse(Brushes.Plum, 200, 100, 100, 200);
            g.DrawLine(p, new Point(100, 200), new Point(200, 100));
            Point[] p1 = new Point[5];
            p1[0] = new Point(100, 50);
            p1[1] = new Point(200, 100);
            p1[2] = new Point(250, 100);
            p1[3] = new Point(200, 50);
            p1[4] = new Point(100, 250);
            g.DrawPolygon(p, p1);
            System.Drawing.Font f = new Font("Times New Roman", 15, FontStyle.Bold);
            StringFormat f1 = new StringFormat(StringFormatFlags.NoClip);
            StringFormat f2 = new StringFormat(f1);
            f1.LineAlignment = StringAlignment.Center;
            f2.FormatFlags = StringFormatFlags.DirectionVertical;
            f2.Alignment = StringAlignment.Far;
            Rectangle r=new Rectangle(100,100,100,100);
            g.DrawRectangle(Pens.Brown, r);
            g.DrawString("Hello world", f, Brushes.Red, r.X, r.Y, f1);
            g.DrawString("Hai", f, Brushes.SlateBlue, r.Left, r.Top, f2);




        }
    }
}

Windows management Instrumentation


WMI is a set of extensions to the windows drives model that provides an opertaing system interface through which instrumental components provide information and notification.Microsoft also provides a command line interface to WMI called Windows Management Instrumentation Command Line(WMIC)
Win32-Operating System
            CSName,Caption,Windows directory,serialno,registered user,no of processes
Win32-Bios
Version,name,manufacturer,serialnumber,release date,current language,primary bios,status
            Win32-ComputerSystem
                        Manufacturer,username,totalphysicalmemory,system type,model
            Win32-Processor
                        Caption,Current Clock Speed
            Win32-TimeZone
                        Caption
            Win32-CDROMDrive
                        Caption,mediatype,drive,manufacturer,description
            Win32-Account
                        Name,description,domain,sid
            Win32-DiskDrive
                        Caption,deviceid,index,partitions


            using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;

namespace WindowsFormsApplication1
{
    public partial class WMI : Form
    {
        public WMI()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SelectQuery query = new SelectQuery("Win32OperatingSystem");
            ManagementObjectSearcher search = new ManagementObjectSearcher(query);
            foreach (ManagementObject mobj in search.Get())
            {
                MessageBox.Show(mobj["CSname"].ToString());
            }

        }

        private void WMI_Load(object sender, EventArgs e)
        {

        }
    }
}

COM in c#


Com: =Microsoft Shell Controls and Automation
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Shell32;

namespace WindowsFormsApplication1
{
    public partial class com : Form
    {
        public com()
        {
            InitializeComponent();
        }

        private void com_Load(object sender, EventArgs e)
        {

        }
        ShellClass sc = new ShellClass();
        private void button1_Click(object sender, EventArgs e)
        {
            sc.ShutdownWindows();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            sc.RefreshMenu();

        }


        private void button4_Click(object sender, EventArgs e)
        {
            sc.SetTime();
          

        }

        private void button5_Click(object sender, EventArgs e)
        {
            sc.FindComputer();
            sc.FindFiles();
            sc.FileRun();
            sc.Help();
            sc.MinimizeAll();
            sc.ControlPanelItem("C://");
            sc.EjectPC();
            sc.GetHashCode();
            sc.Windows();
            sc.Suspend();
            sc.UndoMinimizeALL();
            sc.TrayProperties();

        }
    }
}

Calculator with Stack


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class calc : Form
    {
        public calc()
        {
            InitializeComponent();
        }
        Stack<int> st = new Stack<int>();

        private void button1_Click(object sender, EventArgs e)
        {
            string[] ar = new string[100];
            string fg = textBox1.Text;
            ar = fg.Split('+');
            int total = 0;
            for (int i = 0; i < ar.Length; i++)
            {
                st.Push(Convert.ToInt32(ar[i].ToString()));
                listBox1.Items.Add(ar[i].ToString());
            }
            MessageBox.Show(st.Count.ToString());
            for (int i = st.Count; i > 0; i--)
            {
                int s = st.Pop();
                total = total + s;
            }
            MessageBox.Show(Convert.ToString(total));

        }
    }
}

Queue(Enqueue and Dequeue)


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class queue : Form
    {
        public queue()
        {
            InitializeComponent();
        }
        Queue<string> qu = new Queue<string>();

        private void btnen_Click(object sender, EventArgs e)
        {
            qu.Enqueue(textBox1.Text);
            listBox1.Items.Add(textBox1.Text);
            textBox1.Text = "";
        }

        private void btnde_Click(object sender, EventArgs e)
        {
            listBox1.Items.RemoveAt(0);
            listBox1.Refresh();
        }
    }
}

Stack(Push and Pop)


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class stack : Form
    {
        public stack()
        {
            InitializeComponent();
        }
        Stack<int> st = new Stack<int>();

        private void btnpush_Click(object sender, EventArgs e)
        {
            st.Push(Convert.ToInt32(textBox1.Text));
            listBox1.Items.Add(textBox1.Text);
            textBox1.Text = "";

        }

        private void btnpop_Click(object sender, EventArgs e)
        {
            int i = st.Pop();
            MessageBox.Show(i + "is poped");
            int k = st.Count;
            listBox1.Items.RemoveAt(k);
            listBox1.Refresh();

        }
    }
}

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...