[经典] vb.net经典代码 show

landlordh 2004-12-07 02:29:51
你的codes有个性吗?
你的窗口精彩吗?
你的程式与众不同吗?
那么来吧,
这里,你可以show出你的个性,贴出你的精彩。

VB.NET经典代码show(主推控件重写,XP style[不要系统支持])

请各位大虾show出个性代码,供社区研究学习。
长度不限,put者有分,希望大家涌跃参与
show.........
...全文
1047 68 打赏 收藏 转发到动态 举报
写回复
用AI写文章
68 条回复
切换为时间正序
请发表友善的回复…
发表回复
yzg100 2005-05-11
  • 打赏
  • 举报
回复
如果在XP操作系统下,.NET来实现XP风格的控件很方便呀。
把下边的代码保存为<你的程序>.exe.manifest

<?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="CompanyName.ProductName.YourApp"

type="win32"

/>

<description>Your application description here.</description>

<dependency>

<dependentAssembly>

<assemblyIdentity

type="win32"

name="Microsoft.Windows.Common-Controls"

version="6.0.0.0"

processorArchitecture="X86"

publicKeyToken="6595b64144ccf1df"

language="*"

/>

</dependentAssembly>

</dependency>

</assembly>

然后把这个文件添加到程序的bin文件夹中,把窗体上的控件FlatStyle属性里有System,如Button,有些控件你加了这个文件后自动就是XP风格。然后运行试试,TabControl控件好漂亮哦。
不是XP系统的不要试,试了也出不来XP风格,就算你用第三方控件,也不会出来D。
yangrenhuai 2005-01-26
  • 打赏
  • 举报
回复
hao dong xi
xiaoqingren 2004-12-09
  • 打赏
  • 举报
回复
好厉害啊!学习一下!
landlordh 2004-12-09
  • 打赏
  • 举报
回复
很早以前重写的XP_button类
怎么使用:
在窗体中将System.Windows.Forms.Button改为XPCtrl.XPButton即可
Friend WithEvents Button10 As XPCtrl.XPButton
...
Me.Button10 = New XPCtrl.XPButton
-----------------------------------------------------------------

Imports System
Imports System.Windows
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Namespace XPCtrl
Public Class XPButton
Inherits System.Windows.Forms.Button
Private mouseover As Boolean = False
Public Sub New()
End Sub
Protected Overloads Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim c5 As Color = Color.FromArgb(255, 255, 255)
Dim c2 As Color = Color.FromArgb(192, 192, 192)
If mouseover Then
c5 = Color.FromArgb(245, 245, 245)
c2 = Color.FromArgb(180, 175, 190)
End If
Dim b As Brush = New System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle, c5, c2, LinearGradientMode.Vertical)
Dim offsetwidth As Integer = Me.Width / 50
Dim points(8) As Point
points(0).X = offsetwidth
points(0).Y = 0
points(1).X = Me.Width - offsetwidth
points(1).Y = 0
points(2).X = Me.Width
points(2).Y = offsetwidth
points(3).X = Me.Width
points(3).Y = Me.Height - offsetwidth
points(4).X = Me.Width - offsetwidth
points(4).Y = Me.Height
points(5).X = offsetwidth
points(5).Y = Me.Height
points(6).X = 0
points(6).Y = Me.Height - offsetwidth
points(7).X = 0
points(7).Y = offsetwidth
e.Graphics.FillPolygon(b, points, FillMode.Winding)
If Me.Focused Then
Dim offsetwidth1 As Integer = (Me.Width - 5) / 50 + 2
Dim points1(8) As Point
points1(0).X = offsetwidth1
points1(0).Y = 2
points1(1).X = Me.Width - offsetwidth1
points1(1).Y = 2
points1(2).X = Me.Width - 1
points1(2).Y = offsetwidth1
points1(3).X = Me.Width - 1
points1(3).Y = Me.Height - offsetwidth1
points1(4).X = Me.Width - offsetwidth1
points1(4).Y = Me.Height - 1
points1(5).X = 1
points1(5).Y = Me.Height - 1
points1(6).X = 2
points1(6).Y = Me.Height - offsetwidth1
points1(7).X = 2
points1(7).Y = offsetwidth1
Dim p As Pen = New Pen(Color.Orange, 2)
Dim p1 As Pen = New Pen(Color.Wheat, 2)
e.Graphics.DrawLine(p1, points1(0), points1(1))
e.Graphics.DrawLine(p, points1(1), points1(2))
e.Graphics.DrawLine(p, points1(2), points1(3))
e.Graphics.DrawLine(p, points1(3), points1(4))
e.Graphics.DrawLine(p, points1(4), points1(5))
e.Graphics.DrawLine(p, points1(5), points1(6))
e.Graphics.DrawLine(p1, points1(6), points1(7))
e.Graphics.DrawLine(p1, points1(7), points1(0))
End If
e.Graphics.DrawPolygon(New Pen(Color.DarkBlue, 2), points)
Dim drawFormat As StringFormat = New StringFormat
drawFormat.FormatFlags = StringFormatFlags.DisplayFormatControl
drawFormat.LineAlignment = StringAlignment.Center
drawFormat.Alignment = System.Drawing.StringAlignment.Center
Dim pf As PointF = New PointF(MyBase.Location.X, MyBase.Location.Y)
e.Graphics.DrawString(MyBase.Text, MyBase.Font, New LinearGradientBrush(Me.ClientRectangle, Color.Black, Color.Black, LinearGradientMode.Vertical), pf, drawFormat)

