Saturday, 2 April 2016

c# form control






contextmenustrip setup
right click on textbox

tooltip
hover on right side of textbox

helpprovider
click textbox3 -> press F1

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 control
{
    public partial class Form1 : Form
    {
        Random r = new Random();

        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Button x = new Button();
            x.Location = new Point(100, 200);
            x.Text = "hit me";
            x.Click += new System.EventHandler(mystuff);
            this.Controls.Add(x);

            timer1.Enabled = true;
            error.Text = "found";
            errorProvider1.SetError(textBox2, "bad name");
        }

        private void mystuff(object sender, EventArgs e)
        {
            MessageBox.Show("hi");

            errorProvider1.Clear();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;

            MessageBox.Show("you got me");
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //button3.Location = new Point(r.Next(1, 200), r.Next(1, 200));
            textBox1.Text = DateTime.Now.ToLongTimeString();
        }

        private void error_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            error.Enabled = true;
            addup1.box1 = "888";
        }

        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("copy pressed");
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("paste pressed");
        }

        private void dclock1_Load(object sender, EventArgs e)
        {

        }

       

        private void button4_Click(object sender, EventArgs e)
        {
            string s = addup1.addtotal;
            MessageBox.Show(s);
        }

        private void addup1_Load(object sender, EventArgs e)
        {

        }
    }
}

---------------------------------------------------------------------------------------

make windows form control library
run created form to generate .dll file 


right click on general in toolbox in windows form application, select choose.
when loading finished, click browse
select .dll file in library file location
drag the new tool from toolbox to windows form

dclock windows form library

dclock windows form library, shown on windows form app
clock color, types are created with [description]


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

namespace dclock
{
    public enum clock_type { longtime, shorttime };

    public partial class dclock: UserControl
    {
        private clock_type timetype = clock_type.longtime;
        [Description("choose a clock type")]
        public clock_type types
        {
            get { return timetype; }
            set { timetype = value; }
        }

        private Color time_color = Color.Gray;
        [Description("clock color")]
        public Color clock_color
        {
            get { return time_color; }
            set { time_color = value; textBox1.BackColor = value; }
        }

        public dclock()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (timetype == clock_type.longtime)
            {
                textBox1.Text = DateTime.Now.ToLongTimeString();
            }
            else
            {
                textBox1.Text = DateTime.Now.ToShortTimeString();
            }
            textBox1.Text = DateTime.Now.ToLongTimeString();
        }
    }
}

----------------------------------------------------------------------------------

addon windows form library

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

namespace addon
{
    public partial class addup: UserControl
    {
        public addup()
        {
            InitializeComponent();
        }

        private void addon_Load(object sender, EventArgs e)
        {
            number1.Text = "0";
            number2.Text = "0";
        }

        public string addtotal
        {
            get { return total.Text; }
        }

        public string box1
        {
            set { number1.Text = value; }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double x, y, z;
            x = Convert.ToDouble(number1.Text);
            y = Convert.ToDouble(number2.Text);
            z = x + y;
            total.Text = z.ToString();
        }

        private void number1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

No comments:

Post a Comment