[求助]--- winform关于图形方面的.

zhouheng123456 2006-02-06 02:59:18
需求是...读取一张图片...要在上面加上一个方框..

方框可以被拖动..把方框里的图片内容..导出..

现在碰到的麻烦是....在拖动方框的时候..控件会重新绘制...导致显示效果上出现重影..

代码如下...请帮我看看有什么办法解决掉...谢谢

...全文
98 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouheng123456 2006-02-06
  • 打赏
  • 举报
回复
怎么没人啊...我来错地方了??


实际问题点数是200
MonkWang 2006-02-06
  • 打赏
  • 举报
回复
很少做winform的
更别说图形了
帮你顶吧
学习学习
zhouheng123456 2006-02-06
  • 打赏
  • 举报
回复
private void Form2_Load(object sender, System.EventArgs e)
{
p = new PictureBox();
p.ForeColor = Color.Transparent;
p.BackColor = Color.Transparent;
p.BorderStyle = BorderStyle.FixedSingle;
pictureBox1.Controls.Add(p);
p.Top = 0;
p.Left = 0;
p.Width = 260;
p.Height = 200;
p.Show();
p.MouseDown += new MouseEventHandler( Panel2_MouserDown);
p.MouseMove += new MouseEventHandler( Panel2_MouseMove);
p.MouseUp += new MouseEventHandler( Panel2_MouseUp);

this.MouseUp += new MouseEventHandler(Panel2_MouseUp);
this.pictureBox1.MouseUp += new MouseEventHandler(Panel2_MouseUp);
this.panel1.MouseUp += new MouseEventHandler(Panel2_MouseUp);
}
private void Panel2_MouserDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
pMouseDown = true;
pDownX = e.X;
pDownY = e.Y;
}

private void Panel2_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(pMouseDown)
{
int x = Cursor.Position.X - pDownX;
int y = Cursor.Position.Y - pDownY;
p.Location = new Point(x,y);
}
}

private void Panel2_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(pMouseDown)
{
pMouseDown = false;
p.Invalidate();
p.Show();
}
this.pictureBox1.Show();
}

private void button1_Click(object sender, System.EventArgs e)
{
OpenFileDialog fdSelect = new OpenFileDialog();
fdSelect.Multiselect = false;
fdSelect.Filter = "Image files (*.jpg)|*.jpg|Bmp files (*.bmp)|*.Bmp";
fdSelect.ShowDialog();
string strFilePath = fdSelect.FileName;
if(File.Exists(strFilePath))
{
if(btmap != null)
{
btmap.Dispose();
}
btmap = new Bitmap(strFilePath);
// show image
this.pictureBox1.Image = btmap;
oldWdith = btmap.Width;
oldHeight = btmap.Height;
}
}

private void domainUpDown1_SelectedItemChanged(object sender, System.EventArgs e)
{
try
{
if(btmap != null)
{
int NewWdith = oldWdith / 100 * int.Parse(domainUpDown1.Text);
int NewHeight = oldHeight / 100 * int.Parse(domainUpDown1.Text);
System.Drawing.Size NewSize = new Size(NewWdith,NewHeight);
Bitmap tempBtmap = new Bitmap((Image)btmap,NewSize);
if(!Object.Equals(this.pictureBox1.Image,btmap))
{
this.pictureBox1.Image.Dispose();
}
this.pictureBox1.Image = (Image)tempBtmap;
this.pictureBox1.Show();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
zhouheng123456 2006-02-06
  • 打赏
  • 举报
回复
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(412, 376);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 7;
this.pictureBox1.TabStop = false;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.domainUpDown1);
this.groupBox1.Controls.Add(this.button5);
this.groupBox1.Controls.Add(this.button4);
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Location = new System.Drawing.Point(514, 10);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(160, 186);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(140, 136);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(11, 15);
this.label1.TabIndex = 5;
this.label1.Text = "%";
//
// domainUpDown1
//
this.domainUpDown1.Items.Add("10");
this.domainUpDown1.Items.Add("20");
this.domainUpDown1.Items.Add("30");
this.domainUpDown1.Items.Add("40");
this.domainUpDown1.Items.Add("50");
this.domainUpDown1.Items.Add("60");
this.domainUpDown1.Items.Add("70");
this.domainUpDown1.Items.Add("80");
this.domainUpDown1.Items.Add("90");
this.domainUpDown1.Items.Add("100");
this.domainUpDown1.Location = new System.Drawing.Point(46, 134);
this.domainUpDown1.Name = "domainUpDown1";
this.domainUpDown1.Size = new System.Drawing.Size(80, 19);
this.domainUpDown1.TabIndex = 4;
this.domainUpDown1.SelectedItemChanged += new System.EventHandler(this.domainUpDown1_SelectedItemChanged);
//
// button5
//
this.button5.Location = new System.Drawing.Point(48, 96);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(64, 16);
this.button5.TabIndex = 3;
this.button5.Text = "button5";
//
// button4
//
this.button4.Location = new System.Drawing.Point(120, 48);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(16, 48);
this.button4.TabIndex = 2;
this.button4.Text = "button4";
//
// button3
//
this.button3.Location = new System.Drawing.Point(24, 48);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(16, 48);
this.button3.TabIndex = 1;
this.button3.Text = "button3";
//
// button2
//
this.button2.Location = new System.Drawing.Point(48, 24);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 16);
this.button2.TabIndex = 0;
this.button2.Text = "button2";
//
// button1
//
this.button1.Location = new System.Drawing.Point(190, 468);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(136, 16);
this.button1.TabIndex = 4;
this.button1.Text = "Load";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(680, 489);
this.Controls.Add(this.panel1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.button1);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.panel1.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion
zhouheng123456 2006-02-06
  • 打赏
  • 举报
回复
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Drawing2D;

namespace photo_Test
{
/// <summary>
/// Form2 の概要の説明です。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
public System.Windows.Forms.Panel panel1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.DomainUpDown domainUpDown1;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private int oldWdith = 0;
private int oldHeight = 0;
private Bitmap btmap = null;
private System.Windows.Forms.PictureBox pictureBox1;
private PictureBox p;
private bool pMouseDown = false;
int pDownX = 0;
int pDownY = 0;
//private Graphics ImgGra = null;
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;

public Form2()
{
//
// 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.panel1 = new System.Windows.Forms.Panel();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.domainUpDown1 = new System.Windows.Forms.DomainUpDown();
this.button5 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.panel1.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.AllowDrop = true;
this.panel1.AutoScroll = true;
this.panel1.AutoScrollMargin = new System.Drawing.Size(1, 1);
this.panel1.AutoScrollMinSize = new System.Drawing.Size(1, 1);
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.Add(this.pictureBox1);
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(496, 456);
this.panel1.TabIndex = 6;

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