1. 隐藏TabPage

在使用TabControl控件时,希望隐藏其中某个选项卡(即TabPage)。设置该TabPage的父容器为null 即可,如TabPage.Parent = null 。如需显示该TabPage,设置其父容器为对应的TabControl即可;

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 WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
tabPage3.Parent = null;//使tabPage3不可见 }
private void button1_Click(object sender, EventArgs e)
{
tabPage3.Parent = tabControl2;//使tabPage3可见
tabPage1.Parent = null;//使tabPage1不可见
tabControl2.SelectedTab = tabPage3;//停留在tabPage3
} }
}

2. 鼠标右键菜单

1) 把ContextMenuStrip控件拖放到设计界面上(此处命名为cmMenu)。

2)右键cmMenu,点击Edit Items,添加菜单项,比如添加“打开”,“保存”等

3)  将想绑定控件(此处为Form)的ContextMenuStrip属性设置为设计的ContextMenuStrip(即cmMenu)。

运行:

3. 定时器

示例:用定时器每隔1s刷新数组,数字每次+1

代码:

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 WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public int number = 0; System.Timers.Timer timer;
private void Form1_Load(object sender, EventArgs e)
{
timer = new System.Timers.Timer(1000);
timer.Elapsed += new System.Timers.ElapsedEventHandler(changeNumber);
timer.AutoReset = true;//AutoReset属性设置是否重复计时(设置为false只执行一次,设置为true可以多次执行)
timer.Enabled = false;
}
private void changeNumber(object obj, EventArgs e)
{
number++;
this.Invoke(new Action(delegate { this.textBox1.Text = number.ToString(); }));
} private void toolStripMenuItem1_click(object sender, EventArgs e)
{
timer.Start();
}
private void toolStripMenuItem2_click(object sender, EventArgs e)
{
timer.Stop();
}
}
}
namespace WinFormsApp1
{
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.components = new System.ComponentModel.Container();
this.cmMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
this.textBox1 = new System.Windows.Forms.TextBox();
this.cmMenu.SuspendLayout();
this.SuspendLayout();
//
// cmMenu
//
this.cmMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItem1,
this.toolStripMenuItem2});
this.cmMenu.Name = "contextMenuStrip1";
this.cmMenu.Size = new System.Drawing.Size(101, 48);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(100, 22);
this.toolStripMenuItem1.Text = "开始";
this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_click);
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(100, 22);
this.toolStripMenuItem2.Text = "停止";
this.toolStripMenuItem2.Click += new System.EventHandler(this.toolStripMenuItem2_click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(149, 74);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(161, 23);
this.textBox1.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.ContextMenuStrip = this.cmMenu;
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.cmMenu.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.ContextMenuStrip cmMenu;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2;
private System.Windows.Forms.TextBox textBox1;
}
}

