社区
C#
帖子详情
toolStripMenuItem小问题
yunhaiC QQ654777694
2015-03-25 10:30:22
请教大家一个问题,这个toolStripMenuItem在设计的状态下,我把属性Check = true,然后控件就会显示勾选状态,他是怎么在工程没有Run的情况下,就是在设计器的状态下,进行勾选重绘的?
能否给个代码看看效果,谢谢
...全文
146
1
打赏
收藏
toolStripMenuItem小问题
请教大家一个问题,这个toolStripMenuItem在设计的状态下,我把属性Check = true,然后控件就会显示勾选状态,他是怎么在工程没有Run的情况下,就是在设计器的状态下,进行勾选重绘的? 能否给个代码看看效果,谢谢
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
RainBow_24
2015-03-26
打赏
举报
回复
并不是程序自己重绘,那是IDE干的事吧。
C# 創建彈出式菜單(
Tool
Strip
MenuItem
).doc
方法: 1、創建一個菜單項數組。 2、在數組中增加菜單項 3、創建一個彈出式引用菜單 4、將菜單與菜單項加入到彈出式引用菜單中 5、將控件的ContextMenu
Strip
屬性設置成彈出菜單
HistoryMenu(历史菜单)
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.IO; namespace HistoryMenu { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void 打开
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { openFileDialog1.Filter = "*.*(所有文件)|*.*";//设置打开文件格式 if (openFileDialog1.ShowDialog() == DialogResult.OK)//判断是否打开选择文件对话框 { StreamWriter s = new StreamWriter("Menu.ini", true);//实例化写入流对象 s.WriteLine(openFileDialog1.FileName);//向INI文件写入内容 s.Flush();//清除缓冲区 s.Close();//关闭写入流 System.Diagnostics.Process.Start(openFileDialog1.FileName);//打开选择的文件 } Form1_Load(sender, e);//重新加载菜单 } private void Form1_Load(object sender, EventArgs e) { 文件
Tool
Strip
MenuItem
.DropDownItems.Clear();//清空菜单
Tool
Strip
MenuItem
menuitem
1 = new
Tool
Strip
MenuItem
("打开");//实例化打开菜单 文件
Tool
Strip
MenuItem
.DropDownItems.Insert(0,
menuitem
1);//添加打开菜单
menuitem
1.Click += new EventHandler(打开
Tool
Strip
MenuItem
_Click);//为打开菜单指定单击事件
Tool
Strip
MenuItem
menuitem
2 = new
Tool
Strip
MenuItem
("退出");//实例化退出菜单 文件
Tool
Strip
MenuItem
.DropDownItems.Insert(1,
menuitem
2);//添加退出菜单 StreamReader sr = new StreamReader("Menu.ini");//实例化读取流对象 int i = this.文件
Tool
Strip
MenuItem
.DropDownItems.Count - 1;//定义历史记录位置 while (sr.Peek() >= 0)//从INI文件读取历史记录 {
Tool
Strip
MenuItem
menuitem
= new
Tool
Strip
MenuItem
(sr.ReadLine());//实例化历史菜单 this.文件
Tool
Strip
MenuItem
.DropDownItems.Insert(i,
menuitem
);//添加历史菜单 i++;//重新指定历史记录位置
menuitem
.Click += new EventHandler(
menuitem
_Click);//为历史菜单指定单击事件 } sr.Close();//关闭读取流 } private void
menuitem
_Click(object sender, EventArgs e) { try {
Tool
Strip
MenuItem
menu = (
Tool
Strip
MenuItem
)sender;//获取菜单单击项 System.Diagnostics.Process.Start(menu.Text);//根据历史菜单打开指定文件 } catch { } } } }
贪吃蛇C#net
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.Collections; namespace 贪吃蛇 { public partial class Form1 : Form { public int speed = 350; //用于设置贪吃蛇的速度 public static bool ifStart = false; //用于游戏是否开始 public static bool pause = true; //用于游戏是否暂停,游戏暂停为true Snake snake = new Snake();//实例化Snake类 Food food = new Food(); public Form1() { InitializeComponent(); } //绘制游戏场景 public void ProtractTable(Graphics G) { //绘制单元格的纵向线 for (int i = 0; i <= panel1.Width / Snake.SnakeBone; i++) { G.DrawLine(new Pen(Color.LightGreen, 1), new Point(i * Snake.SnakeBone, 0), new Point(i * Snake.SnakeBone, panel1.Height)); } //绘制单元格的横向线 for (int i = 0; i <= panel1.Height / Snake.SnakeBone; i++) { G.DrawLine(new Pen(Color.LightGreen, 1), new Point(0, i * Snake.SnakeBone), new Point(panel1.Width, i * Snake.SnakeBone)); } } private void panel1_Paint(object sender, PaintEventArgs e) { Graphics G = panel1.CreateGraphics();//创建panel1控件的Graphics类 ProtractTable(G); //绘制游戏场景 if (!ifStart) //如果没有开始游戏 { Snake.timer = timer1; Snake.label = label1; //初始化场地及贪吃蛇信息; //Control c = (Control)panel1; Snake.GamePlaceSet(panel1, Snake.SnakeBone); } else { for (int i = 0; i < Snake.List.Count; i++)//绘制蛇体 { e.Graphics.FillRectangle(Snake.SolidSnake, ((Point)Snake.List[i]).X + 1, ((Point)Snake.List[i]).Y + 1, Snake.SnakeBone - 1, Snake.SnakeBone - 1); } //绘制食物 e.Graphics.FillRectangle(Food.SolidFood, Food.FoodPoint.X + 1, Food.FoodPoint.Y + 1, Snake.SnakeBone - 1, Snake.SnakeBone - 1); if (Snake.isGame)//如果游戏结束 { e.Graphics.DrawString("游戏结束!", new Font("宋体", 50, FontStyle.Bold), new SolidBrush(Color.Yellow), new PointF(100, 150)); } } } private void 初级
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) {//在游戏没有开始和游戏结束时才可以选择设置 if ((ifStart == false) || Snake.isGame) {初级
Tool
Strip
MenuItem
.Checked = false;//设置初级项被选中 中级
Tool
Strip
MenuItem
.Checked = false;//设置中级项被选中 高级
Tool
Strip
MenuItem
.Checked = false;//设置高级项目被选中 ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 speed = 350; label.Focus();//获得焦点 } } private void 中级
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { //在游戏没有开始和游戏结束时才可以选择设置 if ((ifStart == false) || Snake.isGame) { 初级
Tool
Strip
MenuItem
.Checked = false;//设置初级项被选中 中级
Tool
Strip
MenuItem
.Checked = false;//设置中级项被选中 高级
Tool
Strip
MenuItem
.Checked = false;//设置高级项目被选中 ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 speed = 250;//中级 label.Focus();//获得焦点 } } private void 高级
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) {//在游戏没有开始和游戏结束时才可以选择设置 if ((ifStart == false) || (Snake.isGame)) { 初级
Tool
Strip
MenuItem
.Checked = false;//设置初级项被选中 中级
Tool
Strip
MenuItem
.Checked = false;//设置中级项被选中 高级
Tool
Strip
MenuItem
.Checked = false;//设置高级项目被选中 ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 speed = 200;//高级 label.Focus();//获得焦点 } } private void 开始sapce
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { //控制游戏的开始、暂停、和退出 ifStart = false; Graphics G = panel1.CreateGraphics();//创建panel1控件的Graphics类 //刷新游戏场地 G.FillRectangle(Snake.SolidBack, 0, 0, panel1.Width, panel1.Height); ProtractTable(G);//绘制游戏场地 ifStart = true;//开始游戏 //初始化场地以及贪吃蛇信息 Snake.GamePlaceSet(panel1, Snake.SnakeBone); timer1.Interval = speed;//设置贪吃蛇的移动速度 timer1.Start();//启动计时器 pause = false;//游戏初始状态,暂停取消 label.Text = "0";//显示当前分数 Food.Buildfood(Snake.hasFood, Snake.co);//生成食物 label.Focus();//获得焦点,便于键盘操作 } private void 暂停
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { Graphics G = panel1.CreateGraphics();//创建panel1控件的Graphics类 //如果游戏正在运行 if ((pause == false && ifStart == true) && (!Snake.isGame)) { G.DrawString("游戏暂停!", new Font("宋体", 50, FontStyle.Bold), new SolidBrush(Color.Yellow), new PointF(100, 150)); timer1.Stop();//停止当前计时器 pause = true;//当前游戏暂停 } //如果游戏正在运行 else if (pause == true && ifStart == true && (!Snake.isGame)) { G.FillRectangle(Snake.SolidBack, 0, 0, panel1.Width, panel1.Height); ProtractTable(G); timer1.Start();//启动计时器 pause = false;//开始游戏 } } private void 结束F4
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { if ((ifStart == false) || (Snake.isGame))//如果游戏正在运行 { if (DialogResult.Yes == MessageBox.Show("是否退出游戏?", "提示", MessageBoxButtons.YesNo)) { timer1.Stop(); //停止计时器 Application.Exit(); //停止运行,退出游戏 } } else MessageBox.Show("游戏正在运行中,暂时不允许退出!", "提示"); } private void 游戏说明
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { Form2 f2 = new Form2(); f2.Show(); } //控制游戏的开始、暂停、和退出 public void NoviceControl(int n) { Graphics G = panel1.CreateGraphics();//创建panel1控件的Graphics类 switch (n) { case 1://开始游戏 { ifStart = false; //刷新游戏场地 G.FillRectangle(Snake.SolidBack, 0, 0, panel1.Width, panel1.Height); ProtractTable(G);//绘制游戏场地 ifStart = true;//开始游戏 //初始化场地以及贪吃蛇信息 Snake.GamePlaceSet(panel1, Snake.SnakeBone); timer1.Interval = speed;//设置贪吃蛇的移动速度 timer1.Start();//启动计时器 pause = false;//暂停游戏 Food.Buildfood(Snake.hasFood, Snake.co);//生成食物 label.Text = "0";//显示当前分数 break; } case 2://暂停游戏 {//如果游戏正在运行 if ((pause == false && ifStart == true) && (!Snake.isGame)) { G.DrawString("游戏暂停!", new Font("宋体", 50, FontStyle.Bold), new SolidBrush(Color.Yellow), new PointF(100, 150)); timer1.Stop();//停止当前计时器 pause = true;//当前游戏暂停 } //如果游戏正在运行 else if (pause == true && ifStart == true && (!Snake.isGame)) { G.FillRectangle(Snake.SolidBack, 0, 0, panel1.Width, panel1.Height); ProtractTable(G); timer1.Start();//启动计时器 pause = false;//开始游戏 } break; } case 3://退出游戏 { if ((ifStart == false) || (Snake.isGame))//如果游戏正在运行 { timer1.Stop(); //停止计时器 Application.Exit(); //停止运行,退出游戏 } break; } // case 4://打开帮助信息 // ' { if ((ifStart == false) || (Snake.isGame))//如果游戏正在运行 { // help temp = new help();//初始 一个 help实例 // if (temp.ShowDialog(this) == DialogResult.OK) // temp.Dispose(); // } // break; // } // } } } } private void Form1_KeyDown(object sender, KeyEventArgs e) { int tem_p = -1;//记录控件键值 if (e.KeyCode == Keys.F2)//如果按F2 tem_p = 1;//开始游戏 if (e.KeyCode == Keys.Space)//如果按F3 tem_p = 2;//暂停游戏或者继续游戏 if (e.KeyCode == Keys.F4)//如果按F4 tem_p = 3;//关闭游戏 if (e.KeyCode==Keys.F3) tem_p = 4;//打开帮助信息 if (tem_p != -1)//如果当前是操作标识 NoviceControl(tem_p); //控制游戏的暂停和关闭 if (ifStart == true && pause == false)//如果游戏启动,键盘方向键才起作用 { int tem_n = -1;//记录移动键值 if (e.KeyCode == Keys.Right || e.KeyCode == Keys.D)//按下右键向右移动 tem_n = 0; if (e.KeyCode == Keys.Left || e.KeyCode == Keys.A)//按下左键向左移动 tem_n = 1; if (e.KeyCode == Keys.Up || e.KeyCode == Keys.W)//按下上键向上移动 tem_n = 2; if (e.KeyCode == Keys.Down || e.KeyCode == Keys.S)//按下键向下移动 tem_n = 3; if (tem_n != -1 && tem_n != Snake.Direct) { if (Snake.isGame == false) {//如果移动的方向不是相反方向 if (!((tem_n == 0 && Snake.Direct == 1 || tem_n == 1 && Snake.Direct == 0) || (tem_n == 2 && Snake.Direct == 3 || tem_n == 3 && Snake.Direct == 2))) { Snake.Direct = tem_n;//记录移动的方向 snake.SnakeMove(tem_n, this);//移动贪吃蛇 } } } } } private void 绿色
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { if ((ifStart == false) || (Snake.isGame)) { 绿色
Tool
Strip
MenuItem
.Checked = false; 红色
Tool
Strip
MenuItem
.Checked = false; 蓝色
Tool
Strip
MenuItem
.Checked = false; 黑色
Tool
Strip
MenuItem
.Checked = false; ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 Snake.SolidSnake = new SolidBrush(Color.Green); } } private void 红色
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { if ((ifStart == false) || (Snake.isGame)) { 绿色
Tool
Strip
MenuItem
.Checked = false; 红色
Tool
Strip
MenuItem
.Checked = false; 蓝色
Tool
Strip
MenuItem
.Checked = false; 黑色
Tool
Strip
MenuItem
.Checked = false; ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 Snake.SolidSnake = new SolidBrush(Color.Red); } } private void 蓝色
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { if ((ifStart == false) || (Snake.isGame)) { 绿色
Tool
Strip
MenuItem
.Checked = false; 红色
Tool
Strip
MenuItem
.Checked = false; 蓝色
Tool
Strip
MenuItem
.Checked = false; 黑色
Tool
Strip
MenuItem
.Checked = false; ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 Snake.SolidSnake = new SolidBrush(Color.Blue); } } private void 黑色
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { if ((ifStart == false) || (Snake.isGame)) { 绿色
Tool
Strip
MenuItem
.Checked = false; 红色
Tool
Strip
MenuItem
.Checked = false; 蓝色
Tool
Strip
MenuItem
.Checked = false; 黑色
Tool
Strip
MenuItem
.Checked = false; ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 Snake.SolidSnake = new SolidBrush(Color.Black); } } private void 原始大小
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { if ((ifStart == false) || (Snake.isGame)) { 原始大小
Tool
Strip
MenuItem
.Checked = false; 放大两倍
Tool
Strip
MenuItem
.Checked = false; 放大三倍
Tool
Strip
MenuItem
.Checked = false; ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 Snake.SnakeBone = 10; } } private void 放大两倍
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { if ((ifStart == false) || (Snake.isGame)) { 原始大小
Tool
Strip
MenuItem
.Checked = false; 放大两倍
Tool
Strip
MenuItem
.Checked = false; 放大三倍
Tool
Strip
MenuItem
.Checked = false; ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 Snake.SnakeBone = 20; } } private void 放大三倍
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { if ((ifStart == false) || (Snake.isGame)) { 原始大小
Tool
Strip
MenuItem
.Checked = false; 放大两倍
Tool
Strip
MenuItem
.Checked = false; 放大三倍
Tool
Strip
MenuItem
.Checked = false; ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 Snake.SnakeBone = 30; } } private void 橙色
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { if ((ifStart == false) || (Snake.isGame)) {橙色
Tool
Strip
MenuItem
.Checked = false; 黄色
Tool
Strip
MenuItem
.Checked = false; 紫色
Tool
Strip
MenuItem
.Checked = false; ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 Food.SolidFood = new SolidBrush(Color.Orange); } } private void 黄色
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { if ((ifStart == false) || (Snake.isGame)) { 橙色
Tool
Strip
MenuItem
.Checked = false; 黄色
Tool
Strip
MenuItem
.Checked = false; 紫色
Tool
Strip
MenuItem
.Checked = false; ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 Food.SolidFood = new SolidBrush(Color.Yellow); } } private void 紫色
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { if ((ifStart == false) || (Snake.isGame)) { 橙色
Tool
Strip
MenuItem
.Checked = false; 黄色
Tool
Strip
MenuItem
.Checked = false; 紫色
Tool
Strip
MenuItem
.Checked = false; ((
Tool
Strip
MenuItem
)sender).Checked = true;//设置当前项选中 Food.SolidFood = new SolidBrush(Color.Purple); } } private void timer1_Tick(object sender, EventArgs e) { snake.SnakeMove(Snake.Direct, this);//移动贪吃蛇 } private void textBox1_TextChanged(object sender, EventArgs e) { } private void label_Click(object sender, EventArgs e) { } } }
Nathan记事本源代码
一个功能比较全面的记事本源代码示例 private void 复制
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { richTextBox1.Copy(); } private void 剪切
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { richTextBox1.Cut(); } private void 粘贴
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { richTextBox1.Paste(); } private void 撤消
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { richTextBox1.Undo(); } private void 恢复
Tool
Strip
MenuItem
_Click(object sender, EventArgs e) { richTextBox1.Redo();
C#的简单的学生管理系统
private void
tool
Strip
MenuItem
1_Click(object sender, EventArgs e) { string num = dataGridView1["ID", dataGridView1.SelectedRows[0].Index].Value.ToString().Trim(); if (MessageBox.Show("是否确定删除?", "确认删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No) { //Console.WriteLine(dataGridView1.Columns[1].HeaderText); OleDbConnection conn = DB.connection(); DB.delete(conn, "ID", num); DB.close(conn); Close(); } }
C#
110,535
社区成员
642,577
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章