| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 910 人关注过本帖
标题:Width,Heigth能用负数么?
只看楼主 加入收藏
大雨过后
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-8-22
收藏
 问题点数:0 回复次数:1 
Width,Heigth能用负数么?

在看一个自画菜单的设计的时候有一个问题很不理解!
这个点击一个命令"椭圆形"时(我已经在其命令的属性窗口中选择了DrawItem事件)
此时我在这个事件中添加这个代码:
private void menuItem2_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
Graphics g=e.Graphics;
//判断菜单项的状态
if ((e.State & DrawItemState.Selected)==DrawItemState.Selected)
{
//绘制背景填充矩形
g.FillRectangle(new SolidBrush(Color.Red),e.Bounds.Left,
e.Bounds.Top,e.Bounds.Width,e.Bounds.Height);
//绘制前景椭圆
g.DrawEllipse(new Pen(Color.Yellow,2.0f),e.Bounds.Left+5,e.Bounds.Top+3,
e.Bounds.Width-10,e.Bounds.Height-6);
}

else
{
//变换颜色绘制前景和背景
g.FillRectangle(new SolidBrush(Color.Yellow),
e.Bounds.Left,e.Bounds.Top,e.Bounds.Width,e.Bounds.Height);
g.DrawEllipse(new Pen( Color.Red,2.0f),e.Bounds.Left+5,e.Bounds.Top+3,
e.Bounds.Width-10,e.Bounds.Height-6);

}
}
我的问题是;1为什么在调用Drawlist()的时候这个Width和Height的参数设的是负数啊?
2.这个代码的if ((e.State & DrawItemState.Selected)==DrawItemState.Selected)这个条件是什么意思啊?
万分感激啊!

搜索更多相关主题的帖子: Heigth Width 负数 
2006-08-22 01:43
mylover624
Rank: 1
来 自:乖乖的心中
等 级:新手上路
帖 子:868
专家分:0
注 册:2006-7-6
收藏
得分:0 
这不是负数:
e.Bounds.Width-10 这个是将原来的宽度减少10;
e.Bounds.Height-6 这个是将原来的高度减少6;
它们和"e.Bounds.Left+5,e.Bounds.Top+3"是差不多的道理.

if ((e.State & DrawItemState.Selected)==DrawItemState.Selected)
这句是当 DrawItemState 的某一项被选中时.你将要进行什么操作…………

[此贴子已经被作者于2006-8-22 11:19:14编辑过]


一个天才顶不上十个笨蛋!
书山有路勤为径,学海无涯友相伴。
我的E-mail:mylover624@.cn
2006-08-22 11:18
快速回复:Width,Heigth能用负数么?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011241 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved