用鼠标点住左键选择多个同一个界面下的Label 得到Label 的Text 在线等。

fangkuai3 2009-01-20 10:37:07
类似window桌面 用鼠标点住左键选择多个文件。
...全文
206 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgke 2009-01-20
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 zgke 的回复:]
对不起啊~~~ 忘记了 时间长了忘记哪个类是没有反转的~~
改了下
void m_SetRect_SetRectangel(object sneder, Rectangle e)
{
if (e.Width < 0)
{
int _X = e.X;
e.X = e.Width+e.X;
e.Width = _X;
}
if (e.Height < 0)
{
int _Y = e.Y;
e.Y =…
[/Quote]
改成这样
if (e.Width < 0)
{
int _X = e.X;
e.X = e.Width+e.X;
e.Width = _X - e.X;
}
if (e.Height < 0)
{
int _Y = e.Y;
e.Y = e.Height+e.Y;
e.Height = _Y - e.Y;
}

fangkuai3 2009-01-20
  • 打赏
  • 举报
回复
谢谢大家
fangkuai3 2009-01-20
  • 打赏
  • 举报
回复
SetControlRectangle 里的很多命名空间是什么啊?
zgke 2009-01-20
  • 打赏
  • 举报
回复
对不起啊~~~ 忘记了 时间长了忘记哪个类是没有反转的~~
改了下
void m_SetRect_SetRectangel(object sneder, Rectangle e)
{
if (e.Width < 0)
{
int _X = e.X;
e.X = e.Width+e.X;
e.Width = _X;
}
if (e.Height < 0)
{
int _Y = e.Y;
e.Y = e.Height+e.Y;
e.Height = _Y;
}


string _SetText="";
for (int i = 0; i != this.Controls.Count; i++)
{
if (this.Controls[i] is Label)
{
if (e.IntersectsWith(this.Controls[i].Bounds))
{
_SetText += this.Controls[i].Text + "\r\n";
}
}
}
MessageBox.Show(_SetText);

}
fangkuai3 2009-01-20
  • 打赏
  • 举报
回复
2楼的那个我还没看懂呢!很多命名空间都不知道
xiaoyanwei2000 2009-01-20
  • 打赏
  • 举报
回复
好像3楼给的SetControlRectangle 类也有点问题吧
用鼠标拖拽矩形框只有从右上到左下能够显示值,其他方向好像不行
xiaoyanwei2000 2009-01-20
  • 打赏
  • 举报
回复
private void Form1_Load(object sender, EventArgs e)
{
m_SetRect = new SetControlRectangle(this.panel1 );
m_SetRect.SetRectangel += new SetControlRectangle.SelectRectangel(m_SetRect_SetRectangel);
}


void m_SetRect_SetRectangel(object sneder, Rectangle e)
{

string _SetText = "";

for (int i = 0; i != this.panel1.Controls.Count; i++)
{
if (this.panel1.Controls[i] is TextBox)
{
if (e.IntersectsWith(this.panel1.Controls[i].Bounds))
{
_SetText += this.panel1.Controls[i].Text + "\r\n";
}
}
}

MessageBox.Show(_SetText);
}
xiaoyanwei2000 2009-01-20
  • 打赏
  • 举报
回复
修改一下3楼的
private void Form1_Load(object sender, EventArgs e)
{
m_SetRect = new SetControlRectangle(this.panel1 );
m_SetRect.SetRectangel += new SetControlRectangle.SelectRectangel(m_SetRect_SetRectangel);
}


void m_SetRect_SetRectangel(object sneder, Rectangle e)
{

string _SetText = "";

for (int i = 0; i != this.panel1.Controls.Count; i++)
{
if (this.panel1.Controls[i] is Lable)
{
if (e.IntersectsWith(this.panel1.Controls[i].Bounds))
{
_SetText += this.panel1.Controls[i].Text + "\r\n";
}
}
}

MessageBox.Show(_SetText);
}
fangkuai3 2009-01-20
  • 打赏
  • 举报
回复
问3楼 h_w_king
你做的项目是什么项目?
你能写详细点吗
fangkuai3 2009-01-20
  • 打赏
  • 举报
回复
我这是一个Panel里有多个多个Label 怎么鼠标按住不放 选中多个
h_w_king 2009-01-20
  • 打赏
  • 举报
回复
参考:

private void Form1_Load(object sender, EventArgs e)
{
labellist = new List<Label>();
foreach (Control c in this.Controls)
{
if(c is Label)
{
Label l= c as Label;
l.MouseUp += new MouseEventHandler(l_MouseUp);
}
}
}
List<Label> labellist;

void l_MouseUp(object sender, MouseEventArgs e)
{

if (e.Button == MouseButtons.Left)
{

Label l = (Label)sender;
if (labellist.Contains(l))
{
l.BackColor = Color.Transparent;
labellist.Remove(l);
}
else
{
l.BackColor = SystemColors.Highlight;
labellist.Add(l);
}

}
}
zgke 2009-01-20
  • 打赏
  • 举报
回复

private SetControlRectangle m_SetRect;
private void Form1_Load(object sender, EventArgs e)
{
m_SetRect = new SetControlRectangle(this);
m_SetRect.SetRectangel += new SetControlRectangle.SelectRectangel(m_SetRect_SetRectangel);
}

void m_SetRect_SetRectangel(object sneder, Rectangle e)
{

string _SetText="";
for (int i = 0; i != this.Controls.Count; i++)
{
if (this.Controls[i] is Label)
{
if (e.IntersectsWith(this.Controls[i].Bounds))
{
_SetText += this.Controls[i].Text + "\r\n";
}
}
}

MessageBox.Show(_SetText);
}


我没判断是否是子控件~~你可以低归获取 用RectangleToScreen转换 然后IntersectsWith

SetControlRectangle 是 http://blog.csdn.net/zgke/archive/2008/12/12/3502920.aspx

不知道能不能帮你
zgke 2009-01-20
  • 打赏
  • 举报
回复

private SetControlRectangle m_SetRect;
private void Form1_Load(object sender, EventArgs e)
{
m_SetRect = new SetControlRectangle(this);
m_SetRect.SetRectangel += new SetControlRectangle.SelectRectangel(m_SetRect_SetRectangel);
}

void m_SetRect_SetRectangel(object sneder, Rectangle e)
{

string _SetText="";
for (int i = 0; i != this.Controls.Count; i++)
{
if (this.Controls[i] is Label)
{
if (e.IntersectsWith(this.Controls[i].Bounds))
{
_SetText += this.Controls[i].Text + "\r\n";
}
}
}

MessageBox.Show(_SetText);
}


我没判断是否是子控件~~你可以低归获取 用RectangleToScreen转换 然后IntersectsWith

SetControlRectangle 是 http://blog.csdn.net/zgke/archive/2008/12/12/3502920.aspx

不知道能不能帮你
fangkuai3 2009-01-20
  • 打赏
  • 举报
回复
我的Label是动态生成后是充满Panel。鼠标选择在Label上就不行了。可以改吗?
xiaoyanwei2000 2009-01-20
  • 打赏
  • 举报
回复
呵呵,收藏了

111,131

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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