急: 如何使用c#自定义Windows Forms窗体外观???!!!

syinter 2002-11-10 02:39:51
相信大家都用过MediaPlayer 7/8/9,我要的效果就要像WM换了皮肤后那样!!!

如何实现那种不规则外观的窗口呢

高手一定要指点一二,越详细越好!!!!

(BTW: 我看完<<C#高级编程>>和<<Windows Forms高级编程>>后仍然没有个具体的概念,大概只知道要继承System.Windows.Forms ...)
...全文
133 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qaqaqa 2002-11-10
  • 打赏
  • 举报
回复
我自己做的控件。。、清你试用。。。www.chinadeer.com/c.zip
visualcpu 2002-11-10
  • 打赏
  • 举报
回复
mark
saucer 2002-11-10
  • 打赏
  • 举报
回复
Shaped Windows Forms and Controls in Visual Studio .NET
http://msdn.microsoft.com/library/en-us/dv_vstechart/html/vbtchshapedwindowsformscontrolsinvisualstudionet.asp?frame=true

NonRectangular Forms
http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=417
syinter 2002-11-10
  • 打赏
  • 举报
回复
谢谢各位,我通过MSDN文档已经掌握了做法,谢谢saucer!!
yqjyn 2002-11-10
  • 打赏
  • 举报
回复
我这里有一个vb.net 写的例子你可以参考一下!
Imports System.Drawing.Drawing2D
Public Class Form2
Inherits System.Windows.Forms.Form
Private IsDraging As Boolean = False 'Varible for draging from
Private lCurX, lCurY As Long 'needed for current x, y values
Private WithEvents tTimer As Timer = New Timer() 'setup timer (no need for a formcontrol)
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
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

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
Me.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
Me.ClientSize = New System.Drawing.Size(272, 150)
Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.Name = "Form2"
Me.Text = "Form2"

End Sub

#End Region

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'avvio in un altro thread la costruzione della grafica
'Dim t2 As System.Threading.Thread = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf drawScocca))
't2.Start()
drawScocca()
End Sub

Private Sub drawScocca()
Dim Path As New GraphicsPath()

Dim g As Graphics = Me.CreateGraphics
Dim b As New Bitmap("scocca.gif")

Dim x, y, i As Long
Dim rect As Rectangle

Dim colorFirst As Color = b.GetPixel(1, 1)
For x = 0 To b.Width - 1
For y = 0 To b.Height - 1
If b.GetPixel(x, y).Equals(colorFirst) Then
'non lo disegno perch?devo fare la trasparenza
Else
rect = New Rectangle(x, y, 1, 1)
Path.AddRectangle(rect)
End If
Next y
Next x

Me.Region = New Region(Path)
End Sub


Private Sub Form2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim g As Graphics = Me.CreateGraphics
Dim b As New Bitmap("scocca.gif")

g.DrawImage(b, 0, 0, b.Width, b.Height)
g.Dispose()
End Sub

Private Sub Form2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
lCurX = e.X : lCurY = e.Y 'Set the Current x and y values
IsDraging = True 'Begin Draging Form
tTimer.Enabled = True 'Enable Drag Timer
End Sub

Private Sub tTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tTimer.Tick
'Checks the state of the mouseevent and moves form Accordingly
If IsDraging = True Then
'Move the form accordingly to cursor x, y positions (minus) the current form x, y positions
Dim curxx As Integer = Cursor.Position.X
Dim curyy As Integer = Cursor.Position.Y
Me.SetDesktopLocation(curxx - lCurX, curyy - lCurY)
End If
'tTimer.Enabled = False 'Cancel timer, no longer needed
End Sub

Private Sub Form2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
IsDraging = False 'No Longer Moving Form
tTimer.Enabled = False 'Cancel Timer
End Sub
End Class
自定义窗体的最大化、最小化和关闭按钮, C#移动无标题栏窗体的三种代码: C#移动无标题栏窗体的三种代码:第一种采用,需注意窗体上的控件是否把窗体覆盖了。。。MouseDown、MouseMove、MouseUp事件应该是鼠标所处位置最顶层的控件的事件 在窗体的类中声明两个变量 private Point mouseOffset; //记录鼠标指针的坐标 private bool isMouseDown = false; //记录鼠标按键是否按下 创建该窗体 MouseDown、MouseMove、MouseUp事件的相应处理程序 private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { int xOffset; int yOffset; if (e.Button == MouseButtons.Left) { xOffset = -e.X ; yOffset = -e.Y ; mouseOffset = new Point(xOffset, yOffset); isMouseDown = true; } } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (isMouseDown) { Point mousePos = Control.MousePosition; mousePos.Offset(mouseOffset.X, mouseOffset.Y); Location = mousePos; } } private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { // 修改鼠标状态isMouseDown的值 // 确保只有鼠标左键按下并移动时,才移动窗体 if (e.Button == MouseButtons.Left) { isMouseDown = false; } } 第二种调用API 未验证 using System.Runtime.InteropServices; [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); public const int WM_SYSCOMMAND = 0x0112; public const int SC_MOVE = 0xF010; public const int HTCAPTION = 0x0002; private void Form1_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } 第三种未验证 private bool isMouseDown = false; private Point FormLocation; //form的location private Point mouseOffset; //鼠标的按下位置 [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); private const int WM_SYSCOMMAND = 0x0112;//点击窗口左上角那个图标时的系统信息 private const int SC_MOVE = 0xF010;//移动信息 private const int HTCAPTION = 0x0002;//表示鼠标在窗口标题栏时的系统信息 private const int WM_NCHITTEST = 0x84;//鼠标在窗体客户区(除了标题栏和边框以外的部分)时发送的消息 private const int HTCLIENT = 0x1;//表示鼠标在窗口客户区的系统消息 private const int SC_MAXIMIZE = 0xF030;//最大化信息 private const int SC_MINIMIZE = 0xF020;//最小化信息 protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_SYSCOMMAND: if (m.WParam == (IntPtr)SC_MAXIMIZE) { m.WParam = (IntPtr)SC_MINIMIZE; } break; case WM_NCHITTEST: //如果鼠标移动或单击 base.WndProc(ref m);//调用基类的窗口过程——WndProc方法处理这个消息 if (m.Result == (IntPtr)HTCLIENT)//如果返回的是HTCLIENT { m.Result = (IntPtr)HTCAPTION;//把它改为HTCAPTION return;//直接返回退出方法 } break; } base.WndProc(ref m);//如果不是鼠标移动或单击消息就调用基类的窗口过程进行处理 } private void Form1_Load(object sender, EventArgs e) { } ------------------------------- 如何在窗体标题栏左边的控制菜单加入自己的菜单啊? 我们一般在窗口标题栏点右键 或 按Alt+空格 可以弹出那个菜单。 ------解决方案-------------------- using System.Runtime.InteropServices; [DllImport( "user32.dll ")] public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert); [DllImport( "user32.dll ")] public static extern bool InsertMenu(IntPtr hMenu, uint uPosition, uint uFlags, uint uIDNewItem, string lpNewItem); public const int MF_BYCOMMAND = 0; public const int MF_STRING = 0; public const int MF_BYPOSITION = 0x400; public const int MF_SEPARATOR = 0x800; private const uint SC_ABOUT = 0x0001; public const int WM_SYSCOMMAND = 0x0112; private void Form1_Load(object sender, EventArgs e) { IntPtr vMenuHandle = GetSystemMenu(Handle, false); InsertMenu(vMenuHandle, 255, MF_STRING, SC_ABOUT, "About... "); } protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_SYSCOMMAND: if ((uint)m.WParam == SC_ABOUT) { MessageBox.Show( "Zswang 路过! "); } break; } base.WndProc(ref m); }

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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