發表文章

目前顯示的是有「WinForm」標籤的文章

[C#]WinForm Label 透明底色

C#的Winform不支援底色透明的Label(Button也一樣) 雖然在物件屬性上可以選擇底色為透明,但其透明仍以Winform底色為主(Label透明=Winform的顏色) 所以 參考了人家的做法 ,在此做了紀錄,並加上詳細的使用方式 1.在專案上新增類別(類別名稱:TransparentLabel ),將下列程式碼貼上 2.在Form設計模式底下點選工具箱,即會出現該類別所產生的Label,將其拖拉到Form上 3.修改該物件的屬性(跟一般使用Label一樣) 4.注意一點,只要Label的背景有變,就要執行 Refesh() 有空再來做範例 ==========在專案上新增類別(類別名稱:TransparentLabel ),將下列程式碼貼上======= using System; using System.Drawing; using System.Windows.Forms; namespace WinFormsControls { /// /// A label that can be transparent. /// public class TransparentLabel : Control { /// /// Creates a new instance. /// public TransparentLabel() { TabStop = false; } /// /// Gets the creation parameters. /// protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x20; return cp; } } /// /// Paints the background. /// /// E. protected override void OnPaintBackgr...

[C#]Listbox的上移、下移、左移、右移

圖片
話說,Vb.Net轉C#真的不是加個大誇號和分號就搞定,有些物件的屬性還不盡相同。趁有時間練習一下C#的一些物件使用,並在此做一下紀錄。 由於感冒藥吃下去快陣亡,所以就廢話不多說,首先是介面的示意畫面,下方是程式碼。 程式碼內都有註解~有需要的朋友可以參考,這個包含了多筆選擇的操控。 /// /// 表單開啟 /// private void Select_Item_Load(object sender, EventArgs e) { //給ListBox值 for (int i = 0; i < 10; i++) { this.listBox1.Items.Add("★" + i); } //調整listbox為可多選 listBox1.SelectionMode = SelectionMode.MultiExtended; listBox2.SelectionMode = SelectionMode.MultiExtended; } /// /// listbox所選項目向右移 /// private void button_right_Click(object sender, EventArgs e) { // '檢查有沒有選取項目 if (listBox1.SelectedIndices.Count > 0) { //由於被移動後所選取的數量會改變,所以要先放在暫存器內 int selectedCount = listBox1.SelectedIndices.Count; //用for迴圈由小到大去巡覽 for (int i ...