C#圓形頭像框制作并從數(shù)據(jù)庫讀取
現(xiàn)在只要是有關(guān)頭像的框基本都是圓形的了,C#提供的PictureBox控鍵默認情況下是方形的非常大的影響美觀

PictureBox默認情況下

比起上面的還是有一點不太好看的…
使用C#提供的類進行圓形:
工具箱拉出PictureBox

設置圖片的顯示模式為ZOOM

特別注意:
框的比例必須為一樣不然會變橢圓的

窗體加載時:
pictureBox1.Image = Image.FromFile(@"C:\Users\Administrator\Desktop\1.png");
為了方便演示,在窗口加載的時候加載出圖片

圖片加載出來后然后,把框框變圓的
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(pictureBox1.ClientRectangle);
Region region = new Region(gp);
pictureBox1.Region = region;//賦值
gp.Dispose();//釋放資源
region.Dispose();//釋放資源
只有簡單的幾行
效果圖:

一下美觀了很多
接下來演示從數(shù)據(jù)庫讀取圖片到框框上:
同樣也是,寫在窗口的加載事件
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(pictureBox1.ClientRectangle);
Region region = new Region(gp);
pictureBox1.Region = region;
gp.Dispose();
region.Dispose();
CheckForIllegalCrossThreadCalls = false;
username.Text = 登錄界面.jmuser;
Thread th = new Thread(a);
th.IsBackground = true;
th.Start();
us = username.Text;
首頁 form = new 首頁();
form.TopLevel = false;
form.Parent = panel1;
panel1.Controls.Add(form);//將子窗體載入panel
form.Show();
SqlConnectionStringBuilder bu = new SqlConnectionStringBuilder();
bu.Password = "0";
bu.UserID = "0";
bu.DataSource = "0-0";
bu.InitialCatalog = "0";
SqlConnection b = new SqlConnection(bu.ToString());
string str = "select * from user1 where username ='" + 登錄成功界面.us + "'";
b.Open();
SqlCommand c = new SqlCommand(str, b);
SqlDataReader d = c.ExecuteReader();
while (d.Read())
{
// label2.Text = d["userid"].ToString();
string s = d["頭像"].ToString();
byte[] imageBytes = Convert.FromBase64String(s);
MemoryStream memoryStream = new MemoryStream(imageBytes, 0, imageBytes.Length);
memoryStream.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(memoryStream);
this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
this.pictureBox1.Image = image;
}
}
效果圖:

圖片是從數(shù)據(jù)庫讀取的,并不是本地上傳的?。?/p>
到此這篇關(guān)于C#圓形頭像框制作并從數(shù)據(jù)庫讀取的文章就介紹到這了,更多相關(guān)C#圓形頭像框制作 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
WinForm中變Enter鍵為Tab鍵實現(xiàn)焦點轉(zhuǎn)移的方法
這篇文章主要介紹了WinForm中變Enter鍵為Tab鍵實現(xiàn)焦點轉(zhuǎn)移的方法,主要通過一個ControlTools類來實現(xiàn)該功能,需要的朋友可以參考下2014-08-08
C#如何實現(xiàn)對sql server數(shù)據(jù)庫的增刪改查
本文的主要內(nèi)容是C#實現(xiàn)對sql server數(shù)據(jù)庫的增刪改查,示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-08-08
c# 使用特定帳號密碼訪問Windows網(wǎng)路共享
這篇文章主要介紹了c# 使用特定帳號密碼訪問Windows網(wǎng)路共享的方法,幫助大家更好的理解和學習使用c#,感興趣的朋友可以了解下2021-03-03

