自定义MessageBox
来源:互联网 发布:软件项目进度计划表 编辑:程序博客网 时间:2024/05/25 01:35
其实就是一个Form遮挡另一个Form。
The convenience of having custom controls is that they can be usedas normal controls. Where convenient, we adhered to this philosophythroughout the project; e.g. the message box, the picture button andthe sliding list are real controls, ready to be reuse in externalprojects.
Custom Image Button
The button ImageButtoninherits from Control and allows you to display an image with thebehaviors of a button. To customize the control we perform the overrideof these methods:
protected override void OnPaintBackground(PaintEventArgs e)
{
//Do nothing
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if (isPressed)
e.Graphics.DrawImage(imagePressed, 0, 0);
else
e.Graphics.DrawImage(image, 0, 0);
}
To change the image of the button when it is pressed, we override OnMouseDown and OnMouseUp event methods and we set a Boolean defining which image to draw:
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
isPressed = true;
this.Invalidate();
base.OnMouseDown(e);
}
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
{
isPressed = false;
this.Invalidate();
base.OnMouseUp(e);
}
Finally, in order to use this custom control within a form, we can use the following:
ImageButton customButton = new ImageButton(bitmap, bitmapPressed, transparentColor);
customButton.Size = new Size(200,50);
customButton.Location = newPoint(0,0);
customButton.Click += new EventHandler(customButton_Click);
Custom MessageBox, AlphaBlend and Image Trasparency
The MessageBox is a full screen form exploiting alpha blending and image transparency. The alpha blending is obtained from a PInvoke call to the AlphaBlend API, which is available starting from Windows CE version 5.0.
[DllImport("coredll.dll")]
extern publicstatic Int32 AlphaBlend(IntPtr hdcDest, Int32 xDest, Int32yDest, Int32 cxDest, Int32 cyDest, IntPtr hdcSrc, Int32 xSrc, Int32ySrc, Int32 cxSrc, Int32 cySrc, BlendFunction blendFunction);
The function is wrapped by the managed method DrawApha, which can be called as follows:
Drawing .DrawAlpha(e.Graphics, background, 180, 0, 0);
NOTE: the image “background” will be drawn with a transparency of 70% (=180/255).
As for the ImageButton,the customized message box has OnPaintBackground and OnPaint methodsoverridden, drawing a picture completely black semitransparent. Afterpainting the background image, the solid background image of themessage box is drawn using the technique of image transparency offeredby the Compact Framework. First you must create an instance of theclass ImageAttributes:
transparency = new ImageAttributes
Then you have to decide what color to make transparent, in this case we are using the Black:
transparency.SetColorKey(transparentColor, transparentColor);
NOTE:in .NET Framework, you can select a range of colors ranging from thefirst and the second parameter of the SetColorKey function. In the .NETCompact Framework instaed this is not possible, and the two parametersneed to be equal.
Finally you can draw the image using the following overload method of Graphics.DrawImage:
e.Graphics.DrawImage(background, rectangle, 0, 0, background.Width,background.Height, GraphicsUnit.Pixel, transparency);
Inthe case of our application, the final result is a background imagewith the edges rounded, while the rest of the screen is darker.
- 自定义MessageBox
- 自定义messagebox
- 自定义 MessageBox
- 自定义MessageBox
- [JavaScript]自定义MessageBox
- [JavaScript]自定义MessageBox
- 使用JS自定义MessageBox
- 自定义MessageBox----HOOK
- 自定义显示MessageBox
- 自定义MessageBox消息图标
- 自定义MessageBox消息图标 .
- Qt自定义MessageBox
- sencha touch自定义messageBox
- MFC自定义MessageBox
- WPF 自定义MessageBox
- 自定义一个MessageBox
- miniui自定义messageBox框
- Hook自定义MessageBox
- csdn论坛技术区平均给分功能
- CVS
- ORACLE WITH AS 用法
- [知识竞赛策划方案]那么如何用PPT制作知识竞赛所需要的题库?
- 将.net framework1.0的virtual directory转成1.1的
- 自定义MessageBox
- 09年大势已去,还需努力奋斗,思考之后。。。
- 加权平均资本成本(Weighted Average Cost of Capital,WACC)
- ASP.NET文件扩展名
- 汇编传送指令
- 公告:capi自今日起迁移到sourceforge.net里,改名为mcapi
- SVN(Subversion)
- 使用 Override 和 New 关键字进行版本控制(C# 编程指南)
- xsd教程1