• 全部
  • VBS
  • .NET技术
  • VBA
  • VB网络编程
  • VB多媒体
  • VB数据库
  • VB控件
  • VB COM/DCOM
  • VB基础类
  • VB API
  • 问答

30分求一个xp风格的form

jiangyuedong 2005-03-04 07:47:42
请问各位高人,我想自定义一个xp风格的控件,不知哪位能予以帮助,急急急急急急急急急
...全文
172 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
haoztao 2005-04-08
去网上下载吧,那上面有很多啊!呵呵
回复
bob008 2005-04-08
哎,晕,VB6写的自绘窗体源码要不要,你改下数据类型就可以了
回复
chenhui530 2005-04-07
这是篇VB.NET希望对你有帮助

拥有xp风格的界面
Windows XP发布时,我们中许多人都为她华丽漂亮的界面折服和兴奋。然而,.NET1.0发布时,我们中又有许多人,包括我自己,对它不支持XP风格感到大失所望。可事实是,在Windows XP(只限于WindowsXP)里.NET支持XP风格,只是还要您做一点小工作。

这篇文章主要参考了http://www.codeproject.com/csharp/dotnetvisualstyles.asp
跟随下面的步骤,使您的程序拥有XP风格的界面,GO!

1. 新建一个Windows应用程序,然后打开AssemblyInfo.cs,修改一下内容,下面的是示例代码:
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyTitle("abc")]
[assembly: AssemblyDescription("abc")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

2. 往项目添加新项。新添加一个XML文件,将文件命名为 [您的程序名].exe.manifest,[您的程序名]指的是在 ..\bin\debug 文件夹里生成的可执行程序名 。文件的内容示例如下:您只要根据您在AssemblyInfo.cs里所作的设置修改 version="1.0.0.0", name="abc", <description>abc</description> 这几个值就可以了。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly
xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="abc"
type="win32" />
<description>abc</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>
</assembly>

重新编译程序。 注意,从ButtonBase,GroupBox和Label继承下来的组件必须将FlatStyle属性设为System。

3. 将 [您的程序名].exe.manifest 文件添加到程序的可执行文件

(1)菜单-->文件-->打开,打开..\bin\debug\[您的程序名].exe,现在您可以看到一个资源浏览树;
(2)右击根目录[您的程序名],单击"添加资源...";
(3)在跳出的对话框中单击“自定义...”;
(4)将资源类型命名为RT_MANIFEST,确定;
(5)双击资源树的RT_MANIFEST下的项(一般情况下是101),Copy 文件 [您的程序名].exe.manifest 的内容,粘贴在打开的文件中,粘贴的结果是二进制形式(结果有点奇怪,不用理会);
(6)保存,然后将101项的ID改为1,再保存。注意,不要重新对程序进行编译。

现在,重新打开您的程序,怎么样,界面应该不错吧。

原理:
问题的关键在于comctl32.dll。您搜索一下您的计算机,将发现有两个comctl32.dll。组件的外观就与这两个DLL中的特定资源相联系,它们提供特定的资源用于组件客户区域的绘制。对于继承于ButtonBase,GroupBox和Label的组件,将它们的FlatStyle属性设为System的目的也是为了让系统对组件进行绘制。
默认情况下,系统将使用..\Windows\System32目录下的DLL,您需要做的工作就是告诉系统使用另一个DLL,这就是将 [您的程序名].exe.manifest 文件 添加到可执行文件的目的。
下面是支持XP风格的组件完整列表:
Label,TextBox, RichTextBox, HScrollBox, VScrollBox, ProgressBar, TabControl, MainMenu, ComboBox, ContextMenu, DataGrid, ListBox, ListView, TreeView, DataTimePicker, MonthCalendar, Splitter,TrackBar, StatusBar, ToolBar
回复
jshyjyw 2005-03-07
#C的风格看不懂啊,有VB的吗?谢谢。
回复
jiangyuedong 2005-03-04
请问 landlordh(software) 有制作xp风格的脚本吗 拜托了
回复
hamadou 2005-03-04
这里是一个xp风格的按钮的c#代码,窗体的修改是类似的。希望能给你些帮助。

using System;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;

namespace OwnDrawButton2
{
public class MyButton : System.Windows.Forms.Button
{
//state variable for mouse down
private bool mouseDown=false;

//state variable for mouse hover
private bool mouseHover=false;

public MyButton()
{
//set the control UserPaint
SetStyle(ControlStyles.UserPaint,true);

//EventHandler for MouseDown
MouseDown+=new MouseEventHandler(OnMouseDown);

//EventHandler for MouseUp
MouseUp+=new MouseEventHandler(OnMouseUp);

//EventHandler for MouseEnter
MouseEnter+=new EventHandler(OnMouseEnter);

//EventHandler for MouseLeave
MouseLeave+=new EventHandler(OnMouseLeave);

Height=23;//Default Height
Width=75;//Default Width
}

protected override void OnPaint(PaintEventArgs pe)
{
//first, paint the control with parent form's background color
pe.Graphics.FillRectangle(new SolidBrush(Parent.BackColor),
pe.ClipRectangle);

//if the button is disabled, draw the disable style
if (Enabled == false)
{
DrawDisableButton(pe.Graphics);
}
else if (mouseDown)
{
//when mouse down, draw the mouse down style
DrawMouseDownButton(pe.Graphics);
}
else if (mouseHover)
{
//when mouse hover, draw the mouse hover style
DrawMouseHoverButton(pe.Graphics);
}
else if (Focused)
{
//when mouse is focused but not mouse hover,
//draw the focus style
DrawContainFocusButton(pe.Graphics);
}
else//else, draw the normal style
{
DrawNormalButton(pe.Graphics);
}
WriteText(pe.Graphics);//write text
}
private void OnMouseDown(object sender,MouseEventArgs e)
{
mouseDown=true; //mouse is down now
}

private void OnMouseUp(object sender,MouseEventArgs e)
{
mouseDown=false; //mouse is up now

//call paint action
PaintEventArgs pe =
new PaintEventArgs(CreateGraphics(),ClientRectangle);

OnPaint(pe);
}

private void OnMouseEnter(object sender,EventArgs e)
{
mouseHover=true; //mouse hover on

//call paint action
PaintEventArgs pe =
new PaintEventArgs(CreateGraphics(),ClientRectangle);

OnPaint(pe);
}

private void OnMouseLeave(object sender,EventArgs e)
{
mouseHover=false; //mouse is not hover on

//call paint action
PaintEventArgs pe =
new PaintEventArgs(CreateGraphics(),ClientRectangle);

OnPaint(pe);
}

private void DrawBorder(Graphics g,int state)
{
if (state==1)//draw normal style broder
{
Pen p = new Pen(SystemColors.ControlLightLight,2);
g.DrawLine(p,1,1,1,Height-2);
g.DrawLine(p,1,1,Width-2,1);
g.DrawLine(p,Width-1,2,Width-1,Height-2);
g.DrawLine(p,2,Height-1,Width-2,Height-1);
}
else if (state==2)//draw hover style border
{
Pen p = new Pen(Color.Yellow,2);
g.DrawLine(p,1,1,1,Height-2);
g.DrawLine(p,1,1,Width-2,1);
g.DrawLine(p,Width-1,2,Width-1,Height-2);
g.DrawLine(p,2,Height-1,Width-2,Height-1);
}
else if (state==3)//draw pressed style border
{
Pen p = new Pen(SystemColors.ControlDark,2);
g.DrawLine(p,1,1,1,Height-2);
g.DrawLine(p,1,1,Width-2,1);
g.DrawLine(p,Width-1,2,Width-1,Height-2);
g.DrawLine(p,2,Height-1,Width-2,Height-1);
}
else if (state==4)//draw disabled style border
{
Pen p = new Pen(SystemColors.ControlLight,2);
g.DrawLine(p,1,1,1,Height-2);
g.DrawLine(p,1,1,Width-2,1);
g.DrawLine(p,Width-1,2,Width-1,Height-2);
g.DrawLine(p,2,Height-1,Width-2,Height-1);
}
else if (state==5)//draw default style border
{
Pen p = new Pen(Color.SkyBlue,2);
g.DrawLine(p,1,1,1,Height-2);
g.DrawLine(p,1,1,Width-2,1);
g.DrawLine(p,Width-1,2,Width-1,Height-2);
g.DrawLine(p,2,Height-1,Width-2,Height-1);
}
if (state==4)//draw disable style border
{
Pen p = new Pen(Color.FromArgb(161,161,146),1);
g.DrawLine(p,0,2,0,Height-3);
g.DrawLine(p,2,0,Width-3,0);
g.DrawLine(p,Width-1,2,Width-1,Height-3);
g.DrawLine(p,2,Height-1,Width-3,Height-1);
g.DrawLine(p,0,2,2,0);
g.DrawLine(p,0,Height-3,2,Height-1);
g.DrawLine(p,Width-3,0,Width-1,2);
g.DrawLine(p,Width-3,Height-1,Width-1,Height-3);
}
else//draw normal style border
{
g.DrawLine(Pens.Black,0,2,0,Height-3);
g.DrawLine(Pens.Black,2,0,Width-3,0);
g.DrawLine(Pens.Black,Width-1,2,Width-1,Height-3);
g.DrawLine(Pens.Black,2,Height-1,Width-3,Height-1);
g.DrawLine(Pens.Black,0,2,2,0);
g.DrawLine(Pens.Black,0,Height-3,2,Height-1);
g.DrawLine(Pens.Black,Width-3,0,Width-1,2);
g.DrawLine(Pens.Black,Width-3,Height-1,
Width-1,Height-3);
}
}

private void DrawNormalButton(Graphics g)//draw normal style button
{
//draw normal style border
DrawBorder(g,1);

//paint background
PaintBack(g,SystemColors.ControlLightLight);
}

private void DrawMouseHoverButton(Graphics g)
{
//draw mouse hover style border
DrawBorder(g,2);

//paint background
PaintBack(g,SystemColors.ControlLightLight);
}

private void DrawMouseDownButton(Graphics g)
{
//draw mouse down style border
DrawBorder(g,3);

//paint background
PaintBack(g,SystemColors.ControlLight);
}

private void DrawDisableButton(Graphics g)
{
//draw disable style border
DrawBorder(g,4);

//paint background
PaintBack(g,SystemColors.ControlLight);
}

private void DrawContainFocusButton(Graphics g)
{
//draw contain focuse style border
DrawBorder(g,5);

//paint background
PaintBack(g,SystemColors.ControlLightLight);
}

//paint background area of the button
private void PaintBack(Graphics g,Color c)
{
g.FillRectangle(new SolidBrush(c),3,3,
Width-6,Height-6);
}

private void WriteText(Graphics g)
{
//calculate the text position
int x=0,y=0;
Size s = g.MeasureString(Text,Font).ToSize();
x=(Width-s.Width)/2;
y=(Height-s.Height)/2;

//draw text
if (Enabled) //is enabled, draw black text
g.DrawString(Text,Font,Brushes.Black,x,y);
else //not enabled, draw gray text
g.DrawString(Text,Font,Brushes.Gray,x,y);
}
}
}

3、在新控件的构造函数中添加:拖3个按钮到Form1上,将其中一个的"Enable"设为"false",右击鼠标,单击"View Code",在代码中用"MyButton"替换掉"System.Windows.Forms.Button";
4、编译执行。
最终,我们就得到了如图2所示的按钮控件。它可以在任何版本的windows操作系统上都保持一个样子。
回复
landlordh 2005-03-04
eg.

http://blog.csdn.net/landlordh/archive/2005/03/03/309755.aspx

XP BUTTON控件
回复
发帖
VB
创建于2007-09-28

1.6w+

社区成员

VB技术相关讨论,主要为经典vb,即VB6.0
申请成为版主
帖子事件
创建了帖子
2005-03-04 07:47
社区公告
暂无公告