MenuStrip trong lập trình C# Winform

Lập trình Winform cơ bản

4.9 (7 đánh giá)
Tạo bởi HowKteam Cập nhật lần cuối 23:11 03-08-2020 48.892 lượt xem 0 bình luận
Tác giả/Dịch giả: HowKteam
Học nhanh

Danh sách bài học

MenuStrip trong lập trình C# Winform

Dẫn nhập

Sức mạnh của hệ điều hành Window là không thể chối cãi. Và để tạo nên sức mạnh đó không thể thiếu những ứng dụng mạnh mẽ. Vậy để tạo ra những ứng dụng đó, người lập trình viên cần học cái gì?

Cùng nhau tìm hiểu serial Lập trình Winform.

Nội dung

Form1.cs

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 MenuStripGUI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str = mntsCombo.SelectedItem.ToString();
            label1.Text = str;
        }

        private void freeEducationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Đã click vào free education");
        }
    }
}

Form1.Designer.cs

namespace MenuStripGUI
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.howKteamcomToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.k9ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.freeEducationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.shareToBeBetterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.mntsCombo = new System.Windows.Forms.ToolStripComboBox();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.toolStripTextBox1 = new System.Windows.Forms.ToolStripTextBox();
            this.kjhToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.iyoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.dasdasToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.dasdaToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.adasdToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.asdasdToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.menuStrip2 = new System.Windows.Forms.MenuStrip();
            this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem5 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem6 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem7 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem8 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem9 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem10 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox();
            this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
            this.toolStripTextBox2 = new System.Windows.Forms.ToolStripTextBox();
            this.menuStrip1.SuspendLayout();
            this.menuStrip2.SuspendLayout();
            this.SuspendLayout();
            // 
            // menuStrip1
            // 
            this.menuStrip1.Dock = System.Windows.Forms.DockStyle.None;
            this.menuStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Visible;
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.k9ToolStripMenuItem,
            this.howKteamcomToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(232, 156);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(158, 101);
            this.menuStrip1.TabIndex = 0;
            this.menuStrip1.Text = "menuStrip1";
            this.menuStrip1.TextDirection = System.Windows.Forms.ToolStripTextDirection.Vertical90;
            // 
            // howKteamcomToolStripMenuItem
            // 
            this.howKteamcomToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.freeEducationToolStripMenuItem,
            this.shareToBeBetterToolStripMenuItem,
            this.mntsCombo,
            this.toolStripSeparator1,
            this.toolStripTextBox1});
            this.howKteamcomToolStripMenuItem.Name = "howKteamcomToolStripMenuItem";
            this.howKteamcomToolStripMenuItem.Size = new System.Drawing.Size(27, 97);
            this.howKteamcomToolStripMenuItem.Text = "HowKteam.com";
            this.howKteamcomToolStripMenuItem.TextDirection = System.Windows.Forms.ToolStripTextDirection.Vertical90;
            // 
            // k9ToolStripMenuItem
            // 
            this.k9ToolStripMenuItem.MergeIndex = 0;
            this.k9ToolStripMenuItem.Name = "k9ToolStripMenuItem";
            this.k9ToolStripMenuItem.Size = new System.Drawing.Size(27, 97);
            this.k9ToolStripMenuItem.Text = "K9";
            this.k9ToolStripMenuItem.TextDirection = System.Windows.Forms.ToolStripTextDirection.Vertical90;
            // 
            // freeEducationToolStripMenuItem
            // 
            this.freeEducationToolStripMenuItem.CheckOnClick = true;
            this.freeEducationToolStripMenuItem.Image = global::MenuStripGUI.Properties.Resources.Kteam_vector_copy_2;
            this.freeEducationToolStripMenuItem.Name = "freeEducationToolStripMenuItem";
            this.freeEducationToolStripMenuItem.ShortcutKeyDisplayString = "";
            this.freeEducationToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.K)));
            this.freeEducationToolStripMenuItem.Size = new System.Drawing.Size(193, 22);
            this.freeEducationToolStripMenuItem.Text = "Free education";
            this.freeEducationToolStripMenuItem.Click += new System.EventHandler(this.freeEducationToolStripMenuItem_Click);
            // 
            // shareToBeBetterToolStripMenuItem
            // 
            this.shareToBeBetterToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.kjhToolStripMenuItem,
            this.iyoToolStripMenuItem});
            this.shareToBeBetterToolStripMenuItem.Name = "shareToBeBetterToolStripMenuItem";
            this.shareToBeBetterToolStripMenuItem.Size = new System.Drawing.Size(181, 22);
            this.shareToBeBetterToolStripMenuItem.Text = "Share to be better";
            // 
            // mntsCombo
            // 
            this.mntsCombo.Items.AddRange(new object[] {
            "1",
            "2",
            "3",
            "4"});
            this.mntsCombo.Name = "mntsCombo";
            this.mntsCombo.Size = new System.Drawing.Size(121, 23);
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(178, 6);
            // 
            // toolStripTextBox1
            // 
            this.toolStripTextBox1.Name = "toolStripTextBox1";
            this.toolStripTextBox1.Size = new System.Drawing.Size(100, 23);
            // 
            // kjhToolStripMenuItem
            // 
            this.kjhToolStripMenuItem.Name = "kjhToolStripMenuItem";
            this.kjhToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.kjhToolStripMenuItem.Text = "kjh";
            // 
            // iyoToolStripMenuItem
            // 
            this.iyoToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.dasdasToolStripMenuItem});
            this.iyoToolStripMenuItem.Name = "iyoToolStripMenuItem";
            this.iyoToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.iyoToolStripMenuItem.Text = "iyo";
            // 
            // dasdasToolStripMenuItem
            // 
            this.dasdasToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.dasdaToolStripMenuItem});
            this.dasdasToolStripMenuItem.Name = "dasdasToolStripMenuItem";
            this.dasdasToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.dasdasToolStripMenuItem.Text = "dasdas";
            // 
            // dasdaToolStripMenuItem
            // 
            this.dasdaToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.adasdToolStripMenuItem});
            this.dasdaToolStripMenuItem.Name = "dasdaToolStripMenuItem";
            this.dasdaToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.dasdaToolStripMenuItem.Text = "dasda";
            // 
            // adasdToolStripMenuItem
            // 
            this.adasdToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.asdasdToolStripMenuItem});
            this.adasdToolStripMenuItem.Name = "adasdToolStripMenuItem";
            this.adasdToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.adasdToolStripMenuItem.Text = "adasd";
            // 
            // asdasdToolStripMenuItem
            // 
            this.asdasdToolStripMenuItem.Name = "asdasdToolStripMenuItem";
            this.asdasdToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            this.asdasdToolStripMenuItem.Text = "asdasd";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(222, 92);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(91, 102);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 13);
            this.label1.TabIndex = 2;
            this.label1.Text = "label1";
            // 
            // menuStrip2
            // 
            this.menuStrip2.Dock = System.Windows.Forms.DockStyle.None;
            this.menuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripMenuItem1,
            this.toolStripMenuItem2});
            this.menuStrip2.Location = new System.Drawing.Point(35, 235);
            this.menuStrip2.Name = "menuStrip2";
            this.menuStrip2.Size = new System.Drawing.Size(62, 101);
            this.menuStrip2.TabIndex = 3;
            this.menuStrip2.Text = "menuStrip2";
            // 
            // toolStripMenuItem1
            // 
            this.toolStripMenuItem1.MergeIndex = 0;
            this.toolStripMenuItem1.Name = "toolStripMenuItem1";
            this.toolStripMenuItem1.Size = new System.Drawing.Size(27, 97);
            this.toolStripMenuItem1.Text = "K9";
            this.toolStripMenuItem1.TextDirection = System.Windows.Forms.ToolStripTextDirection.Vertical90;
            // 
            // toolStripMenuItem2
            // 
            this.toolStripMenuItem2.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripMenuItem3,
            this.toolStripMenuItem4,
            this.toolStripComboBox1,
            this.toolStripSeparator2,
            this.toolStripTextBox2});
            this.toolStripMenuItem2.Name = "toolStripMenuItem2";
            this.toolStripMenuItem2.Size = new System.Drawing.Size(27, 97);
            this.toolStripMenuItem2.Text = "HowKteam.com";
            this.toolStripMenuItem2.TextDirection = System.Windows.Forms.ToolStripTextDirection.Vertical90;
            // 
            // toolStripMenuItem3
            // 
            this.toolStripMenuItem3.CheckOnClick = true;
            this.toolStripMenuItem3.Image = global::MenuStripGUI.Properties.Resources.Kteam_vector_copy_2;
            this.toolStripMenuItem3.Name = "toolStripMenuItem3";
            this.toolStripMenuItem3.ShortcutKeyDisplayString = "";
            this.toolStripMenuItem3.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.K)));
            this.toolStripMenuItem3.Size = new System.Drawing.Size(193, 22);
            this.toolStripMenuItem3.Text = "Free education";
            // 
            // toolStripMenuItem4
            // 
            this.toolStripMenuItem4.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripMenuItem5,
            this.toolStripMenuItem6});
            this.toolStripMenuItem4.Name = "toolStripMenuItem4";
            this.toolStripMenuItem4.Size = new System.Drawing.Size(193, 22);
            this.toolStripMenuItem4.Text = "Share to be better";
            // 
            // toolStripMenuItem5
            // 
            this.toolStripMenuItem5.Name = "toolStripMenuItem5";
            this.toolStripMenuItem5.Size = new System.Drawing.Size(90, 22);
            this.toolStripMenuItem5.Text = "kjh";
            // 
            // toolStripMenuItem6
            // 
            this.toolStripMenuItem6.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripMenuItem7});
            this.toolStripMenuItem6.Name = "toolStripMenuItem6";
            this.toolStripMenuItem6.Size = new System.Drawing.Size(90, 22);
            this.toolStripMenuItem6.Text = "iyo";
            // 
            // toolStripMenuItem7
            // 
            this.toolStripMenuItem7.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripMenuItem8});
            this.toolStripMenuItem7.Name = "toolStripMenuItem7";
            this.toolStripMenuItem7.Size = new System.Drawing.Size(110, 22);
            this.toolStripMenuItem7.Text = "dasdas";
            // 
            // toolStripMenuItem8
            // 
            this.toolStripMenuItem8.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripMenuItem9});
            this.toolStripMenuItem8.Name = "toolStripMenuItem8";
            this.toolStripMenuItem8.Size = new System.Drawing.Size(105, 22);
            this.toolStripMenuItem8.Text = "dasda";
            // 
            // toolStripMenuItem9
            // 
            this.toolStripMenuItem9.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripMenuItem10});
            this.toolStripMenuItem9.Name = "toolStripMenuItem9";
            this.toolStripMenuItem9.Size = new System.Drawing.Size(105, 22);
            this.toolStripMenuItem9.Text = "adasd";
            // 
            // toolStripMenuItem10
            // 
            this.toolStripMenuItem10.Name = "toolStripMenuItem10";
            this.toolStripMenuItem10.Size = new System.Drawing.Size(110, 22);
            this.toolStripMenuItem10.Text = "asdasd";
            // 
            // toolStripComboBox1
            // 
            this.toolStripComboBox1.Items.AddRange(new object[] {
            "1",
            "2",
            "3",
            "4"});
            this.toolStripComboBox1.Name = "toolStripComboBox1";
            this.toolStripComboBox1.Size = new System.Drawing.Size(121, 23);
            // 
            // toolStripSeparator2
            // 
            this.toolStripSeparator2.Name = "toolStripSeparator2";
            this.toolStripSeparator2.Size = new System.Drawing.Size(190, 6);
            // 
            // toolStripTextBox2
            // 
            this.toolStripTextBox2.Name = "toolStripTextBox2";
            this.toolStripTextBox2.Size = new System.Drawing.Size(100, 23);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(462, 375);
            this.Controls.Add(this.menuStrip2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.menuStrip1);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form1";
            this.Text = "Form1";
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.menuStrip2.ResumeLayout(false);
            this.menuStrip2.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem howKteamcomToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem freeEducationToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem shareToBeBetterToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem k9ToolStripMenuItem;
        private System.Windows.Forms.ToolStripComboBox mntsCombo;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
        private System.Windows.Forms.ToolStripTextBox toolStripTextBox1;
        private System.Windows.Forms.ToolStripMenuItem kjhToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem iyoToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem dasdasToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem dasdaToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem adasdToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem asdasdToolStripMenuItem;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.MenuStrip menuStrip2;
        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2;
        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem3;
        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem4;
        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem5;
        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem6;
        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem7;
        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem8;
        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem9;
        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem10;
        private System.Windows.Forms.ToolStripComboBox toolStripComboBox1;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
        private System.Windows.Forms.ToolStripTextBox toolStripTextBox2;
    }
}