C#笔记(1)窗体的更多相关文章

  1. C#学习笔记-Windows窗体自定义初始位置

    根据屏幕大小定义初始位置: (这个不是难,但是最近常常忘记,记着方便查看.) //获取当前屏幕的长和宽 int ScreenX = Screen.PrimaryScreen.Bounds.Width; ...

  2. C#学习笔记-Windows窗体基本功能(Login登录界面)

    本菜鸟由于实习工作的原因,不得不快速接触C#语言,刚刚好又要做毕业设计,所以就通过自学的方式一举两得地完成这两件事情. 故此文字记录或代码中的各种文件名之类均是以毕业设计为模版记录的,看着不方便之处请 ...

  3. C#学习笔记——MDI窗体(多文档界面)

    1.设置父窗体: 如果要将某个窗体设置为父窗体,只需将该窗体的IsMdiContainer属性设置为True即可. 2.设置子窗体: 通过设为某个窗体的MdiParent属性来确定该窗体是那个窗体的子 ...

  4. JAVA笔记__窗体类/Panel类/Toolkit类

    /** * 窗体类 */ public class Main { public static void main(String[] args) { MyFrame m1 = new MyFrame() ...

  5. c#窗体开发

    奇: 常用控件的使用(期间参杂着VS快捷键/常用设置) 快捷键:引用命名空间:shift+alt+F10 断点:F9 调试:F5 逐句调试(每行代码一次跳转):F11 逐过程调试:F10 重构提取方法 ...

  6. Duilib学习笔记《06》— 窗体基类WindowImpBase

    在前面的例子中我们发现,窗口都是继承CWindowWnd.INotifyUI,然后重载相关函数去实现.显然,我们发现窗口的创建流程实际上都是差不多的,主要只是在OnCreate加载的配置文件不同等等… ...

  7. Duilib学习笔记《04》— 窗体显示

    在前面已经了解了duilib控件以及界面布局相关内容,接下来就要考虑该如何将xml中描述的布局通过界面展现出来.实际上在 Duilib学习笔记<01> 中我们已经简单提到过基本的流程及元素 ...

  8. OpenTK学习笔记(3)-你好!窗体!

    参考:http://dreamstatecoding.blogspot.com/2017/01/opengl-4-with-opentk-in-c-part-1.html http://www.cnb ...

  9. PyQt5学习笔记-从主窗体打开一个子窗体

    PyQt5学习笔记-从主窗体打开一个子窗体 软件环境: Eric6+Python3.5+PyQt5 试验目标: 1.点击菜单项Open,打开一个子窗体 2.点击按钮Open,打开一个子窗体 主窗体设计 ...

  10. SQL Server Window Function 窗体函数读书笔记二 - A Detailed Look at Window Functions

    这一章主要是介绍 窗体中的 Aggregate 函数, Rank 函数, Distribution 函数以及 Offset 函数. Window Aggregate 函数 Window Aggrega ...

随机推荐

  1. c# .net缓存(旧)

    前言 是迁移以前的blog. 关于c# 缓存在web应用中的一个引导,能够建立起一个缓存的基本思路. System.Web.Caching 这个真的是老生常谈了,我们只需要key和iv,然后我们就可以 ...

  2. 剑指offer56(Java)-数组中出现的次数Ⅰ(中等)

    题目: 一个整型数组 nums 里除两个数字之外,其他数字都出现了两次.请写程序找出这两个只出现一次的数字.要求时间复杂度是O(n),空间复杂度是O(1). 示例 1: 输入:nums = [4,1, ...

  3. 力扣220(java)-存在重复元素 III(困难)

    题目: 给你一个整数数组 nums 和两个整数 k 和 t .请你判断是否存在 两个不同下标 i 和 j,使得 abs(nums[i] - nums[j]) <= t ,同时又满足 abs(i ...

  4. SRE技术保障平台-盯屏中心TAC: 混合云一站式告警运维平台

    简介: SRE技术保障平台-盯屏中心TAC: 混合云一站式告警运维平台 1.目标定位 1.1背景 告警管控平台种类繁多 告警出现后未及时发现处理最终导致故障产生 专有云监控能力拉起依赖版本升级,操作复 ...

  5. [GPT] swoole的协程和golang的协程有什么区别,哪个更好

    Swoole 的协程和 Golang(Go 语言)的协程(Goroutine)在概念上都是为了实现轻量级的并发编程,但它们在具体实现.使用方式和性能特点上有所不同: 实现原理: Golang 协程(G ...

  6. GitHub 的 Action 判断仅在主仓库才执行脚本

    我有一个 GitHub 项目,这个项目配置了仅需要在源仓库才能执行的 Action 如推送 NuGet 等发布动作.如何在 Action 里面设置让 Fork 的仓库不执行 Action 的步骤 想要 ...

  7. Vue3 和 Vue2 的异同及开发中具体区别

    目录 总体来说 性能提升 树摇(Tree shaking) 碎片化节点(Fragment) 传送门 (Teleport) Suspense 更好的TypeScript支持 Composition AP ...

  8. spannerlib优雅的go异常处理

    蹩脚的go 异常处理 一般写go的人,如果他不是写算法,正常写业务代码的话,可能都会为优雅的异常处理而烦恼,因为脑子抽筋的go设计者们,总是感觉语法糖是一种很低级的东西.但是在我们大多数公司的业务逻辑 ...

  9. LVGL 字体

    一.LVGL 内置字体 LVGL有几种不同大小的内置字体,可以通过 LV_FONT_MONTSERRAT_X 定义在 lv_conf.h 中启用. 普通字体 包含所有ASCII字符,度数符号(U + ...

  10. Ryght 在 Hugging Face 专家助力下赋能医疗保健和生命科学之旅

    本文是 Ryght 团队的客座博文. Ryght 是何方神圣? Ryght 的使命是构建一个专为医疗保健和生命科学领域量身定制的企业级生成式人工智能平台.最近,公司正式公开了 Ryght 预览版 平台 ...