主要是想用C#在一个MDI程序中添加一个可以浮动的小窗口。
基本要求为:
1.类似于浮动工具栏,最好没有边框,可以任意拖动;
2.这个东西应该不是窗体,显示在所有窗体的最前面。
本来想用外接程序来实现,但是发现有点过于繁琐,还需要注册外接程序,想请大侠们帮帮指指路。用什么方式可以实现
基本要求为:
1.类似于浮动工具栏,最好没有边框,可以任意拖动;
2.这个东西应该不是窗体,显示在所有窗体的最前面。
本来想用外接程序来实现,但是发现有点过于繁琐,还需要注册外接程序,想请大侠们帮帮指指路。用什么方式可以实现
解决方案 »
- 在主窗体用serialPort1通讯,调用另一窗体时也需要通讯,怎么实现?
- 如何执行oracle下列存储过程?
- 一个中文问题
- 在 WINDOWSAPPLICATION 中,如何给 TEXTBOX 加背景图片?
- "将截断字符串或二进制数据。"错误解决
- 如何将软件与配套硬件信息绑定防止非法Copy?
- 编译器提示 : 并非所有的代码路径都返回值,可我没有看出来哪儿没有返回,帮忙?
- c# 中数组如何存放,是连续? operator 重载时 对象加对象时 是否跟 c++的单链表一样?如果不是,那么什么原理?
- 菜鸟问题(续)
- 主机IP地址
- 那么多的get set有什么用?(只有10分了)
- windows服务timer问题
this.MaximizeBox = false;
this.MinimizeBox = false;
要的话可以Mail给你!
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.MdiParent = this;
f2.Show();
}
}
}//-------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form2 : Form
{
bool IsMouseDown = false; int x0 = 0;
int y0 = 0; public Form2()
{
InitializeComponent(); this.label1.Text = "你的控件摆在这里";
this.label1.BackColor = Color.YellowGreen; this.Width = 160;
this.Height = 300;
this.FormBorderStyle = FormBorderStyle.None;
this.BackColor = Color.White; this.MouseDown += new MouseEventHandler(Form2_MouseDown);
this.MouseUp += new MouseEventHandler(Form2_MouseUp);
this.MouseMove += new MouseEventHandler(Form2_MouseMove);
} void Form2_MouseMove(object sender, MouseEventArgs e)
{
if (IsMouseDown)
{
this.Left += e.X -x0;
this.Top += e.Y -y0;
}
} void Form2_MouseUp(object sender, MouseEventArgs e)
{
IsMouseDown = false;
} void Form2_MouseDown(object sender, MouseEventArgs e)
{
IsMouseDown = true;
x0 = this.Left;
y0 = this.Top;
}
}
}
补一下: public Form2()
{
InitializeComponent(); this.label1.Text = "你的控件摆在这里";
this.label1.BackColor = Color.YellowGreen; this.Width = 160;
this.Height = 300;
this.FormBorderStyle = FormBorderStyle.None;
this.BackColor = Color.White;//新加的在这里
this.TopMost = true;
//新加的在这里 this.MouseDown += new MouseEventHandler(Form2_MouseDown);
this.MouseUp += new MouseEventHandler(Form2_MouseUp);
this.MouseMove += new MouseEventHandler(Form2_MouseMove);
}