看範例學C#-28 自動產生圖片捲軸

  • 8248
  • 0
  • C#
  • 2011-10-07

看範例學C#-28 圖片捲軸

因為picturebox預設沒有捲軸,所以當圖片超過表單大小的時候,我們想要看到每個部分就需要有捲軸才能移過去

Form有一個AutoScroll的屬性可以設定為true,這樣當圖超過表單大小時,我們就可以任意捲動到想看的地方去了

以下為本例程式碼

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;
namespace ex28
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            this.AutoScroll = true;//有捲軸
            pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + "\\ex28.png");//載入圖片
            pictureBox1.Width = Screen.PrimaryScreen.Bounds.Width;//設定圖的寬度 與解析度同寬
            pictureBox1.Height = Screen.PrimaryScreen.Bounds.Height;//設定圖的高度 與解析度同高
        }
    }
}

1

ex28.rar

 


如有錯誤 歡迎指正