c# picturebox控件的使用方法介绍
以TIM軟件為例,“微信登陸”圖標(biāo)默認(rèn)顯示為灰色。
鼠標(biāo)移動(dòng)到圖標(biāo),“預(yù)覽”顯示的圖標(biāo)變化為高亮狀態(tài)。
點(diǎn)擊登陸圖標(biāo),登陸圖標(biāo)高亮顯示。再次移動(dòng)鼠標(biāo),不發(fā)生“預(yù)覽”變化效果。
下面使用c#語(yǔ)言編程,說明實(shí)現(xiàn)過程:
1、打開VS2012軟件,新建一個(gè)窗體應(yīng)用程序;
2、“公共控件”,選擇“picturebox”控件,拖動(dòng)到窗體。
? ?? ??
3、選擇“picturebox”控件,image屬性,添加兩張本地圖片,默認(rèn)顯示為灰色圖片(未選中狀態(tài))
? ? ? 圖片可以從“阿里巴巴矢量庫(kù)網(wǎng)站下載”網(wǎng)址:iconfont-阿里巴巴矢量圖標(biāo)庫(kù),搜索“收藏”即可獲取各種類型的收藏圖標(biāo),選擇喜歡的圖片,以png格式下載即可。
4、選擇“picturebox”控件,在事件中添加“MouseMove”鼠標(biāo)移動(dòng)到圖標(biāo)函數(shù)、“MouseLeave”鼠標(biāo)離開圖標(biāo)函數(shù)。如下所示添加代碼。
? ? ? 可以實(shí)現(xiàn),未選中狀態(tài)下,鼠標(biāo)移動(dòng)到圖標(biāo)出現(xiàn)的“高亮”顯示效果。
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
? ? ? ? {
? ? ? ? ? ? pictureBox1.Image = Properties.Resources.blue;
? ? ? ? }
? ? ? ? private void pictureBox1_MouseLeave(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? ? ? pictureBox1.Image = Properties.Resources.gray;
? ? ? ? }
?5、添加一個(gè)布爾型的變量,緩存是否選中狀態(tài),
? ? ? 添加,如下代碼。實(shí)現(xiàn)未選中狀態(tài)才出現(xiàn)預(yù)覽效果。
?public partial class Form1 : Form
? ? {
? ? ? ? bool Bcollect = false;
? ? ? ? public Form1()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? }
? ? ? ? private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
? ? ? ? {
? ? ? ? ? ? pictureBox1.Image = Properties.Resources.blue;
? ? ? ? }
? ? ? ? private void pictureBox1_MouseLeave(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? if (!Bcollect)
? ? ? ? ? ? ? ? pictureBox1.Image = Properties.Resources.gray;
? ? ? ? }
6、雙擊“picturebox”控件,添加單擊觸發(fā)函數(shù)。
? ? 如果鼠標(biāo)左鍵點(diǎn)擊“picturebox”控件,“收藏”功能選中狀態(tài)變化,同時(shí)切換顯示圖標(biāo)。
? ? ? ? private void pictureBox1_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? if (!Bcollect)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Bcollect = true;
? ? ? ? ? ? ? ? pictureBox1.Image = Properties.Resources.blue;
? ? ? ? ? ? }
? ? ? ? ? ? else if (Bcollect)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Bcollect = false;
? ? ? ? ? ? ? ? pictureBox1.Image = Properties.Resources.gray;
? ? ? ? ? ? }
? ? ? ? }
9、視頻教程連接:
c#Picturebox控件的使用方法介紹-C#文檔類資源-CSDN下載
c#picturebox控件的使用方法介紹-C#文檔類資源-CSDN下載
總結(jié)
以上是生活随笔為你收集整理的c# picturebox控件的使用方法介绍的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 常见的PCA、tSNE、UMAP降维及聚
- 下一篇: C#笔记-PictureBox.Size