Download project

Kết luận

Bài sau chúng ta sẽ cùng tìm hiểu về ToolStrip trong lập trình C# Winform.

Cảm ơn các bạn đã theo dõi bài viết. Hãy để lại bình luận hoặc góp ý của mình để phát triển bài viết tốt hơn. Đừng quên “Luyện tập – Thử thách – Không ngại khó”.


Tải xuống

Tài liệu

Nhằm phục vụ mục đích học tập Offline của cộng đồng, Kteam hỗ trợ tính năng lưu trữ nội dung bài học MenuStrip trong lập trình C# Winform dưới dạng file PDF trong link bên dưới.

Ngoài ra, bạn cũng có thể tìm thấy các tài liệu được đóng góp từ cộng đồng ở mục TÀI LIỆU trên thư viện Howkteam.com

Đừng quên likeshare để ủng hộ Kteam và tác giả nhé!


Thảo luận

Nếu bạn có bất kỳ khó khăn hay thắc mắc gì về khóa học, đừng ngần ngại đặt câu hỏi trong phần bên dưới hoặc trong mục HỎI & ĐÁP trên thư viện Howkteam.com để nhận được sự hỗ trợ từ cộng đồng.

Nội dung bài viết

Tác giả/Dịch giả

Khóa học

Lập trình Winform cơ bản

Lập trình Winform cơ bản

Đánh giá

tonyit2003 đã đánh giá 18:09 06-07-2023

hoanganh51199 đã đánh giá 21:10 18-09-2020

Kobe24 đã đánh giá 21:17 09-09-2020

Thanks HowKteam/K9!

Masterboy1103 đã đánh giá 20:36 10-08-2020

Nhàn đã đánh giá 22:19 31-01-2020

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
Không có video.