[英]How to customize the controlbox of a winform in c#
我想用不同的背景和不同的按鈕圖像自定義Winform的控制箱。 我該怎么辦? 有什么方法可以使用usercontrol或類似的控件制作自定義控件框,然后將其添加到winform中?
您可以像這樣從UserControl
繼承來創建自己的自定義控件
class MyControl : System.Windows.Forms.Button //this could also have been System.Windows.Forms.UserControl or any other existing control type as a template
{
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
//Paint whatever you wish on this buttons graphics using e.Graphics
}
}
對自定義控件進行編程有很多內容。 這里有很多要回答的。 一個很好的參考是: http : //msdn.microsoft.com/en-us/library/6hws6h2t.aspx
您可以創建自己的Forms控件並隱藏父控件框。 或者,也許您可以從System.Windows.Form
繼承並創建一個自定義窗體。 但是我自己從來沒有嘗試過。
使用OnPaint時,如果您關心性能和/或閃爍,則必須牢記一些規則,例如: 在.Net應用程序中使用OnPaint的正確方法是什么?
使用.NET Framework手段對您沒有影響。 您必須為表單的非客戶區域實現自定義繪圖。 以下內容可能對您有幫助: http : //www.codeplex.com/wikipage ?ProjectName= CustomerBorderForm&title=Painting%20NonClient%20Area
我不知道我是否理解正確。 您要創建自己的控件嗎? 如果是,請嘗試以下操作:
更改:
public partial class MyCustomControl : Control { ... }
對於:
public partial class MyCustomControl : Form { ... }
更改:
public partial class MyForm : Form { ... }
對於:
public partial class MyForm : MyCustomControl { ... }
現在,您的MyForm就像MyCustomControl,您可以在所有項目中重復使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.