设为首页 加入收藏

TOP

C# 在winform画面上点击某个区域造成按钮按下效果的方法(一)
2014-11-24 14:34:35 来源: 作者: 【 】 浏览:5
Tags:winform 面上 点击 某个 区域 造成 按钮 效果 方法

在Winform的窗体中,存在背景图的情况下,不想在画面上加入按钮,只希望利用窗体自身的几个事件来实现按钮按下的效果,怎么样实现呢?


其实这也不难,只需要按照下列步骤即可实现,首先确定要按下的几个区域的坐标点和大小,准备好按下和弹出的图片,将这些坐标点和大小


组成一个个区域(使用GraphicsPath来完成)。然后使用几个Flage标志,标识是否区域的按下。具体实现的代码如下:


///


/// 实时监控,酒位展示,酒柜介绍,网络订购4个按钮的位置参数
///

int[,] BtnLocation = new int[4, 2]{{637,161},{683,269},{714,374},{637,478}};
///
/// 4个按钮的Size参数
///

Size BtnSize = new Size(285,92);
///
/// 实时监控按钮是否按下的标志
///

bool FlageMouseDownRealTime = false;
///
/// 酒位展示按钮是否按下的标志
///

bool FlageMouseDownWinePos = false;
///
/// 酒柜介绍按钮是否按下的标志
///

bool FlageMouseDownCupIntrol = false;
///
/// 网络订购按钮是否按下的标志
///

bool FlageMouseDownNetPurchase = false;
///
/// 实时监控按钮的位置范围
///

GraphicsPath gpRealTime = new GraphicsPath();
///
/// 酒位展示按钮的位置范围
///

GraphicsPath gpWinePos = new GraphicsPath();
///
/// 酒柜介绍按钮的位置范围
///

GraphicsPath gpCupIntrol = new GraphicsPath();
///
/// 网络订购按钮的位置范围
///

GraphicsPath gpNetPurchase = new GraphicsPath();


Graphics dc = null;




///


/// 获取4个按钮的区域范围
///

private void GetButtonGraphicPath()
{
FlageMouseDownRealTime = false;
FlageMouseDownWinePos = false;
FlageMouseDownCupIntrol = false;
FlageMouseDownNetPurchase = false;


Point[] pt = new Point[]{
new Point(BtnLocation[0,0],BtnLocation[0,1]),
new Point(BtnLocation[0,0]+BtnSize.Width,BtnLocation[0,1]),
new Point(BtnLocation[0,0]+BtnSize.Width,BtnLocation[0,1]+BtnSize.Height),
new Point(BtnLocation[0,0],BtnLocation[0,1]+BtnSize.Height)
};
gpRealTime.AddLines(pt);
pt = new Point[]{
new Point(BtnLocation[1,0],BtnLocation[1,1]),
new Point(BtnLocation[1,0]+BtnSize.Width,BtnLocation[1,1]),
new Point(BtnLocation[1,0]+BtnSize.Width,BtnLocation[1,1]+BtnSize.Height),
new Point(BtnLocation[1,0],BtnLocation[1,1]+BtnSize.Height)
};
gpWinePos.AddLines(pt);
pt = new Point[]{
new Point(BtnLocation[2,0],BtnLocation[2,1]),
new Point(BtnLocation[2,0]+BtnSize.Width,BtnLocation[2,1]),
new Point(BtnLocation[2,0]+BtnSize.Width,BtnLocation[2,1]+BtnSize.Height),
new Point(BtnLocation[2,0],BtnLocation[2,1]+BtnSize.Height)
};
gpCupIntrol.AddLines(pt);
pt = new Point[]{
new Point(BtnLocation[3,0],BtnLocation[3,1]),
new Point(BtnLocation[3,0]+BtnSize.Width,BtnLocation[3,1]),
new Point(BtnLocation[3,0]+BtnSize.Width,BtnLocation[3,1]+BtnSize.Height),
new Point(BtnLocation[3,0],BtnLocation[3,1]+BtnSize.Height)
};
gpNetPurchase.AddLines(pt);


}




private void InitialButtonsStyle()
{
GetButtonGraphicPath();


pxControl.Location = new Point(0,0);
pxControl.Size = new Size(1024,768);
SetBackGroudImg();
this.Controls.Add(pxControl);
dc = pxControl.CreateGraphics();
pxControl.MouseDoubleClick +=new MouseEventHandler(this.Main_MouseDoubleClick);
pxControl.MouseDown+=new MouseEventHandler(this.

首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android提供两个常用的消息弹出框.. 下一篇[C#]分享一个以前的项目使用的Dat..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: