Chinaunix首页 | 论坛 | 博客
  • 博客访问: 841922
  • 博文数量: 372
  • 博客积分: 10063
  • 博客等级: 中将
  • 技术积分: 4220
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 11:36
文章分类

全部博文(372)

文章存档

2012年(372)

分类: 系统运维

2012-04-24 21:44:30

界面我觉得可以做到跟QQ一样都没问题,本来不想搞成这样的,不过搞来搞去就变成这样了

背景是可以换的,或自定义背景图,或背景颜色

这个界面是怎么做的呢?很多初学者可能比较头疼,用第三方控件有时是很难做成自已想要的效果的,而且有些控件是通过拦截系统消息更改实现的,这样方法虽然用起来简单,但很耗系统资源,建议不要用。

要做自定义界面重点要是这里:

复制代码
void form_Paint(object sender, PaintEventArgs e) { if (backgroundpic == null) { bodybrush = new LinearGradientBrush(new Rectangle(0, 0, form.Width, form.Height), backGroundColorA, backGroundColorB, LinearGradientMode.Vertical); e.Graphics.FillPath(bodybrush, CreateRoundedRectanglePath(new Rectangle(0, 0, form.Width, form.Height), cornerSiz, CornerPostionType.Body)); //画底色 } else { // e.Graphics.DrawImage(backgroundpic, new Rectangle(0, 0, form.ClientSize.Width, form.ClientSize.Height), 0, 0, backgroundpic.Width, backgroundpic.Height, GraphicsUnit.Pixel); e.Graphics.DrawImage(backgroundpic, new Rectangle(0, 0, form.ClientSize.Width, form.ClientSize.Height), 0, 0, form.ClientSize.Width, form.ClientSize.Height, GraphicsUnit.Pixel, BackGroundImageAttributes); // e.Graphics.DrawImage(backgroundpic, new Rectangle(0, 0, form.ClientSize.Width, form.ClientSize.Height), 0, 0, backgroundpic.Width, backgroundpic.Height, GraphicsUnit.Pixel, BackGroundImageAttributes); } captionBrush = new LinearGradientBrush(new Rectangle(0, 0, e.ClipRectangle.Width, captionTopHeight), Color.FromArgb(captionTopAlpha, Color.White), Color.FromArgb(captionCenterAlpha, Color.White), LinearGradientMode.Vertical); e.Graphics.FillPath(captionBrush, CreateRoundedRectanglePath(new Rectangle(0, 0, form.ClientSize.Width, captionTopHeight), cornerSiz, CornerPostionType.Top)); //画标题栏 captionBrush2 = new LinearGradientBrush(new Rectangle(0, captionTopHeight - 1, e.ClipRectangle.Width, captionBottomHeight+1), Color.FromArgb(captionCenterAlpha, Color.White), Color.FromArgb(captionBottomAlpha, Color.White), LinearGradientMode.Vertical); e.Graphics.FillRectangle(captionBrush2, new Rectangle(0, captionTopHeight, form.ClientSize.Width, captionBottomHeight)); //画标题栏 ///////// PaintBackgroundStyle(e); }
复制代码

另外自定义后还有一个比较常见的问题,就是没有拖拉窗口大小功能了,这个可以通过程序实现,比较好的方法是拦截窗口消息实现原来的拖拉功能,代码奉上:

复制代码
protected override void WndProc(ref Message m) { switch (m.Msg) { case Win32Message.WM_NCPAINT: break; case Win32Message.WM_NCACTIVATE: if (m.WParam == (IntPtr)0) { m.Result = (IntPtr)1; } if (m.WParam == (IntPtr)2097152) { m.Result = (IntPtr)1; } break; case Win32Message.WM_NCCALCSIZE: break; case Win32Message.WM_NCHITTEST: Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF); vPoint = PointToClient(vPoint); if (MaximizeBox) { if (vPoint.X <= 3) { if (vPoint.Y <= 3) m.Result = (IntPtr)Win32Message.HTTOPLEFT; else if (vPoint.Y >= Height - 3) m.Result = (IntPtr)Win32Message.HTBOTTOMLEFT; else m.Result = (IntPtr)Win32Message.HTLEFT; } else if (vPoint.X >= Width - 3) { if (vPoint.Y <= 3) m.Result = (IntPtr)Win32Message.HTTOPRIGHT; else if (vPoint.Y >= Height - 3) m.Result = (IntPtr)Win32Message.HTBOTTOMRIGHT; else m.Result = (IntPtr)Win32Message.HTRIGHT; } else if (vPoint.Y <= 3) { m.Result = (IntPtr)Win32Message.HTTOP; } else if (vPoint.Y >= Height - 3) m.Result = (IntPtr)Win32Message.HTBOTTOM; } break; default: base.WndProc(ref m); break; } }
复制代码

另外附上我的界面实现类,调用很方便简单 ,在窗口构造函数(初始加载的地方就行)处实例化即可 new SkinEngineForm(this);

 

整个微博桌面应用:

直接用帐号登录是登录不了的,因为新浪已经不允许直接用帐号登录了,做这软件时是可以的

阅读(1099) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~