b.Dispose()
End Sub
Protected Overloads Overrides Sub OnMouseEnter(ByVal e As EventArgs)
mouseover = True
End Sub
Protected Overloads Overrides Sub OnNotifyMessage(ByVal m As System.Windows.Forms.Message)
MyBase.OnNotifyMessage(m)
End Sub
Protected Overloads Overrides Sub OnMouseLeave(ByVal e As EventArgs)
mouseover = False
End Sub
Protected Overloads Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
pevent.Graphics.Clear(Color.Wheat)
End Sub
End Class
End Namespace
moxili 2004-12-09
  • 打赏
  • 举报
回复
顶,不过这里为什么不能提问啊,我有些问题但不知为什么,不能提问
badboy308 2004-12-09
  • 打赏
  • 举报
回复
是呀,代码的书写要规范
landlordh 2004-12-09
  • 打赏
  • 举报
回复
没空来看就沉下了呀
windforce151515 2004-12-08
  • 打赏
  • 举报
回复
好强啊.....NX
yikais 2004-12-08
  • 打赏
  • 举报
回复
BloodPhenix 2004-12-08
  • 打赏
  • 举报
回复
简单一点的控件重写:
在Textbox产生gotfocus事件时先执行背景变色,再发送gotfocus事件给控件用户。
主要学习Overrides子句以及认识基类的事件生成的方法

Public Class Tr_text
Inherits System.Windows.Forms.TextBox

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()
MyBase.New()

'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'UserControl1 重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'Tr_text
'
Me.Name = "Tr_text"

End Sub

#End Region
Protected Overrides Sub OnGotFocus(ByVal e As EventArgs)
Me.BackColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(255, Byte), CType(255, Byte))
MyBase.OnGotFocus(e)
End Sub

Protected Overrides Sub OnLostFocus(ByVal e As EventArgs)
Me.BackColor = Color.White
MyBase.OnLostFocus(e)
End Sub
End Class
深山老翁 2004-12-08
  • 打赏
  • 举报
回复
学习了!
兔子-顾问 2004-12-08
  • 打赏
  • 举报
回复
我也来一个实用的,大家需要就看看。
功能:在指定的区域花一个矩形,鼠标拖动显示矩形框的。
测试方法:新建一个vb.net的windows application 工程,放一个panel控件,复制如下代码。可以测试了。必要的时候,把csdn提供的标点符号替换成半角或删除空格换行

