2007 دە تەرتىپ مۇنداقكەن http://jingyan.baidu.com/article/49ad8bce104c1f5834d8faf9.html
在access对象中,找到你要修改的窗体,然后右键单击该窗体,选择设计视图
access怎样插入和设置窗体背景图片
在菜单栏点击【数据库工具】选项,然后选择【属性表】打开属性对话框
access怎样插入和设置窗体背景图片
接着点击窗体左上角的这个位置,如图所示,在这个四方型中间出现一个小黑色四方形,这样窗体就被选中
access怎样插入和设置窗体背景图片
我们转移视线到属性表,在图片属性这一栏,点击右边的省略号
access怎样插入和设置窗体背景图片
打开了插入图片的对话框,我们选择想要作为背景的图片,然后点击确定按钮。
access怎样插入和设置窗体背景图片
这样我们就看到背景被插入,但是背景太大,无法显示完整效果。
access怎样插入和设置窗体背景图片
还是在属性表,设置图片的缩放模式为【缩放】,这样背景图片就会随着窗体的大小而变化
access怎样插入和设置窗体背景图片
最后我们点击菜单栏上面的窗体视图预览一下效果:
رەسىم قىستۇرۇش كودى، ئەسقاتامىكىن دەپ قوشۇپ قويدۇم
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.OleDb;
- using System.IO;
- namespace SendEMail
- {
- public partial class frmSaveImg : Form
- {
- OleDbConnection conn;
- public frmSaveImg()
- {
- InitializeComponent();
- //OleDbConnection连接字符串
- string strConn = @"provider=Microsoft.Jet.OLEDB.4.0;data source=" + Application.StartupPath + "";
- //创建OleDbConnection对象
- conn = new OleDbConnection(strConn);
- }
- ///
- /// 执行SQL语句函数
- ///
- /// SQL语句
- /// SQL语句中的参数组
- /// 返回受影响记录条数
- public int ExecuteSql(string sqlcmd,params OleDbParameter[] paras)
- {
- OleDbCommand cmd = new OleDbCommand(sqlcmd, conn);
- if (conn.State == ConnectionState.Closed)
- {
- conn.Open();
- }
- foreach (OleDbParameter p in paras)
- {
- cmd.Parameters.Add(p);
- }
- int cnt = cmd.ExecuteNonQuery();
- conn.Close();
- return cnt;
- }
- ///
- /// 执行SQL查询
- ///
- /// SQL语句
- /// 返回数据表
- public DataTable QuerySql(string sqlcmd)
- {
- OleDbDataAdapter oda = new OleDbDataAdapter(sqlcmd, conn);
- DataTable dt = new DataTable();
- oda.Fill(dt);
- return dt;
- }
- //单击pictureBox1是执行
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- //打开文件对话框
- OpenFileDialog ofd = new OpenFileDialog();
- //选择图片后,点击确定按钮,加载图片
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- pictureBox1.ImageLocation= ofd.FileName;
- }
- }
- //单击保存按钮执行图片保存到数据库中
- private void button1_Click(object sender, EventArgs e)
- {
- //插入数据SQL语句, img字段为表中存储图片的字段(ole类型)
- string sql = "insert into tb_img (img) values (@img)";
- //读取图片文件流
- FileStream fs = File.Open(pictureBox1.ImageLocation, FileMode.Open, FileAccess.Read);
- //将流转化为byte数组
- byte[] MyData = new byte[fs.Length];
- fs.Read(MyData, 0, MyData.Length);
- fs.Close();
- //给SQL语句中的参数@img, 赋值
- OleDbParameter p = new OleDbParameter("@img", MyData);
- //执行SQL语句,将数据插入表中
- ExecuteSql(sql, p);
- //刷新comboBox1
- comboBox1.ValueMember = "id";
- comboBox1.DisplayMember = "id";
- comboBox1.DataSource = QuerySql("select id from tb_img");
- }
- //当comboBox1的index改变时执行
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- //得到当前comboBox1选中的记录
- DataTable dt = QuerySql("select * from tb_img where id =" + comboBox1.SelectedValue.ToString());
- //将值强转为byte数组
- byte[] MyData = (byte[])dt.Rows[0]["img"];
- //将byte[]数组写入到流中
- MemoryStream s = new MemoryStream();
- s.Write(MyData, 0, MyData.Length);
- //pictureBox1加载得到的流
- pictureBox1.Image = Image.FromStream(s);
- }
- //窗体启动时,comboBox1绑定数据库
- private void frmSaveImg_Load(object sender, EventArgs e)
- {
- comboBox1.ValueMember = "id";
- comboBox1.DisplayMember = "id";
- comboBox1.DataSource = QuerySql("select id from tb_img");
- }
- }
- }
مەزمۇننى كۆچۈرۈۋېلىش |