主form上的图片如果实现拉伸 在paint事件中自己画上去,(没记错的话)画图片的方法可以指定实际画出的大小 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.Drawing.Bitmap myBit=new System.Drawing.Bitmap( "E:\\Tools\\photo\\Photo\\228569.jpg",false);Graphics GraphicsMyg=this.CreateGraphics();GraphicsMyg.DrawImage(myBit,0,0,this.Width,this.Height); 把上面的代码加入到OnPaint事件中,如下:protected override void OnPaint(PaintEventArgs e){ System.Drawing.Bitmap myBit=new System.Drawing.Bitmap( 背景图片文件名,false); Graphics GraphicsMyg=this.CreateGraphics(); GraphicsMyg.DrawImage(myBit,0,0,this.Width,this.Height);} using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Diagnostics;using System.Data;namespace WindowsApplication1{ public class Form1 : System.Windows.Forms.Form { private int ox; private int oy; private Control control; private System.Windows.Forms.Button button1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button4; private System.Windows.Forms.Button button5; private System.Windows.Forms.Splitter splitter1; private System.Windows.Forms.Splitter splitter2; private System.Windows.Forms.Splitter splitter3; private System.Windows.Forms.Splitter splitter4; private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); this.splitter1 = new System.Windows.Forms.Splitter(); this.splitter2 = new System.Windows.Forms.Splitter(); this.splitter3 = new System.Windows.Forms.Splitter(); this.splitter4 = new System.Windows.Forms.Splitter(); this.SuspendLayout(); // // button1 // this.button1.BackColor = System.Drawing.SystemColors.ActiveBorder; this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button1.Location = new System.Drawing.Point(248, 128); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(160, 64); this.button1.TabIndex = 0; this.button1.Text = "sdfffsdfsdfsdfsdfsd"; this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp); this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove); this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Control_MouseDown); // // label1 // this.label1.Location = new System.Drawing.Point(184, 32); this.label1.Name = "label1"; this.label1.TabIndex = 1; this.label1.Text = "label1"; // // label2 // this.label2.Location = new System.Drawing.Point(296, 32); this.label2.Name = "label2"; this.label2.TabIndex = 2; this.label2.Text = "label2"; // // button2 // this.button2.Dock = System.Windows.Forms.DockStyle.Left; this.button2.Location = new System.Drawing.Point(0, 0); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 326); this.button2.TabIndex = 3; this.button2.Text = "button2"; // // button3 // this.button3.Dock = System.Windows.Forms.DockStyle.Bottom; this.button3.Location = new System.Drawing.Point(75, 303); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(568, 23); this.button3.TabIndex = 4; this.button3.Text = "button3"; // // button4 // this.button4.Dock = System.Windows.Forms.DockStyle.Top; this.button4.Location = new System.Drawing.Point(75, 0); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(568, 23); this.button4.TabIndex = 5; this.button4.Text = "button4"; // // button5 // this.button5.Dock = System.Windows.Forms.DockStyle.Right; this.button5.Location = new System.Drawing.Point(568, 23); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(75, 280); this.button5.TabIndex = 6; this.button5.Text = "button5"; // // splitter1 // this.splitter1.Location = new System.Drawing.Point(75, 23); this.splitter1.Name = "splitter1"; this.splitter1.Size = new System.Drawing.Size(3, 280); this.splitter1.TabIndex = 7; this.splitter1.TabStop = false; // // splitter2 // this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom; this.splitter2.Location = new System.Drawing.Point(78, 300); this.splitter2.Name = "splitter2"; this.splitter2.Size = new System.Drawing.Size(490, 3); this.splitter2.TabIndex = 8; this.splitter2.TabStop = false; // // splitter3 // this.splitter3.Dock = System.Windows.Forms.DockStyle.Right; this.splitter3.Location = new System.Drawing.Point(565, 23); this.splitter3.Name = "splitter3"; this.splitter3.Size = new System.Drawing.Size(3, 277); this.splitter3.TabIndex = 9; this.splitter3.TabStop = false; // // splitter4 // this.splitter4.Dock = System.Windows.Forms.DockStyle.Top; this.splitter4.Location = new System.Drawing.Point(78, 23); this.splitter4.Name = "splitter4"; this.splitter4.Size = new System.Drawing.Size(487, 3); this.splitter4.TabIndex = 10; this.splitter4.TabStop = false; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(643, 326); this.Controls.Add(this.splitter4); this.Controls.Add(this.splitter3); this.Controls.Add(this.splitter2); this.Controls.Add(this.splitter1); this.Controls.Add(this.button5); this.Controls.Add(this.button4); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.button1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "Form1"; this.Text = "Form1"; this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove); this.ResumeLayout(false); } #endregion [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if(this.control == null) return; if(e.Button == MouseButtons.Left) { if(this.Cursor == Cursors.SizeWE&&left==false) { this.control.Width += (e.X - ox); ox = e.X; return; } else if(this.Cursor == Cursors.SizeWE&&left==true) { this.control.Width += (e.X - ox); this.control.Location=new Point(e.X+e.X-ox,oy); ox = e.X; return; } if(this.Cursor == Cursors.SizeNS) { this.control.Height += (e.Y - oy); oy = e.Y; return; } if(this.Cursor == Cursors.SizeNWSE) { this.control.Width += (e.X - ox); this.control.Height += (e.Y - oy); ox = e.X; oy = e.Y; return; } if(this.Cursor==Cursors.SizeAll) { //this.control.Left += ( ox-e.X); //this.control.Top += (e.Y - oy); //int x=((Control)sender).Left-e.X; //int y=((Control)sender).Top-e.Y; //this.control.Location=new Point(x,y); return; } } } private void Control_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.Button == MouseButtons.Left) { ox = e.X + ((Control)sender).Left; oy = e.Y + ((Control)sender).Top; this.Capture = true; } label1.Text=((Control)sender).Left.ToString(); label2.Text=e.X.ToString(); } private bool left; private bool leftshang; private bool leftxia; private bool shang; private void button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { this.control = (Control)sender; if(e.X<10) { this.Cursor=Cursors.SizeWE; left=true; if(e.Y<10) { this.Cursor=Cursors.SizeNWSE; leftshang=true; } else if(e.Y>(this.control.ClientSize.Height-10)) { leftxia=true; this.Cursor=Cursors.SizeNESW; } } else if(e.X>(this.control.ClientSize.Width-10)) { this.Cursor=Cursors.SizeWE; left=false; if(e.Y<10) { leftshang=false; this.Cursor=Cursors.SizeNESW; } else if(e.Y>(this.control.ClientSize.Height-10)) { leftxia=false; this.Cursor=Cursors.SizeNWSE; } } else if(e.Y<10||(e.Y>(this.control.ClientSize.Height-10))) { if(e.Y<10) { shang=true; } else { shang=false; } this.Cursor=Cursors.SizeNS; } else { this.Cursor=Cursors.SizeAll; } } private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { this.control = null; } private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.Button == MouseButtons.Left) { this.Capture = false; this.Cursor = Cursors.Default; } } }} wpf窗体问题 编码问题,iso-8859-1,utf-8,unicode变量转换 VB.NET中,如何将一个项目中的全部.vb代码文件中的每3个空行都统一替换成一个空行 C# 打包问题 关于C#文件上传发生异常! 更改窗体的默认图标 正则表达式获取所有的HTML控件 怎样判断Region的区域为空? C#中如何强制引用。 判断坐标合法性! 关于combox的问题!是不是bug?还是我搞错呢?在线等!! 请问可以用mouse控制picturebox里图片的缩放吗?
"E:\\Tools\\photo\\Photo\\228569.jpg",false);
Graphics GraphicsMyg=this.CreateGraphics();
GraphicsMyg.DrawImage(myBit,0,0,this.Width,this.Height);
protected override void OnPaint(PaintEventArgs e)
{
System.Drawing.Bitmap myBit=new System.Drawing.Bitmap(
背景图片文件名,false);
Graphics GraphicsMyg=this.CreateGraphics();
GraphicsMyg.DrawImage(myBit,0,0,this.Width,this.Height);
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;
using System.Data;namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private int ox;
private int oy;
private Control control; private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Splitter splitter2;
private System.Windows.Forms.Splitter splitter3;
private System.Windows.Forms.Splitter splitter4;
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
} protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.splitter1 = new System.Windows.Forms.Splitter();
this.splitter2 = new System.Windows.Forms.Splitter();
this.splitter3 = new System.Windows.Forms.Splitter();
this.splitter4 = new System.Windows.Forms.Splitter();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Location = new System.Drawing.Point(248, 128);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(160, 64);
this.button1.TabIndex = 0;
this.button1.Text = "sdfffsdfsdfsdfsdfsd";
this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove);
this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Control_MouseDown);
//
// label1
//
this.label1.Location = new System.Drawing.Point(184, 32);
this.label1.Name = "label1";
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// label2
//
this.label2.Location = new System.Drawing.Point(296, 32);
this.label2.Name = "label2";
this.label2.TabIndex = 2;
this.label2.Text = "label2";
//
// button2
//
this.button2.Dock = System.Windows.Forms.DockStyle.Left;
this.button2.Location = new System.Drawing.Point(0, 0);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 326);
this.button2.TabIndex = 3;
this.button2.Text = "button2";
//
// button3
//
this.button3.Dock = System.Windows.Forms.DockStyle.Bottom;
this.button3.Location = new System.Drawing.Point(75, 303);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(568, 23);
this.button3.TabIndex = 4;
this.button3.Text = "button3";
//
// button4
//
this.button4.Dock = System.Windows.Forms.DockStyle.Top;
this.button4.Location = new System.Drawing.Point(75, 0);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(568, 23);
this.button4.TabIndex = 5;
this.button4.Text = "button4";
//
// button5
//
this.button5.Dock = System.Windows.Forms.DockStyle.Right;
this.button5.Location = new System.Drawing.Point(568, 23);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(75, 280);
this.button5.TabIndex = 6;
this.button5.Text = "button5";
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(75, 23);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 280);
this.splitter1.TabIndex = 7;
this.splitter1.TabStop = false;
//
// splitter2
//
this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.splitter2.Location = new System.Drawing.Point(78, 300);
this.splitter2.Name = "splitter2";
this.splitter2.Size = new System.Drawing.Size(490, 3);
this.splitter2.TabIndex = 8;
this.splitter2.TabStop = false;
//
// splitter3
//
this.splitter3.Dock = System.Windows.Forms.DockStyle.Right;
this.splitter3.Location = new System.Drawing.Point(565, 23);
this.splitter3.Name = "splitter3";
this.splitter3.Size = new System.Drawing.Size(3, 277);
this.splitter3.TabIndex = 9;
this.splitter3.TabStop = false;
//
// splitter4
//
this.splitter4.Dock = System.Windows.Forms.DockStyle.Top;
this.splitter4.Location = new System.Drawing.Point(78, 23);
this.splitter4.Name = "splitter4";
this.splitter4.Size = new System.Drawing.Size(487, 3);
this.splitter4.TabIndex = 10;
this.splitter4.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(643, 326);
this.Controls.Add(this.splitter4);
this.Controls.Add(this.splitter3);
this.Controls.Add(this.splitter2);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "Form1";
this.Text = "Form1";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
this.ResumeLayout(false); }
#endregion [STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(this.control == null)
return; if(e.Button == MouseButtons.Left)
{
if(this.Cursor == Cursors.SizeWE&&left==false)
{
this.control.Width += (e.X - ox);
ox = e.X;
return;
}
else if(this.Cursor == Cursors.SizeWE&&left==true)
{
this.control.Width += (e.X - ox);
this.control.Location=new Point(e.X+e.X-ox,oy);
ox = e.X;
return;
}
if(this.Cursor == Cursors.SizeNS)
{
this.control.Height += (e.Y - oy);
oy = e.Y;
return;
}
if(this.Cursor == Cursors.SizeNWSE)
{
this.control.Width += (e.X - ox);
this.control.Height += (e.Y - oy);
ox = e.X;
oy = e.Y;
return;
}
if(this.Cursor==Cursors.SizeAll)
{
//this.control.Left += ( ox-e.X);
//this.control.Top += (e.Y - oy);
//int x=((Control)sender).Left-e.X;
//int y=((Control)sender).Top-e.Y;
//this.control.Location=new Point(x,y);
return;
}
}
} private void Control_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
ox = e.X + ((Control)sender).Left;
oy = e.Y + ((Control)sender).Top;
this.Capture = true;
}
label1.Text=((Control)sender).Left.ToString();
label2.Text=e.X.ToString();
}
private bool left;
private bool leftshang;
private bool leftxia;
private bool shang;
private void button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.control = (Control)sender;
if(e.X<10)
{
this.Cursor=Cursors.SizeWE;
left=true;
if(e.Y<10)
{
this.Cursor=Cursors.SizeNWSE;
leftshang=true;
}
else if(e.Y>(this.control.ClientSize.Height-10))
{
leftxia=true;
this.Cursor=Cursors.SizeNESW;
}
}
else if(e.X>(this.control.ClientSize.Width-10))
{
this.Cursor=Cursors.SizeWE;
left=false;
if(e.Y<10)
{
leftshang=false;
this.Cursor=Cursors.SizeNESW;
}
else if(e.Y>(this.control.ClientSize.Height-10))
{
leftxia=false;
this.Cursor=Cursors.SizeNWSE;
}
}
else if(e.Y<10||(e.Y>(this.control.ClientSize.Height-10)))
{
if(e.Y<10)
{
shang=true;
}
else
{
shang=false;
}
this.Cursor=Cursors.SizeNS;
}
else
{
this.Cursor=Cursors.SizeAll;
}
} private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.control = null;
} private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
this.Capture = false;
this.Cursor = Cursors.Default;
}
}
}
}