像这样的效果在windows窗体里怎么实现,
例:比如想把QQ快捷方式放到statusStrip里,可如何获取正在拖动QQ快捷方式的属性,并且怎么加入效果如何实现。请不希赐教
解决方案 »
- C#保存网页为完整的mht(所有图片、Flash)
- 取单个进程的cpu使用率,要代码能调试。本人做过不过取的不准确求准确的做法
- 这两种代码有何区别?
- WinForm 隐藏控制栏
- 如何在窗口中出现一个模式化的层。这个层遮住整个框架页。
- 怎样通过post方式(地址栏传参)更改datagrid页数
- 求教阿?Hashtable fldAttrs =(Hashtable)cmdArgs ;
- 怎样用TCP异步收POP3邮件,要winform代码!
- 如何实现在编辑框中按回车键时自动执行按钮的Click事件?
- 请帮忙看看这个关于UDP的程序!!
- C# 判断网址是否连接成功(多种都不成功)
- 求一图片上传至数据库里的代码。。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
namespace 拖拽成按钮
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <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()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(352, 285);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.Form1_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.Form1_DragEnter);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.AllowDrop = true;
this.p = new Point(1,1);
}
/// <summary>
/// 文件路径
/// </summary>
string strFileName;
/// <summary>
/// btn的起始位置
/// </summary>
Point p;
//托拽文件或快捷方式进入窗体是记录它的路径
private void Form1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
String[] str_Drop=(String[])e.Data.GetData(DataFormats.FileDrop,true);
this.strFileName = str_Drop[0];
}
//推拽释放时生成按钮
private void Form1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
Button btn = new Button();
//保存文件的路径
btn.Tag = this.strFileName;
btn.Text =this.strFileName.Substring(this.strFileName.LastIndexOf(@"\"));
btn.Click +=new EventHandler(btn_Click);
btn.Location = this.p;
this.p.X += 100;
if(this.p.X > this.Width)
{
this.p.X = 1;
this.p.Y += 30;
}
this.Controls.Add(btn);
}
private void btn_Click(object sender, System.EventArgs e)
{
ProcessStartInfo Info=new ProcessStartInfo();
try
{
Info.FileName = ((Button)sender).Tag.ToString();
Process.Start(Info);
}
catch(Win32Exception win32ex)
{
MessageBox.Show("出错原因:"+win32ex.Message,"出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
}
我已经测过.你自己去试试吧using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics; namespace WindowsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} /// <summary>
/// 文件路径
/// </summary>
string strFileName;
/// <summary>
/// btn的起始位置
/// </summary>
Point p;
//推拽释放时生成按钮
private void Form2_DragDrop(object sender, DragEventArgs e)
{
Button btn = new Button();
//保存文件的路径
btn.Tag = this.strFileName;
btn.Text = this.strFileName.Substring(this.strFileName.LastIndexOf(@"\"));
btn.Click += new EventHandler(btn_Click);
btn.Location = this.p;
this.p.X += 100;
if (this.p.X > this.Width)
{
this.p.X = 1;
this.p.Y += 30;
}
this.Controls.Add(btn); } //托拽文件或快捷方式进入窗体是记录它的路径
private void Form2_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
String[] str_Drop = (String[])e.Data.GetData(DataFormats.FileDrop, true);
this.strFileName = str_Drop[0];
} private void Form2_Load(object sender, EventArgs e)
{
this.AllowDrop = true;
this.p = new Point(1, 1);
} private void btn_Click(object sender, EventArgs e)
{
ProcessStartInfo Info = new ProcessStartInfo();
try
{
Info.FileName = ((Button)sender).Tag.ToString();
Process.Start(Info);
}
catch (Win32Exception win32ex)
{
MessageBox.Show("出错原因:" + win32ex.Message, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
}
}
大部分好用,可我的电脑,我的文档,IE它们拖上去并不好用,
这个可以解决吗?