解决方案 »
- C#如何搜索附件区域里面的蓝牙设备
- Winform DataGridViewCheckBoxColumn值的问题
- 关于如何写入已知数据流形成双声道wave文件(c#和directx),其实和语言没太大关系
- C# 中 将 List 中数据转成 JSon 时出异常,请教高手
- 请各位老鸟帮帮忙!一个弹出页面并返回值的问题
- 我打开了excel2003的一张表,现在我要双击其中一个单元格,让他弹出我编好的一个form,怎么弄啊,用什么语言能实现
- 关于datagrid的大小?
- web页间怎样传送数据,能给段代码吗?放血100分
- 请问C#中的数组对象的传递方式是怎么样的?
- winForm菜单阴影高度不足,请看图!
- 批量更新数据库的问题 麻烦大家了~
- 编写控制台应用程序时,应主要使用class diagram,还是直接编写代码?
private void lbl1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.isdrag = true;
} //移动鼠标激发事件
private void lbl1_MouseMove(object sender, MouseEventArgs e)
{
if (!isdrag)
return;
UIElement control = sender as UIElement;
X = e.GetPosition(canvas1).X - control.DesiredSize.Width / 2;
Y = e.GetPosition(canvas1).Y - control.DesiredSize.Height / 2;
control.SetValue(Canvas.LeftProperty, X);
control.SetValue(Canvas.TopProperty, Y);
} //放开鼠标左键激发事件
private void lbl1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
this.isdrag = false;
UIElement control = sender as UIElement;
control.SetValue(Canvas.LeftProperty, point.X - control.DesiredSize.Width / 2);
control.SetValue(Canvas.TopProperty, point.Y - control.DesiredSize.Height / 2);
if (X > 300 && X < 375 && Y > 0 && Y < 108)
{
this.UpdateUser();
} }
private int CurX = 0,CurY = 0;
private System.Windows.Forms.Label label1;/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void label1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
CurX = e.X;//保存鼠标按下是鼠标在窗口的坐标
CurY = e.Y;
Mousedown = true;
this.label1.Capture = true;
} private void label1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(Mousedown)
{
//Cursor.Position .X Cursor.Position .Y 是屏幕坐标
//用屏幕坐标减窗口坐标以保持鼠标总是在窗口的原位置.
Point sp = new Point(Cursor.Position.X,Cursor.Position.Y);
Point np = this.PointToClient(sp);
this.label1.Location = new Point(np.X - CurX,np.Y - CurY);//(Cursor.Position .X - CurX,Cursor.Position .Y - CurY);
}
} private void label1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
Mousedown = false;
this.label1.Capture = false;
}
UIElement,
e.GetPosition(canvas1),
this.UpdateUser(),这些地方无法通过编译,是缺少了哪个using吗?请指教,谢谢!
UIElement,
e.GetPosition(canvas1),
this.UpdateUser(),这些地方无法通过编译,是缺少了哪个using吗?请指教,谢谢!
该怎么办?大侠们多多指教啊,感激不尽!
用了您的代码后,提示:
UIElement,
e.GetPosition(canvas1),
this.UpdateUser(),这些地方无法通过编译,是缺少了哪个using吗?请指教,谢谢!
using System.Runtime.InteropServices;
using System.Windows.Forms;namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} [DllImport("user32.dll")]
static extern bool ReleaseCapture();
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, UInt32 wParam, UInt32 lParam); private readonly UInt32 WM_SYSCOMMAND = 0x112;
private readonly UInt32 SC_MOVE = 0xF010;
private readonly UInt32 HTCAPTION = 2; private void button1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(button1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
} private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(pictureBox1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
} private void textBox1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(textBox1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}
}