combox和panel的使用 这功能很简单嘛,主要是肯定只会在panel出现一个图形,不会出现两个。只不过有点麻烦,需要先画好三角形,正方形,做成控件,以控件形式添加到panel里显示,然后只要处理键盘事件就可以达到效果了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Drawing.Drawing2D;namespace WindowsApplication162{ public partial class Form1 : Form { Panel Shape = new Panel(); Panel P = new Panel(); public Form1() { InitializeComponent(); ComboBox CB = new ComboBox(); CB.Parent = this; CB.Items.AddRange(new Object[] { "三角形", "正方形" }); CB.SelectedIndexChanged += new EventHandler(CB_SelectedIndexChanged); CB.DropDownStyle = ComboBoxStyle.DropDownList; P.Parent = this; P.Location = new Point(0, 20); this.KeyDown += new KeyEventHandler(Form1_KeyDown); this.KeyPreview = true; CB.KeyDown += new KeyEventHandler(CB_KeyDown); } void CB_KeyDown(object sender, KeyEventArgs e) { e.SuppressKeyPress = true; // 防止联动,只允许鼠标选择ComboBox } void Form1_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Up: Shape.Top--; break; case Keys.Down: Shape.Top++; break; case Keys.Left: Shape.Left--; break; case Keys.Right: Shape.Left++; break; } } void CB_SelectedIndexChanged(object sender, EventArgs e) { ComboBox CB = (ComboBox)sender; GraphicsPath GP = new GraphicsPath(); switch (CB.SelectedIndex) { case 0: GP.AddLine(0, 60, 30, 0); GP.AddLine(30, 0, 60, 60); GP.AddLine(60, 60, 0, 60); break; case 1: GP.AddRectangle(new Rectangle(0, 0, 60, 60)); break; } Shape.Parent = P; Shape.BackColor = Color.Red; Shape.Region = new Region(GP); } }} 画三角形等几何图形比较麻烦,用图片代替。再判断键盘事件,改变图片在panel中的位置就可以。 正则大师来啊,学习正则的来啊 DirectorySecurity如何察看group的访问权限? 怎样让一个程序在一台电脑上面只能运行一次? C#中是否有一个Parameter类? 用实体类后 如何处理多表关联的查询更新删除 这个应该怎样写 图片去干扰 DataGrid .net面试---一些基本概念回答不上来怎么办? 我想问一下这个使用VS2012的应该怎么做? 关于Global Assembly Cache 问题 c# 倒计时与文本接收
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;namespace WindowsApplication162
{
public partial class Form1 : Form
{
Panel Shape = new Panel();
Panel P = new Panel(); public Form1()
{
InitializeComponent(); ComboBox CB = new ComboBox();
CB.Parent = this;
CB.Items.AddRange(new Object[] { "三角形", "正方形" });
CB.SelectedIndexChanged += new EventHandler(CB_SelectedIndexChanged);
CB.DropDownStyle = ComboBoxStyle.DropDownList; P.Parent = this;
P.Location = new Point(0, 20);
this.KeyDown += new KeyEventHandler(Form1_KeyDown);
this.KeyPreview = true;
CB.KeyDown += new KeyEventHandler(CB_KeyDown);
} void CB_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = true; // 防止联动,只允许鼠标选择ComboBox
} void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Up: Shape.Top--; break;
case Keys.Down: Shape.Top++; break;
case Keys.Left: Shape.Left--; break;
case Keys.Right: Shape.Left++; break;
}
} void CB_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox CB = (ComboBox)sender;
GraphicsPath GP = new GraphicsPath(); switch (CB.SelectedIndex)
{
case 0:
GP.AddLine(0, 60, 30, 0);
GP.AddLine(30, 0, 60, 60);
GP.AddLine(60, 60, 0, 60);
break;
case 1:
GP.AddRectangle(new Rectangle(0, 0, 60, 60));
break;
} Shape.Parent = P;
Shape.BackColor = Color.Red;
Shape.Region = new Region(GP);
}
}
}