c#每日一题(六) 编写一个Windows应用程序,实现从白色到绿色渐变的背景,然后接收一字符串,将字符串中的所有小写字母转变成大写字母。 参考程序界面地址: http://www.foyi.cn/bbs/UploadFile/vbdn/example.htm 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Rectangle rec = new Rectangle(0,0,this.Width,this.Height); Drawing2D.LinearGradientBrush myLinearGradientBrush = new Drawing2D.LinearGradientBrush(rec,Color.White,Color.Green,LinearGradientMode.Vertical); e.Graphics.FillRectangle(myLinearGradientBrush,0,0,this.Width,this.Height); } private void button1_Click(object sender, System.EventArgs e) { this.textBox2.Text = this.textBox1.Text.ToUpper(); } //刚才的有点错误 private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Rectangle rec = new Rectangle(0,0,this.Width,this.Height); System.Drawing.Drawing2D.LinearGradientBrush myLinearGradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(rec,Color.White,Color.Green,LinearGradientMode.Vertical); e.Graphics.FillRectangle(myLinearGradientBrush,0,0,this.Width,this.Height); } private void button1_Click(object sender, System.EventArgs e) { this.textBox2.Text = this.textBox1.Text.ToUpper(); } 窗体没有Invalidate()事件,怎么调用Paint()? 这个就更没有意义了没有vs谁TMD能写出来 主要是Drawing类的应用!好东西。 private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Rectangle rec = new Rectangle(0,0,this.Width,this.Height); System.Drawing.Drawing2D.LinearGradientBrush myLinearGradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(rec,Color.White,Color.Green,LinearGradientMode.Vertical); e.Graphics.FillRectangle(myLinearGradientBrush,0,0,this.Width,this.Height); } private void button1_Click(object sender, System.EventArgs e) { this.textBox2.Text = this.textBox1.Text.ToUpper(); } 楼上正解,我来发个清晰版的..^^using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Drawing.Drawing2D;namespace Windows渐变{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button1; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(15, 55); this.textBox1.Name = "textBox1"; this.textBox1.TabIndex = 0; this.textBox1.Text = "textBox1"; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(168, 56); this.textBox2.Name = "textBox2"; this.textBox2.TabIndex = 1; this.textBox2.Text = "textBox2"; // // label1 // this.label1.Location = new System.Drawing.Point(120, 58); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(48, 23); this.label1.TabIndex = 2; this.label1.Text = "转换>>"; // // button1 // this.button1.Location = new System.Drawing.Point(102, 143); this.button1.Name = "button1"; this.button1.TabIndex = 3; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.button1); this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Controls.Add(this.label1); this.Name = "Form1"; this.Text = "Form1"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); this.ResumeLayout(false); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Rectangle rect = new Rectangle(0 , 0 , this.Width , this.Height); LinearGradientBrush linearGradient = new LinearGradientBrush (rect , Color.White , Color.Green , LinearGradientMode.Vertical); e.Graphics.FillRectangle(linearGradient , rect); } private void button1_Click(object sender, System.EventArgs e) { textBox2.Text = textBox1.Text.ToUpper(); } }} 参考答案:主要实现代码如下:using System.Drawing.Drawing2D;//实现从白色到绿色渐变的背景private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e){ Graphics g=e.Graphics; LinearGradientBrush myBrush=new LinearGradientBrush this.ClientRectangle,Color.White,Color.Green,LinearGradientMode.Vertical); g.FillRectangle(myBrush,this.ClientRectangle);}//窗体大小变化时,保证背景颜色仍然渐变并且不会出现重叠private void Form1_SizeChanged(object sender, System.EventArgs e){ this.Invalidate();}//实现将字符串中的所有小写字母转变为大写字母private void button1_Click(object sender, System.EventArgs e){ this.textBox2.Text=this.textBox1.Text.ToUpper();} C#2008下WebKit使用的问题 计算器的退格怎么用C#中的string来实现 C# soap Excel 高难度问题,高手进来看下!!!!!!!!!!!!!!!!! 有关 DataSet 的问题(WinForm) C#自定义安装问题 关于用XSD模式验证XML文档的链接初步问题 从工具->选项里面可以建立以及建立快捷键方案, 请问哪里可以保存这些快捷方案, 好让我拿到公司里面用? 关于是用WCF服务开发微信接口的问题 求随机抽签代码 乱码问题 谁知道vod点歌软件双屏版的实现原理是什么啊?急!急!急!急!急!
{
Rectangle rec = new Rectangle(0,0,this.Width,this.Height);
Drawing2D.LinearGradientBrush myLinearGradientBrush = new Drawing2D.LinearGradientBrush(rec,Color.White,Color.Green,LinearGradientMode.Vertical);
e.Graphics.FillRectangle(myLinearGradientBrush,0,0,this.Width,this.Height);
} private void button1_Click(object sender, System.EventArgs e)
{
this.textBox2.Text = this.textBox1.Text.ToUpper();
}
{
Rectangle rec = new Rectangle(0,0,this.Width,this.Height);
System.Drawing.Drawing2D.LinearGradientBrush myLinearGradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(rec,Color.White,Color.Green,LinearGradientMode.Vertical);
e.Graphics.FillRectangle(myLinearGradientBrush,0,0,this.Width,this.Height);
} private void button1_Click(object sender, System.EventArgs e)
{
this.textBox2.Text = this.textBox1.Text.ToUpper();
}
没有vs谁TMD能写出来
好东西。
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Rectangle rec = new Rectangle(0,0,this.Width,this.Height);
System.Drawing.Drawing2D.LinearGradientBrush myLinearGradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(rec,Color.White,Color.Green,LinearGradientMode.Vertical);
e.Graphics.FillRectangle(myLinearGradientBrush,0,0,this.Width,this.Height);
} private void button1_Click(object sender, System.EventArgs e)
{
this.textBox2.Text = this.textBox1.Text.ToUpper();
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;namespace Windows渐变
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(15, 55);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(168, 56);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 1;
this.textBox2.Text = "textBox2";
//
// label1
//
this.label1.Location = new System.Drawing.Point(120, 58);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 23);
this.label1.TabIndex = 2;
this.label1.Text = "转换>>";
//
// button1
//
this.button1.Location = new System.Drawing.Point(102, 143);
this.button1.Name = "button1";
this.button1.TabIndex = 3;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Rectangle rect = new Rectangle(0 , 0 , this.Width , this.Height);
LinearGradientBrush linearGradient = new LinearGradientBrush
(rect , Color.White , Color.Green , LinearGradientMode.Vertical);
e.Graphics.FillRectangle(linearGradient , rect);
} private void button1_Click(object sender, System.EventArgs e)
{
textBox2.Text = textBox1.Text.ToUpper();
}
}
}
主要实现代码如下:
using System.Drawing.Drawing2D;
//实现从白色到绿色渐变的背景
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g=e.Graphics;
LinearGradientBrush myBrush=new LinearGradientBrush this.ClientRectangle,Color.White,Color.Green,LinearGradientMode.Vertical);
g.FillRectangle(myBrush,this.ClientRectangle);
}
//窗体大小变化时,保证背景颜色仍然渐变并且不会出现重叠
private void Form1_SizeChanged(object sender, System.EventArgs e)
{
this.Invalidate();
}
//实现将字符串中的所有小写字母转变为大写字母
private void button1_Click(object sender, System.EventArgs e)
{
this.textBox2.Text=this.textBox1.Text.ToUpper();
}