button后台添加图片背景
button1.Background = new ImageBrush
{
ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/1.jpg"))
};
数据库添加图片并提取
再在wpf中这样写
databaseclass db = new databaseclass();
SqlConnection con = new SqlConnection(MySqlCon);
string strSql = "select * from activity where ano='A02'";
SqlCommand cmd = new SqlCommand(strSql, con);
cmd.CommandType = CommandType.Text;//CommandText的内容是SQL语句
try
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader != null && reader.HasRows)
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; ++i)
{
if (reader.GetName(i).Equals("picture"))
{
MessageBox.Show(reader.GetValue(i).ToString());
image.Background = new ImageBrush
{
ImageSource = new BitmapImage(new Uri(reader.GetValue(i).ToString(), UriKind.RelativeOrAbsolute))
};
}
}
}
}
reader.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
就ok了
对后台设置的button事件处理为
buttons[j].Click += new RoutedEventHandler(delegate (object sender, RoutedEventArgs r)
{
staticpublic.tano = buttons[j].Name.ToString().Trim();
crazy c1 = new crazy();
c1.Show();
this.Close();
});
在后台设置字体
TempButton.FontFamily = new FontFamily("Microsoft YaHei");