-
大小: 43KB文件類型: .rar金幣: 2下載: 0 次發布日期: 2021-05-14
- 語言: C#
- 標簽:
資源簡介
c#單擊按鈕、滑輪滾動放大、縮小pictruebox中的圖片,并且pictruebox里的圖片可以拖動,而且圖片被放大或縮小到一定的程度不會報錯

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Drawing.Drawing2D;
namespace?WindowsFormsApplication1
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????????this.MouseWheel?+=?new?MouseEventHandler(Form1_MouseWheel);
????????}
????????///?
????????///?圖片導入
????????///?
????????///?
????????///?
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????System.Windows.Forms.OpenFileDialog?of?=?new?OpenFileDialog();
????????????of.ShowDialog();
????????????if?(of.FileName?==?null)?return;
????????????pictureBox1.Image?=?Image.FromFile(of.FileName);
????????????_bitmap?=?new?Bitmap(pictureBox1.Image);
????????}
????????///?
????????///?滑輪滾動圖片放大、縮小
????????///?
????????///?
????????///?
????????private?void?Form1_MouseWheel(object?sender?MouseEventArgs?e)
????????{
????????????var?t?=?pictureBox1.Image.Size;
????????????t.Width?+=?e.Delta;
????????????t.Height?+=?e.Delta;
????????????if?(t.Width?0?||?t.Height?0)
????????????{
????????????????return;
????????????}
????????????if?(t.Width?>?10000?||?t.Height?>?10000)
????????????{
????????????????return;
????????????}
????????????pictureBox1.Image?=?new?Bitmap(_bitmap?t);
????????}
????????double?_percent?=?1;
????????Bitmap?_bitmap?=?null;
????????///?
????????///?圖片放大按鈕事件
????????///?
????????///?
????????///?
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????button3.Enabled?=?true;
????????????_percent?=?_percent?+?(double)0.1;
????????????
????????????pictureBox1.Image?=?PicSized(_bitmap?_percent);
????????}
???????
????????///?
????????///?圖片縮小按鈕事件
????????///?
????????///?
????????///?
????????private?void?button3_Click(object?sender?EventArgs?e)
????????{
????????????button2.Enabled?=?true;
????????????_percent?=?_percent?-?(double)0.1;
????????????pictureBox1.Image?=?PicSized(_bitmap?_percent);
????????}
????????///?
????????///?圖片放大縮小功能
????????///?
????????///?
????????///?
????????///?
????????public?Bitmap?PicSized(Bitmap?originBmp?double?iSize)
????????{
????????????int?w?=?Convert.ToInt32(originBmp.Width?*?iSize);
????????????int?h?=?Convert.ToInt32(originBmp.Height?*?iSize);
????????????if?(w?<50?||?h?<50)
????????????{
????????????????button3.Enabled?=?false;
????????????}
????????????if?(w?>?99999?||?h?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????12288??2014-04-30?18:00??WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
?????文件??????28160??2014-04-30?18:00??WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
?????文件??????11600??2014-04-30?18:00??WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
?????文件????????490??2010-03-17?22:39??WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
?????文件???????5818??2014-04-30?18:00??WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
?????文件???????4443??2014-04-30?13:04??WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
?????文件???????5817??2014-04-30?13:04??WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
?????文件???????2152??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6402??2014-04-30?18:00??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????488??2014-04-30?13:04??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource.read.1.tlog
?????文件???????1142??2014-04-30?13:04??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource.write.1.tlog
?????文件???????1339??2014-04-30?18:00??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
?????文件??????12288??2014-04-30?18:00??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.exe
?????文件????????180??2014-04-30?13:04??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form1.resources
?????文件??????28160??2014-04-30?18:00??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.pdb
?????文件????????180??2014-04-30?10:33??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Properties.Resources.resources
?????文件????????516??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1\Program.cs
?????文件???????1480??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs
?????文件???????2877??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs
?????文件???????5612??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.resx
?????文件???????1110??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.Designer.cs
?????文件????????249??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.settings
?????文件???????3707??2014-04-30?10:33??WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj
?????文件????????914??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1.sln
????..A..H.?????10240??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1.suo
?????目錄??????????0??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\TempPE
?????目錄??????????0??2014-04-30?18:00??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug
?????目錄??????????0??2014-04-30?10:33??WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug
?????目錄??????????0??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1\obj\x86
?????目錄??????????0??2014-04-30?10:22??WindowsFormsApplication1\WindowsFormsApplication1\bin
............此處省略7個文件信息
- 上一篇:C#RDLC動態加載圖片
- 下一篇:添加緩存區的C#串口接收
評論
共有 條評論