偶无聊写的c#图片浏览器(哈,没营养的,纯粹为积分而发)

方法1.    Image类实现,正经版的

 

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 PictureViewer
{

 


    public partial class Form1 : Form
    {

        private System.ComponentModel.IContainer components = null;


        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

 

 

 

        private System.Windows.Forms.Button btnbrower;
        private System.Windows.Forms.Button btnclose;
        private System.Windows.Forms.PictureBox PBpicture;

 
        private void Initialize()
        {
            this.btnbrower = new System.Windows.Forms.Button();
            this.btnclose = new System.Windows.Forms.Button();
            this.PBpicture = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.PBpicture)).BeginInit();
            this.SuspendLayout();
            //
            // btnbrower
            //
            this.btnbrower.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.btnbrower.Location = new System.Drawing.Point(58, 264);
            this.btnbrower.Name = "btnbrower";
            this.btnbrower.Size = new System.Drawing.Size(75, 23);
            this.btnbrower.TabIndex = 1;
            this.btnbrower.Text = "浏览";
            this.btnbrower.UseVisualStyleBackColor = true;
            this.btnbrower.Click += new System.EventHandler(this.button1_Click);
            //
            // btnclose
            //
            this.btnclose.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.btnclose.Location = new System.Drawing.Point(186, 264);
            this.btnclose.Name = "btnclose";
            this.btnclose.Size = new System.Drawing.Size(75, 23);
            this.btnclose.TabIndex = 2;
            this.btnclose.Text = "关闭";
            this.btnclose.UseVisualStyleBackColor = true;
            this.btnclose.Click += new System.EventHandler(this.btnclose_Click);
            //
            // PBpicture
            //
            this.PBpicture.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.PBpicture.BackColor = System.Drawing.SystemColors.ControlDark;
            this.PBpicture.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.PBpicture.Cursor = System.Windows.Forms.Cursors.Hand;
            this.PBpicture.Location = new System.Drawing.Point(-3, -2);
            this.PBpicture.Name = "PBpicture";
            this.PBpicture.Size = new System.Drawing.Size(344, 260);
            this.PBpicture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
            this.PBpicture.TabIndex = 2;
            this.PBpicture.TabStop = false;
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(324, 286);
            this.Controls.Add(this.PBpicture);
            this.Controls.Add(this.btnclose);
            this.Controls.Add(this.btnbrower);
            this.Name = "Form1";
            this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
            this.Text = "PictureViewer    By Gu";
            ((System.ComponentModel.ISupportInitialize)(this.PBpicture)).EndInit();
            this.ResumeLayout(false);

        }
 

      
        public Form1()
        {
            Initialize();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = "选择图片";
            fdlg.InitialDirectory = "c://";
            fdlg.Filter = "All files(*.*)|*.*|Image files(*.jpg.*bmp.*.gif.*.png)|*.jpg;*.bmp;*.gif;";
            fdlg.FilterIndex = 2;
            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                PBpicture.Image = Image.FromFile(fdlg.FileName);
            }
        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

      

#endregion
    }

 

 
   
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }

}

 

 

 

 

 

方法2.   只不过是投机把图片给Form当壁纸用了,勉强看起来是浏览器啦,哈哈

 

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;

namespace UseStateBar
{
 
   

 public partial class Form1:Form
 {
       

        /// <summary>
        /// 必需的设计器变量。
        /// </summary>


 private System.Windows.Forms.StatusBar statusbar1;
 private System.Windows.Forms.MainMenu mainmenu1;
 private System.Windows.Forms.MenuItem file;
 private System.Windows.Forms.MenuItem exit;
 private  System.Windows.Forms.MenuItem view;
 private System.Windows.Forms.MenuItem view2;
 private System.Windows.Forms.MenuItem view3;
 private System.Windows.Forms.MenuItem open;

 

 

 


        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }


        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>

 

 

 

 

 

 

 

 
 
 private void InitializeComponent()
  {

  //statusbar1
  statusbar1=new System.Windows.Forms.StatusBar();
  
  this.statusbar1.Text="the initial information";
  this.statusbar1.Name="statusbar1";
  this.statusbar1.Size=new System.Drawing.Size(300,20);
  this.statusbar1.Location=new System.Drawing.Point(0,250);
  


  //form1
  this.Text="usage of status bar  By Gu 2011/4/3";
  this.Name="Form1";
  this.Controls.Add(this.statusbar1);
  this.ClientSize=new System.Drawing.Size(300,400);
  this.MouseMove+= new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
  this.ResumeLayout(false);
  


  
  this.mainmenu1=new System.Windows.Forms.MainMenu();
  this.file=new System.Windows.Forms.MenuItem();
  this.exit=new System.Windows.Forms.MenuItem();
  this.view=new System.Windows.Forms.MenuItem();
  this.view2=new System.Windows.Forms.MenuItem();
  this.view3=new System.Windows.Forms.MenuItem();
  this.open=new System.Windows.Forms.MenuItem();


  //mainmenu1
  
  this.mainmenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[]{this.file,this.view});
  //file
  this.file.Text="File";
  this.file.Index=0;
  this.file.MenuItems.AddRange(new System.Windows.Forms.MenuItem[]{this.open,this.exit});

  
  //open
  this.open.Text="Open";
  this.open.Index=0;
  this.open.Click+=new System.EventHandler(this.open_Click);

 

 

 

 

  //exit
  this.exit.Text="Exit";
  this.exit.Index=1;
  this.exit.Click+=new System.EventHandler(this.exit_Click);
  

  //view
  this.view.Index=1;
  this.view.Text="View";
  this.view.MenuItems.AddRange(new System.Windows.Forms.MenuItem[]{this.view2,this.view3});
  

  //view2
  this.view2.Text="view2";
  this.view2.Index=0;
  this.view2.Click+=new System.EventHandler(this.view2_Click);

  //view3
  this.view3.Text="view3";
  this.view3.Index=1;
  this.view3.Click+=new System.EventHandler(this.view3_Click);

  //Form1
  this.AutoScaleBaseSize=new System.Drawing.Size(6,14);
  this.ClientSize=new System.Drawing.Size(292,273);
  this.Name="Form1";
  this.Menu=this.mainmenu1;
  this.Text="usage of menu    By Gu 2011/4/4";
  }

#endregion

 

  public Form1()
  {
   InitializeComponent();
  }
 private void Form1_MouseMove(object sender,System.Windows.Forms.MouseEventArgs e)
  {

  string position="mouse's position(" +e.X.ToString()+","+e.Y.ToString()+")";
   statusbar1.Text=position;
  }

    private void open_Click(object sender,EventArgs e)
  {
  OpenFileDialog ofd1=new OpenFileDialog();
  ofd1.Title="please select a picture";
  ofd1.InitialDirectory="c://";
  ofd1.Filter="All files(*.*)|*.*|Image files(*.jpg;*.bmp;*.gif;*png)|*.jpg;*.gif;*.bmp;*.png;";

  ofd1.FilterIndex=2;
  if(ofd1.ShowDialog()==DialogResult.OK)
   {
   
   
   this.BackgroundImage=Image.FromFile(ofd1.FileName);
   this.ClientSize=this.BackgroundImage.Size;
   }
  
  
  }
  

 

 

 

 

 

 

 

 


 private void exit_Click(object sender,System.EventArgs e)
  {
  this.Close();
  }
  private void view2_Click(object sender,System.EventArgs e)
  {
   this.BackColor=Color.Red;
  }
  
  private void view3_Click(object sender,System.EventArgs e)
  {
   this.BackColor=Color.Black;
  }

 

 


 }

    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }

 

 

 

 

 

 

 

 


}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值