C#中新建一窗体,运行时它的color属性和background属性换着用,用代码怎么实现?
2013-07-26
展开全部
很简单了啦@!直接实例化一个colordialog啊然后设置就行了 啊代码如下: private void button4_Click(object sender, EventArgs e)//设置颜色按钮
{
ColorDialog color = new ColorDialog(); if (color.ShowDialog() == DialogResult.OK)
{
this.BackColor = color.Color;
}
} private void button5_Click(object sender, EventArgs e)//设置图片按钮
{
OpenFileDialog file = new OpenFileDialog();
file.Filter = "图片格式|*.jpg;*.bmp;*.gif";
if (file.ShowDialog() == DialogResult.OK)
{
this.BackgroundImage = Image.FromFile(file.FileName);
}
}绝对正确!如不满意请指出!谢谢!
{
ColorDialog color = new ColorDialog(); if (color.ShowDialog() == DialogResult.OK)
{
this.BackColor = color.Color;
}
} private void button5_Click(object sender, EventArgs e)//设置图片按钮
{
OpenFileDialog file = new OpenFileDialog();
file.Filter = "图片格式|*.jpg;*.bmp;*.gif";
if (file.ShowDialog() == DialogResult.OK)
{
this.BackgroundImage = Image.FromFile(file.FileName);
}
}绝对正确!如不满意请指出!谢谢!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-26
展开全部
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System .Runtime .InteropServices ;namespace windshadow16
{
public partial class MainForm
{
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public MainForm()
{
InitializeComponent();
}
void MainFormLoad(object sender, System.EventArgs e)
{
}
void Button1Click(object sender, System.EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.ShowDialog();
this.BackColor =cd.Color ;
}
void Button2Click(object sender, System.EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "可以输入的图片格式(*.jpg;*.bmp;*gif;*jpeg)|*.jpg;*.bmp;*gif;*jpeg;";
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (openFileDialog1.FileName != "")
{
string newFilename = openFileDialog1.FileName;
this.BackgroundImage = Image.FromFile(newFilename );
}
} }
}
}
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System .Runtime .InteropServices ;namespace windshadow16
{
public partial class MainForm
{
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public MainForm()
{
InitializeComponent();
}
void MainFormLoad(object sender, System.EventArgs e)
{
}
void Button1Click(object sender, System.EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.ShowDialog();
this.BackColor =cd.Color ;
}
void Button2Click(object sender, System.EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "可以输入的图片格式(*.jpg;*.bmp;*gif;*jpeg)|*.jpg;*.bmp;*gif;*jpeg;";
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (openFileDialog1.FileName != "")
{
string newFilename = openFileDialog1.FileName;
this.BackgroundImage = Image.FromFile(newFilename );
}
} }
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-26
展开全部
就是给你的窗体属性color和background赋值
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-26
展开全部
换着用?把color 当成background?还是。。。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-26
展开全部
请说明白点,替换,怎么替换法?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询