Private StartPoint, EndPoint As New Point '保存鼠标移动的起始点和结束点
Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown '鼠标按下记录起始点
StartPoint.X = e.X
StartPoint.Y = e.Y
End Sub

Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
If Not e.Button = MouseButtons.Left Then Exit Sub '鼠标移动,如果左键按下,则花一个临时的图形表示用户当前鼠标框选范围
Panel1.Refresh()
EndPoint.X = e.X
EndPoint.Y = e.Y
Dim x1, x2, y1, y2 As Int16
If EndPoint.X < StartPoint.X Then
x1 = EndPoint.X
x2 = StartPoint.X
Else
x2 = EndPoint.X
x1 = StartPoint.X
End If
If EndPoint.Y < StartPoint.Y Then
y1 = EndPoint.Y
y2 = StartPoint.Y
Else
y2 = EndPoint.Y
y1 = StartPoint.Y
End If
Dim g As Graphics
Dim pen As New Pen(Color.Black)
Dim w As Int16 = x2 - x1
Dim h As Int16 = y2 - y1
Dim rect As New Rectangle(x1, y1, w, h)
g = Panel1.CreateGraphics()
g.DrawRectangle(pen, rect)
End Sub



Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp '例子松开鼠标会花一个以短边为边长的正方形
Me.Refresh() '因为用的是panel,区域不大,可以用refresh刷新掉之前的图形再花新的
'如果区域大,可以参考区域更新
EndPoint.X = e.X '保存结束点
EndPoint.Y = e.Y
If EndPoint.X < StartPoint.X Then '计算大小,保证绘制矩形的长宽是正数
Dim t As Int16
t = StartPoint.X
StartPoint.X = EndPoint.X
EndPoint.X = t
End If
If EndPoint.Y < StartPoint.Y Then
Dim t As Int16
t = StartPoint.Y
StartPoint.Y = EndPoint.Y
EndPoint.Y = t
End If
Dim g As Graphics '规则的GDI+绘制矩形的步骤
Dim pen As New Pen(Color.Black)
Dim w As Int16 = EndPoint.X - StartPoint.X
Dim h As Int16 = EndPoint.Y - StartPoint.Y
Dim rect As New Rectangle(StartPoint.X, StartPoint.Y, w, h)
If w > h Then
rect = New Rectangle(StartPoint.X, StartPoint.Y, h, h)
Else
rect = New Rectangle(StartPoint.X, StartPoint.Y, w, w)
End If
g = Panel1.CreateGraphics()
g.DrawRectangle(pen, rect)
GR.Ephemeris(Panel1, g, True, rect)
End Sub
NingFeiyang 2004-12-08
  • 打赏
  • 举报
回复
ding
WJY2003 2004-12-08
  • 打赏
  • 举报
回复
顶!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
hebookboy 2004-12-08
  • 打赏
  • 举报
回复
好贴收藏
NTMDQUSI 2004-12-08
  • 打赏
  • 举报
回复
路過
gxh973121 2004-12-08
  • 打赏
  • 举报
回复
jf
ls_hndd 2004-12-08
  • 打赏
  • 举报
回复
这种经典?晕!
mqmmx 2004-12-08
  • 打赏
  • 举报
回复
学习
longqiaoman 2004-12-08
  • 打赏
  • 举报
回复
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;

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

namespace SuperControls
{
/// <summary>
/// ComboBoxWithIcon 的摘要说明。
/// </summary>
public class ComboBoxWithIcon : ComboBox
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public ComboBoxWithIcon(System.ComponentModel.IContainer container)
{
///
/// Windows.Forms 类撰写设计器支持所必需的
///
container.Add(this);
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

public ComboBoxWithIcon()
{
///
/// Windows.Forms 类撰写设计器支持所必需的
///
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}


#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// ComboBoxWithIcon
//
this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;

}
#endregion

#region "内部变量"
private ImageList m_imgList;
private Color m_clrSelected=Color.SteelBlue;
#endregion

#region "属性"
[Category("自定义属性")]
[Description("图像列表控件")]
public ImageList ImageList
{
get
{
return m_imgList;
}
set
{
m_imgList=value;
}
}

[Category("自定义属性")]
[Description("选择时的背景颜色")]
public Color SelectedColor
{
get
{
return m_clrSelected;
}
set
{
m_clrSelected=value;
}
}
#endregion

#region "重写方法"
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
{
if(m_imgList==null || this.Enabled==false)
return;

try
{
Graphics g = e.Graphics ;
Rectangle r = e.Bounds ;
Size imageSize = m_imgList.ImageSize;
if ( e.Index >= 0 )
{
string s = this.Items[e.Index].ToString();
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;

Color backColor,foreColor;

if ( (e.State & DrawItemState.Selected) == DrawItemState.Selected )
{
backColor=m_clrSelected;
foreColor=Color.White;
}
else
{
backColor=this.BackColor;
foreColor=Color.Black;
}

//画条目背景
e.Graphics.FillRectangle(new SolidBrush(backColor) , r);
//绘制图像
if(m_imgList.Images.Count>e.Index)
m_imgList.Draw(e.Graphics, r.Left, r.Top+(r.Height-imageSize.Height)/2,e.Index);
else
m_imgList.Draw(e.Graphics, r.Left, r.Top+(r.Height-imageSize.Height)/2,0);

//显示字符串
e.Graphics.DrawString( s , this.Font , new SolidBrush(foreColor), r.Left+imageSize.Width ,r.Top+2);
//显示取得焦点时的虚线框
e.DrawFocusRectangle();
}
}
catch
{
}
base.OnDrawItem (e);
}
#endregion
}
}
加载更多回复(47)

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